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"""
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):
return self._family
def __repr__(self):
- return 'AddressFamily(\'' + str(self) + '\')'
+ return 'AddressFamily({0!r})'.format(str(self))
###########################################################################
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:
@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:
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:
# - 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)
__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)
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