From 8959d95e22858148ca75861431dad51356c8a73b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA=20=28=D0=BD=D0=BE=D1=83=D1=82=D0=B1?= =?UTF-8?q?=D1=83=D0=BA=20=D0=B4=D0=BE=D0=BC=D0=B0=29?= Date: Tue, 5 Jun 2012 23:01:39 +0600 Subject: Using only single quotes now and multi-line lists Nothing algorithmic changed really, just cosmetics --- python/netlink/core.py | 40 ++++++++++++++++++++++--------------- python/netlink/route/address.py | 6 +++--- python/netlink/route/link.py | 21 +++++++++++-------- python/netlink/route/links/dummy.py | 6 ++++-- python/netlink/route/links/inet.py | 6 ++++-- python/netlink/route/tc.py | 17 ++++++++-------- python/netlink/util.py | 4 ++-- 7 files changed, 59 insertions(+), 41 deletions(-) diff --git a/python/netlink/core.py b/python/netlink/core.py index 219b522..e18230f 100644 --- a/python/netlink/core.py +++ b/python/netlink/core.py @@ -33,9 +33,17 @@ from . import capi import sys import socket -__all__ = ['Message', 'Socket', 'DumpParams', 'Object', 'Cache', 'KernelError', - 'NetlinkError'] -__version__ = "0.1" +__all__ = [ + 'Message', + 'Socket', + 'DumpParams', + 'Object', + 'Cache', + 'KernelError', + 'NetlinkError', +] + +__version__ = '0.1' # netlink protocols NETLINK_ROUTE = 0 @@ -91,14 +99,14 @@ class NetlinkError(Exception): class KernelError(NetlinkError): def __str__(self): - return "Kernel returned: {0}".format(self._msg) + return 'Kernel returned: {0}'.format(self._msg) class ImmutableError(NetlinkError): def __init__(self, msg): self._msg = msg def __str__(self): - return "Immutable attribute: {0}".format(self._msg) + return 'Immutable attribute: {0}'.format(self._msg) class Message(object): """Netlink message""" @@ -110,7 +118,7 @@ class Message(object): self._msg = capi.nlmsg_alloc_size(size) if self._msg is None: - raise Exception("Message allocation returned NULL") + raise Exception('Message allocation returned NULL') def __del__(self): capi.nlmsg_free(self._msg) @@ -155,13 +163,13 @@ class Socket(object): self._sock = capi.nl_socket_alloc_cb(cb) if self._sock is None: - raise Exception("NULL pointer returned while allocating socket") + raise Exception('NULL pointer returned while allocating socket') def __del__(self): capi.nl_socket_free(self._sock) def __str__(self): - return "nlsock<{0}>".format(self.localPort) + return 'nlsock<{0}>'.format(self.localPort) @property def local_port(self): @@ -200,7 +208,7 @@ class Socket(object): def sendto(self, buf): ret = capi.nl_sendto(self._sock, buf, len(buf)) if ret < 0: - raise Exception("Failed to send") + raise Exception('Failed to send') else: return ret @@ -222,7 +230,7 @@ class DumpParams(object): def __init__(self, type=NL_DUMP_LINE): self._dp = capi.alloc_dump_params() if not self._dp: - raise Exception("Unable to allocate struct nl_dump_params") + raise Exception('Unable to allocate struct nl_dump_params') self._dp.dp_type = type @@ -388,17 +396,17 @@ class Object(object): def apply(self, attr, val): try: - d = attrs[self._name + "." + attr] + d = attrs[self._name + '.' + attr] except KeyError: - raise KeyError("Unknown " + self._name + - " attribute: " + attr) + raise KeyError('Unknown ' + self._name + + ' attribute: ' + attr) if 'immutable' in d: raise ImmutableError(attr) if not self._hasattr(attr): - raise KeyError("Invalid " + self._name + - " attribute: " + attr) + raise KeyError('Invalid ' + self._name + + ' attribute: ' + attr) self._setattr(attr, val) class ObjIterator(object): @@ -695,7 +703,7 @@ class AbstractAddress(object): if self._nl_addr: return capi.nl_addr2str(self._nl_addr, 64)[0] else: - return "none" + return 'none' @property def shared(self): diff --git a/python/netlink/route/address.py b/python/netlink/route/address.py index b5f2448..e8e2f87 100644 --- a/python/netlink/route/address.py +++ b/python/netlink/route/address.py @@ -8,7 +8,7 @@ from __future__ import absolute_import -__version__ = "1.0" +__version__ = '1.0' __all__ = [ 'AddressCache', 'Address'] @@ -27,7 +27,7 @@ class AddressCache(netlink.Cache): def __init__(self, cache=None): if not cache: - cache = self._alloc_cache_name("route/addr") + cache = self._alloc_cache_name('route/addr') self._protocol = netlink.NETLINK_ROUTE self._nl_cache = cache @@ -60,7 +60,7 @@ class Address(netlink.Object): """Network address""" def __init__(self, obj=None): - netlink.Object.__init__(self, "route/addr", "address", obj) + netlink.Object.__init__(self, 'route/addr', 'address', obj) self._rtnl_addr = self._obj2type(self._nl_object) @classmethod diff --git a/python/netlink/route/link.py b/python/netlink/route/link.py index 465b3b3..4c213d0 100644 --- a/python/netlink/route/link.py +++ b/python/netlink/route/link.py @@ -36,11 +36,12 @@ The following public functions exist: from __future__ import absolute_import -__version__ = "0.1" +__version__ = '0.1' __all__ = [ 'LinkCache', 'Link', - 'get_from_kernel'] + 'get_from_kernel', +] import socket import sys @@ -117,7 +118,7 @@ class LinkCache(netlink.Cache): def __init__(self, family=socket.AF_UNSPEC, cache=None): if not cache: - cache = self._alloc_cache_name("route/link") + cache = self._alloc_cache_name('route/link') self._info_module = None self._protocol = netlink.NETLINK_ROUTE @@ -147,7 +148,7 @@ class Link(netlink.Object): """Network link""" def __init__(self, obj=None): - netlink.Object.__init__(self, "route/link", "link", obj) + netlink.Object.__init__(self, 'route/link', 'link', obj) self._rtnl_link = self._obj2type(self._nl_object) if self.type: @@ -403,7 +404,7 @@ class Link(netlink.Object): @type.setter def type(self, value): if capi.rtnl_link_set_type(self._rtnl_link, value) < 0: - raise NameError("unknown info type") + raise NameError('unknown info type') self._module_lookup('netlink.route.links.' + value) @@ -414,7 +415,7 @@ class Link(netlink.Object): if type(stat) is str: stat = capi.rtnl_link_str2stat(stat) if stat < 0: - raise NameError("unknown name of statistic") + raise NameError('unknown name of statistic') return capi.rtnl_link_get_stat(self._rtnl_link, stat) @@ -439,7 +440,7 @@ class Link(netlink.Object): socket = netlink.lookup_socket(netlink.NETLINK_ROUTE) if not self._orig: - raise NetlinkError("Original link not available") + raise NetlinkError('Original link not available') ret = capi.rtnl_link_change(socket._sock, self._orig, self._rtnl_link, flags) if ret < 0: raise netlink.KernelError(ret) @@ -475,7 +476,11 @@ class Link(netlink.Object): @property def _flags(self): - ignore = ['up', 'running', 'lowerup'] + ignore = [ + 'up', + 'running', + 'lowerup', + ] return ','.join([flag for flag in self.flags if flag not in ignore]) def _foreach_af(self, name, args=None): diff --git a/python/netlink/route/links/dummy.py b/python/netlink/route/links/dummy.py index 13b3077..c9253cf 100644 --- a/python/netlink/route/links/dummy.py +++ b/python/netlink/route/links/dummy.py @@ -7,8 +7,10 @@ """ from __future__ import absolute_import -__version__ = "1.0" -__all__ = ['init'] +__version__ = '1.0' +__all__ = [ + 'init', +] from ... import core as netlink diff --git a/python/netlink/route/links/inet.py b/python/netlink/route/links/inet.py index 1a13349..8f89b4e 100644 --- a/python/netlink/route/links/inet.py +++ b/python/netlink/route/links/inet.py @@ -8,7 +8,9 @@ from __future__ import absolute_import -__all__ = [''] +__all__ = [ + '', +] from ... import core as netlink from .. import capi as capi @@ -44,7 +46,7 @@ def _resolve(id): if type(id) is str: id = capi.rtnl_link_inet_str2devconf(id)[0] if id < 0: - raise NameError("unknown configuration id") + raise NameError('unknown configuration id') return id class InetLink(object): diff --git a/python/netlink/route/tc.py b/python/netlink/route/tc.py index 92f2950..9a81a67 100644 --- a/python/netlink/route/tc.py +++ b/python/netlink/route/tc.py @@ -9,7 +9,8 @@ __all__ = [ 'QdiscCache', 'Qdisc', 'TcClassCache', - 'TcClass'] + 'TcClass', +] import socket import sys @@ -255,7 +256,7 @@ class QdiscCache(netlink.Cache): def __init__(self, cache=None): if not cache: - cache = self._alloc_cache_name("route/qdisc") + cache = self._alloc_cache_name('route/qdisc') self._protocol = netlink.NETLINK_ROUTE self._nl_cache = cache @@ -283,7 +284,7 @@ class Qdisc(Tc): """Queueing discipline""" def __init__(self, obj=None): - netlink.Object.__init__(self, "route/qdisc", "qdisc", obj) + netlink.Object.__init__(self, 'route/qdisc', 'qdisc', obj) self._module_path = 'netlink.route.qdisc.' self._rtnl_qdisc = self._obj2type(self._nl_object) self._rtnl_tc = capi.obj2tc(self._nl_object) @@ -337,7 +338,7 @@ class Qdisc(Tc): # def change(self, socket, flags=0): # """Commit changes made to the link object""" # if not self._orig: -# raise NetlinkError("Original link not available") +# raise NetlinkError('Original link not available') # ret = capi.rtnl_link_change(socket._sock, self._orig, self._link, flags) # if ret < 0: # raise netlink.KernelError(ret) @@ -432,7 +433,7 @@ class TcClassCache(netlink.Cache): def __init__(self, ifindex, cache=None): if not cache: - cache = self._alloc_cache_name("route/class") + cache = self._alloc_cache_name('route/class') self._protocol = netlink.NETLINK_ROUTE self._nl_cache = cache @@ -450,7 +451,7 @@ class TcClass(Tc): """Traffic Class""" def __init__(self, obj=None): - netlink.Object.__init__(self, "route/class", "class", obj) + netlink.Object.__init__(self, 'route/class', 'class', obj) self._module_path = 'netlink.route.qdisc.' self._rtnl_class = self._obj2type(self._nl_object) self._rtnl_tc = capi.obj2tc(self._nl_object) @@ -510,7 +511,7 @@ class ClassifierCache(netlink.Cache): def __init__(self, ifindex, parent, cache=None): if not cache: - cache = self._alloc_cache_name("route/cls") + cache = self._alloc_cache_name('route/cls') self._protocol = netlink.NETLINK_ROUTE self._nl_cache = cache @@ -529,7 +530,7 @@ class Classifier(Tc): """Classifier""" def __init__(self, obj=None): - netlink.Object.__init__(self, "route/cls", "cls", obj) + netlink.Object.__init__(self, 'route/cls', 'cls', obj) self._module_path = 'netlink.route.cls.' self._rtnl_cls = self._obj2type(self._nl_object) self._rtnl_tc = capi.obj2tc(self._nl_object) diff --git a/python/netlink/util.py b/python/netlink/util.py index 5249be9..995a6d2 100644 --- a/python/netlink/util.py +++ b/python/netlink/util.py @@ -15,7 +15,7 @@ from . import capi as capi from string import Formatter import types -__version__ = "1.0" +__version__ = '1.0' def _color(t, c): return b'{esc}[{color}m{text}{esc}[0m'.format(esc=b'\x1b', color=c, text=t) @@ -143,7 +143,7 @@ class MyFormatter(Formatter): elif conversion is None: return value - raise ValueError("Unknown converion specifier {0!s}".format(conversion)) + raise ValueError('Unknown converion specifier {0!s}'.format(conversion)) def nl(self, format_string=''): return '\n' + self._indent + self.format(format_string) -- cgit v1.2.1