summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYoshihiro Kaneko <ykaneko0929@gmail.com>2014-05-13 20:21:59 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-05-14 13:20:57 +0900
commitc38270ce122b608d796843d92b8c940358ff1e30 (patch)
treec979131f368773ca4a2a2731fe24a29745d137f8
parent853bdeb1c3329b5caa0f59fa90d0f6ee2f0472cb (diff)
lib/packet: fix pep8
Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/bgp.py10
-rw-r--r--ryu/lib/packet/bpdu.py2
-rw-r--r--ryu/lib/packet/ipv6.py6
-rw-r--r--ryu/lib/packet/ospf.py37
-rw-r--r--ryu/lib/packet/packet_utils.py6
-rw-r--r--ryu/lib/packet/sctp.py12
-rw-r--r--ryu/lib/packet/slow.py40
7 files changed, 57 insertions, 56 deletions
diff --git a/ryu/lib/packet/bgp.py b/ryu/lib/packet/bgp.py
index 6882770c..13858db5 100644
--- a/ryu/lib/packet/bgp.py
+++ b/ryu/lib/packet/bgp.py
@@ -716,7 +716,7 @@ class IPAddrPrefix(_UnlabelledAddrPrefix, _IPAddrPrefix):
@property
def prefix(self):
- return self.addr+'/{0}'.format(self.length)
+ return self.addr + '/{0}'.format(self.length)
@property
def formatted_nlri_str(self):
@@ -728,7 +728,7 @@ class IP6AddrPrefix(_UnlabelledAddrPrefix, _IP6AddrPrefix):
@property
def prefix(self):
- return self.addr+'/{0}'.format(self.length)
+ return self.addr + '/{0}'.format(self.length)
@property
def formatted_nlri_str(self):
@@ -741,7 +741,7 @@ class LabelledVPNIPAddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
@property
def prefix(self):
- return self.addr[-1]+'/{0}'.format(self.length)
+ return self.addr[-1] + '/{0}'.format(self.length)
@property
def route_disc(self):
@@ -762,7 +762,7 @@ class LabelledVPNIP6AddrPrefix(_LabelledAddrPrefix, _VPNAddrPrefix,
@property
def prefix(self):
- return self.addr[-1]+'/{0}'.format(self.length)
+ return self.addr[-1] + '/{0}'.format(self.length)
@property
def route_disc(self):
@@ -2190,7 +2190,7 @@ class BGPRouteRefresh(BGPMessage):
@classmethod
def parser(cls, buf):
(afi, demarcation, safi,) = struct.unpack_from(cls._PACK_STR,
- buffer(buf))
+ buffer(buf))
return {
"afi": afi,
"safi": safi,
diff --git a/ryu/lib/packet/bpdu.py b/ryu/lib/packet/bpdu.py
index a98d35da..8926b2af 100644
--- a/ryu/lib/packet/bpdu.py
+++ b/ryu/lib/packet/bpdu.py
@@ -255,7 +255,7 @@ class ConfigurationBPDUs(bpdu):
_BRIDGE_PRIORITY_STEP = 4096
_PORT_PRIORITY_STEP = 16
- _TIMER_STEP = float(1)/256
+ _TIMER_STEP = float(1) / 256
def __init__(self, flags=0, root_priority=DEFAULT_BRIDGE_PRIORITY,
root_system_id_extension=0,
diff --git a/ryu/lib/packet/ipv6.py b/ryu/lib/packet/ipv6.py
index 20e52341..4be42c71 100644
--- a/ryu/lib/packet/ipv6.py
+++ b/ryu/lib/packet/ipv6.py
@@ -115,7 +115,7 @@ class ipv6(packet_base.PacketBase):
nxt, hop_limit, addrconv.ipv6.bin_to_text(src),
addrconv.ipv6.bin_to_text(dst), ext_hdrs)
return (msg, ipv6.get_packet_type(last),
- buf[offset:offset+payload_length])
+ buf[offset:offset + payload_length])
def serialize(self, payload, prev):
hdr = bytearray(40)
@@ -426,7 +426,7 @@ class routing_type3(header):
assert isinstance(adrs, list)
self.adrs = adrs
self._pad = (8 - ((len(self.adrs) - 1) * (16 - self.cmpi) +
- (16 - self.cmpe) % 8)) % 8
+ (16 - self.cmpe) % 8)) % 8
@classmethod
def _get_size(cls, size):
@@ -462,7 +462,7 @@ class routing_type3(header):
def serialize(self):
if self.size == 0:
self.size = ((len(self.adrs) - 1) * (16 - self.cmpi) +
- (16 - self.cmpe) + self._pad) / 8
+ (16 - self.cmpe) + self._pad) / 8
buf = struct.pack(self._PACK_STR, self.nxt, self.size,
self.type_, self.seg, (self.cmpi << 4) | self.cmpe,
self._pad << 4)
diff --git a/ryu/lib/packet/ospf.py b/ryu/lib/packet/ospf.py
index f51ddf47..6f40a82c 100644
--- a/ryu/lib/packet/ospf.py
+++ b/ryu/lib/packet/ospf.py
@@ -145,7 +145,7 @@ class LSAHeader(StringifyMixin):
"ls_seqnum": ls_seqnum,
"checksum": checksum,
"length": length,
- }, rest
+ }, rest
def serialize(self):
id_ = addrconv.ipv4.text_to_bin(self.id_)
@@ -173,14 +173,14 @@ class LSA(_TypeDisp, StringifyMixin):
@classmethod
def parser(cls, buf):
hdr, rest = LSAHeader.parser(buf)
- #exclude ls_age for checksum calculation
+ # exclude ls_age for checksum calculation
csum = packet_utils.fletcher_checksum(buf[2:hdr['length']], 14)
if csum != hdr['checksum']:
raise InvalidChecksum("header has %d, but calculated value is %d"
% (hdr['checksum'], csum))
subcls = cls._lookup_type(hdr['type_'])
- body = rest[:hdr['length']-LSAHeader._HDR_LEN]
- rest = rest[hdr['length']-LSAHeader._HDR_LEN:]
+ body = rest[:hdr['length'] - LSAHeader._HDR_LEN]
+ rest = rest[hdr['length'] - LSAHeader._HDR_LEN:]
kwargs = subcls.parser(body)
kwargs.update(hdr)
return subcls(**kwargs), subcls, rest
@@ -189,8 +189,8 @@ class LSA(_TypeDisp, StringifyMixin):
tail = self.serialize_tail()
self.header.length = self.header._HDR_LEN + len(tail)
head = self.header.serialize()
- #exclude ls_age for checksum calculation
- csum = packet_utils.fletcher_checksum(head[2:]+tail, 14)
+ # exclude ls_age for checksum calculation
+ csum = packet_utils.fletcher_checksum(head[2:] + tail, 14)
self.header.checksum = csum
struct.pack_into("!H", head, 16, csum)
return head + tail
@@ -260,7 +260,7 @@ class RouterLSA(LSA):
head = bytearray(struct.pack(self._PACK_STR, self.flags, 0,
len(self.links)))
try:
- return head + reduce(lambda a, b: a+b,
+ return head + reduce(lambda a, b: a + b,
(link.serialize() for link in self.links))
except TypeError:
return head
@@ -305,7 +305,7 @@ class NetworkLSA(LSA):
mask = addrconv.ipv4.text_to_bin(self.mask)
routers = [addrconv.ipv4.text_to_bin(
router) for router in self.routers]
- return bytearray(struct.pack("!"+"4s"*(1+len(routers)), mask,
+ return bytearray(struct.pack("!" + "4s" * (1 + len(routers)), mask,
*routers))
@@ -375,7 +375,7 @@ class ASExternalLSA(LSA):
}
def serialize_tail(self):
- return reduce(lambda a, b: a+b,
+ return reduce(lambda a, b: a + b,
(extnw.serialize() for extnw in self.extnws))
@@ -426,8 +426,8 @@ class OSPFMessage(packet_base.PacketBase, _TypeDisp):
(version, type_, length, router_id, area_id, checksum, au_type,
authentication) = struct.unpack_from(cls._HDR_PACK_STR, buffer(buf))
- #Exclude checksum and authentication field for checksum validation.
- if packet_utils.checksum(buf[:12]+buf[14:16]+buf[cls._HDR_LEN:]) \
+ # Exclude checksum and authentication field for checksum validation.
+ if packet_utils.checksum(buf[:12] + buf[14:16] + buf[cls._HDR_LEN:]) \
!= checksum:
raise InvalidChecksum
@@ -453,12 +453,13 @@ class OSPFMessage(packet_base.PacketBase, _TypeDisp):
addrconv.ipv4.text_to_bin(self.area_id), 0,
self.au_type, self.authentication))
buf = head + tail
- csum = packet_utils.checksum(buf[:12]+buf[14:16]+buf[self._HDR_LEN:])
+ csum = packet_utils.checksum(buf[:12] + buf[14:16] +
+ buf[self._HDR_LEN:])
self.checksum = csum
struct.pack_into("!H", buf, 12, csum)
return buf
-#alias
+# alias
ospf = OSPFMessage
@@ -520,7 +521,7 @@ class OSPFHello(OSPFMessage):
addrconv.ipv4.text_to_bin(self.designated_router),
addrconv.ipv4.text_to_bin(self.backup_router)))
try:
- return head + reduce(lambda a, b: a+b,
+ return head + reduce(lambda a, b: a + b,
(addrconv.ipv4.text_to_bin(
n) for n in self.neighbors))
except TypeError:
@@ -579,7 +580,7 @@ class OSPFDBDesc(OSPFMessage):
self.options, flags,
self.sequence_number))
try:
- return head + reduce(lambda a, b: a+b,
+ return head + reduce(lambda a, b: a + b,
(hdr.serialize() for hdr in self.lsa_headers))
except TypeError:
return head
@@ -637,7 +638,7 @@ class OSPFLSReq(OSPFMessage):
}
def serialize_tail(self):
- return reduce(lambda a, b: a+b,
+ return reduce(lambda a, b: a + b,
(req.serialize() for req in self.lsa_requests))
@@ -673,7 +674,7 @@ class OSPFLSUpd(OSPFMessage):
def serialize_tail(self):
head = bytearray(struct.pack(self._PACK_STR, len(self.lsas)))
try:
- return head + reduce(lambda a, b: a+b,
+ return head + reduce(lambda a, b: a + b,
(lsa.serialize() for lsa in self.lsas))
except TypeError:
return head
@@ -702,5 +703,5 @@ class OSPFLSAck(OSPFMessage):
}
def serialize_tail(self):
- return reduce(lambda a, b: a+b,
+ return reduce(lambda a, b: a + b,
(hdr.serialize() for hdr in self.lsa_headers))
diff --git a/ryu/lib/packet/packet_utils.py b/ryu/lib/packet/packet_utils.py
index e797e6e2..3839e69c 100644
--- a/ryu/lib/packet/packet_utils.py
+++ b/ryu/lib/packet/packet_utils.py
@@ -113,11 +113,11 @@ def fletcher_checksum(data, offset):
pos = 0
length = len(data)
data = bytearray(data)
- data[offset:offset+2] = [0]*2
+ data[offset:offset + 2] = [0] * 2
while pos < length:
tlen = min(length - pos, _MODX)
- for d in data[pos:pos+tlen]:
+ for d in data[pos:pos + tlen]:
c0 += d
c1 += c0
c0 %= 255
@@ -132,5 +132,5 @@ def fletcher_checksum(data, offset):
y -= 255
data[offset] = x
- data[offset+1] = y
+ data[offset + 1] = y
return (x << 8) | (y & 0xff)
diff --git a/ryu/lib/packet/sctp.py b/ryu/lib/packet/sctp.py
index 88d9d37e..8dfc28a5 100644
--- a/ryu/lib/packet/sctp.py
+++ b/ryu/lib/packet/sctp.py
@@ -223,11 +223,11 @@ class sctp(packet_base.PacketBase):
return struct.unpack(">I", struct.pack("<I", crc32))[0]
-#=======================================================================
+# =======================================================================
#
# Chunk Types
#
-#=======================================================================
+# =======================================================================
@six.add_metaclass(abc.ABCMeta)
class chunk(stringify.StringifyMixin):
_PACK_STR = '!BBH'
@@ -1166,11 +1166,11 @@ class chunk_shutdown_complete(chunk):
return buf
-#=======================================================================
+# =======================================================================
#
# Cause Code
#
-#=======================================================================
+# =======================================================================
@six.add_metaclass(abc.ABCMeta)
class cause(stringify.StringifyMixin):
_PACK_STR = '!HH'
@@ -1764,11 +1764,11 @@ class cause_protocol_violation(cause_with_value):
return CCODE_PROTOCOL_VIOLATION
-#=======================================================================
+# =======================================================================
#
# Chunk Parameter Types
#
-#=======================================================================
+# =======================================================================
@six.add_metaclass(abc.ABCMeta)
class param(stringify.StringifyMixin):
_PACK_STR = '!HH'
diff --git a/ryu/lib/packet/slow.py b/ryu/lib/packet/slow.py
index d2d39c33..1ca76af7 100644
--- a/ryu/lib/packet/slow.py
+++ b/ryu/lib/packet/slow.py
@@ -431,14 +431,14 @@ class lacp(packet_base.PacketBase):
assert (1 == partner_state_distributing | 1)
assert (1 == partner_state_defaulted | 1)
assert (1 == partner_state_expired | 1)
- #------------------------------
+ # ------------------------------
# Header
- #------------------------------
+ # ------------------------------
self._subtype = SLOW_SUBTYPE_LACP
self.version = version
- #------------------------------
+ # ------------------------------
# Actor Information
- #------------------------------
+ # ------------------------------
self._actor_tag = self.LACP_TLV_TYPE_ACTOR
self._actor_length = self._ACTPRT_INFO_PACK_LEN
self.actor_system_priority = actor_system_priority
@@ -463,9 +463,9 @@ class lacp(packet_base.PacketBase):
(self.actor_state_distributing << 5) |
(self.actor_state_defaulted << 6) |
(self.actor_state_expired << 7))
- #------------------------------
+ # ------------------------------
# Partner Information
- #------------------------------
+ # ------------------------------
self._partner_tag = self.LACP_TLV_TYPE_PARTNER
self._partner_length = self._ACTPRT_INFO_PACK_LEN
self.partner_system_priority = partner_system_priority
@@ -491,15 +491,15 @@ class lacp(packet_base.PacketBase):
(self.partner_state_distributing << 5) |
(self.partner_state_defaulted << 6) |
(self.partner_state_expired << 7))
- #------------------------------
+ # ------------------------------
# Collector Information
- #------------------------------
+ # ------------------------------
self._collector_tag = self.LACP_TLV_TYPE_COLLECTOR
self._collector_length = self._COL_INFO_PACK_LEN
self.collector_max_delay = collector_max_delay
- #------------------------------
+ # ------------------------------
# Terminator
- #------------------------------
+ # ------------------------------
self._terminator_tag = self.LACP_TLV_TYPE_TERMINATOR
self._terminator_length = 0
@@ -507,17 +507,17 @@ class lacp(packet_base.PacketBase):
def parser(cls, buf):
assert cls._ALL_PACK_LEN == len(buf)
offset = 0
- #------------------------------
+ # ------------------------------
# Header
- #------------------------------
+ # ------------------------------
(subtype, version
) = struct.unpack_from(cls._HLEN_PACK_STR, buf, offset)
assert SLOW_SUBTYPE_LACP == subtype
assert cls.LACP_VERSION_NUMBER == version
offset += cls._HLEN_PACK_LEN
- #------------------------------
+ # ------------------------------
# Actor Information
- #------------------------------
+ # ------------------------------
(actor_tag, actor_length, actor_system_priority, actor_system,
actor_key, actor_port_priority, actor_port, actor_state
) = struct.unpack_from(cls._ACTPRT_INFO_PACK_STR, buf, offset)
@@ -532,9 +532,9 @@ class lacp(packet_base.PacketBase):
actor_state_distributing = (actor_state >> 5) & 1
actor_state_defaulted = (actor_state >> 6) & 1
actor_state_expired = (actor_state >> 7) & 1
- #------------------------------
+ # ------------------------------
# Partner Information
- #------------------------------
+ # ------------------------------
(partner_tag, partner_length, partner_system_priority,
partner_system, partner_key, partner_port_priority,
partner_port, partner_state
@@ -550,17 +550,17 @@ class lacp(packet_base.PacketBase):
partner_state_distributing = (partner_state >> 5) & 1
partner_state_defaulted = (partner_state >> 6) & 1
partner_state_expired = (partner_state >> 7) & 1
- #------------------------------
+ # ------------------------------
# Collector Information
- #------------------------------
+ # ------------------------------
(collector_tag, collector_length, collector_max_delay
) = struct.unpack_from(cls._COL_INFO_PACK_STR, buf, offset)
assert cls.LACP_TLV_TYPE_COLLECTOR == collector_tag
assert cls._COL_INFO_PACK_LEN == collector_length
offset += cls._COL_INFO_PACK_LEN
- #------------------------------
+ # ------------------------------
# Terminator Information
- #------------------------------
+ # ------------------------------
(terminator_tag, terminator_length
) = struct.unpack_from(cls._TRM_PACK_STR, buf, offset)
assert cls.LACP_TLV_TYPE_TERMINATOR == terminator_tag