mirror of
https://gitee.com/openharmony/third_party_libnl
synced 2024-12-04 09:13:33 +00:00
Fixed various str-related logick
This commit is contained in:
parent
b369d22f92
commit
38fefc5c1b
@ -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))
|
||||
|
||||
|
||||
###########################################################################
|
||||
|
@ -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:
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user