From 38fefc5c1b005c518d0d511c0921169b92faa86c 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: Mon, 4 Jun 2012 23:12:26 +0600 Subject: Fixed various str-related logick --- python/netlink/core.py | 8 ++++---- python/netlink/route/link.py | 4 ++-- python/netlink/route/links/inet.py | 2 +- python/netlink/route/links/vlan.py | 2 +- python/netlink/util.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/python/netlink/core.py b/python/netlink/core.py index ea78691..b6cf7e9 100644 --- a/python/netlink/core.py +++ b/python/netlink/core.py @@ -92,14 +92,14 @@ class NetlinkError(Exception): class KernelError(NetlinkError): def __str__(self): - return "Kernel returned: " + 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: " + self._msg + return "Immutable attribute: {0}".format(self._msg) class Message(object): """Netlink message""" @@ -162,7 +162,7 @@ class Socket(object): capi.nl_socket_free(self._sock) def __str__(self): - return "nlsock<" + str(self.localPort) + ">" + return "nlsock<{0}>".format(self.localPort) @property def local_port(self): @@ -626,7 +626,7 @@ class AddressFamily(object): return self._family def __repr__(self): - return 'AddressFamily(\'' + str(self) + '\')' + return 'AddressFamily({0!r})'.format(str(self)) ########################################################################### diff --git a/python/netlink/route/link.py b/python/netlink/route/link.py index 74ec2f9..8c87971 100644 --- a/python/netlink/route/link.py +++ b/python/netlink/route/link.py @@ -127,7 +127,7 @@ class LinkCache(netlink.Cache): def __getitem__(self, key): if type(key) is int: link = capi.rtnl_link_get(self._nl_cache, key) - elif type(key) is str: + else: link = capi.rtnl_link_get_by_name(self._nl_cache, key) if link is None: @@ -227,7 +227,7 @@ class Link(netlink.Object): @flags.setter def flags(self, value): - if type(value) is list: + if not (type(value) is str): for flag in value: self._set_flag(flag) else: diff --git a/python/netlink/route/links/inet.py b/python/netlink/route/links/inet.py index 76a9e92..b5b1152 100644 --- a/python/netlink/route/links/inet.py +++ b/python/netlink/route/links/inet.py @@ -52,7 +52,7 @@ class InetLink(object): self._link = link def details(self, fmt): - buf = '\n' + fmt.nl('\t%s\n\t' % util.title('Configuration:')) + buf = fmt.nl('\n\t{0}\n\t'.format(util.title('Configuration:'))) for i in range(DEVCONF_FORWARDING,DEVCONF_MAX+1): if i & 1 and i > 1: diff --git a/python/netlink/route/links/vlan.py b/python/netlink/route/links/vlan.py index 134e721..c9fe2a7 100644 --- a/python/netlink/route/links/vlan.py +++ b/python/netlink/route/links/vlan.py @@ -57,7 +57,7 @@ class VLANLink(object): # - egress map def brief(self): - return 'vlan-id ' + self.id + return 'vlan-id {0}'.format(self.id) def init(link): link.vlan = VLANLink(link._link) diff --git a/python/netlink/util.py b/python/netlink/util.py index a8c831f..f6e7dec 100644 --- a/python/netlink/util.py +++ b/python/netlink/util.py @@ -17,7 +17,7 @@ from string import Formatter __version__ = "1.0" def _color(t, c): - return chr(0x1b)+"["+str(c)+"m"+str(t)+chr(0x1b)+"[0m" + return b'{esc}[{color}m{text}{esc}[0m'.format(esc=b'\x1b', color=c, text=t) def black(t): return _color(t, 30) @@ -126,7 +126,7 @@ class MyFormatter(Formatter): if include_title: if not title: title = key # fall back to key as title - value = kw(title) + ' ' + value + value = '{0} {1}'.format(kw(title), value) return value -- cgit v1.2.1