- zfill() is a func of the string to be putting in a '0'. bytearray().zfill(n) -> bytearray(n)
- unify notation of zero with other code. '\0' -> '\x00' Signed-off-by: HIYAMA Manabu <[email protected]> --- ryu/lib/packet/ipv4.py | 2 +- ryu/lib/packet/tcp.py | 4 ++-- ryu/lib/packet/udp.py | 2 +- ryu/ofproto/ofproto_parser.py | 6 +++--- ryu/tests/unit/ofproto/test_ofproto_parser.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ryu/lib/packet/ipv4.py b/ryu/lib/packet/ipv4.py index 2adf689..21d227a 100644 --- a/ryu/lib/packet/ipv4.py +++ b/ryu/lib/packet/ipv4.py @@ -62,7 +62,7 @@ class ipv4(packet_base.PacketBase): return msg, ipv4.get_packet_type(proto) def serialize(self, payload, prev): - hdr = bytearray().zfill(self.header_length * 4) + hdr = bytearray(self.header_length * 4) version = self.version << 4 | self.header_length flags = self.flags << 13 | self.offset if self.total_length == 0: diff --git a/ryu/lib/packet/tcp.py b/ryu/lib/packet/tcp.py index ec177f0..81c7933 100644 --- a/ryu/lib/packet/tcp.py +++ b/ryu/lib/packet/tcp.py @@ -54,7 +54,7 @@ class tcp(packet_base.PacketBase): return msg, None def serialize(self, payload, prev): - h = bytearray().zfill(self.length) + h = bytearray(self.length) offset = self.offset << 4 struct.pack_into(tcp._PACK_STR, h, 0, self.src_port, self.dst_port, self.seq, self.ack, offset, self.bits, @@ -69,7 +69,7 @@ class tcp(packet_base.PacketBase): ph = struct.pack('!IIBBH', prev.src, prev.dst, 0, 6, length) f = ph + h + payload if len(f) % 2: - f += '\0' + f += '\x00' self.csum = socket.htons(packet_utils.checksum(f)) struct.pack_into('!H', h, 16, self.csum) return h diff --git a/ryu/lib/packet/udp.py b/ryu/lib/packet/udp.py index 2b858d9..b949b5c 100644 --- a/ryu/lib/packet/udp.py +++ b/ryu/lib/packet/udp.py @@ -47,7 +47,7 @@ class udp(packet_base.PacketBase): ph = struct.pack('!IIBBH', prev.src, prev.dst, 0, 17, self.length) f = ph + h + payload if len(f) % 2: - f += '\0' + f += '\x00' self.csum = socket.htons(packet_utils.checksum(f)) h = struct.pack(udp._PACK_STR, self.src_port, self.dst_port, self.length, self.csum) diff --git a/ryu/ofproto/ofproto_parser.py b/ryu/ofproto/ofproto_parser.py index 21a86a9..26adead 100644 --- a/ryu/ofproto/ofproto_parser.py +++ b/ryu/ofproto/ofproto_parser.py @@ -93,7 +93,7 @@ class MsgBase(object): self.version = self.datapath.ofproto.OFP_VERSION self.msg_type = self.cls_msg_type - self.buf = bytearray().zfill(self.datapath.ofproto.OFP_HEADER_SIZE) + self.buf = bytearray(self.datapath.ofproto.OFP_HEADER_SIZE) def _serialize_header(self): # buffer length is determined after trailing data is formated. @@ -122,7 +122,7 @@ class MsgBase(object): def msg_pack_into(fmt, buf, offset, *args): if len(buf) < offset: - buf += bytearray().zfill(offset - len(buf)) + buf += bytearray(offset - len(buf)) if len(buf) == offset: buf += struct.pack(fmt, *args) @@ -130,7 +130,7 @@ def msg_pack_into(fmt, buf, offset, *args): needed_len = offset + struct.calcsize(fmt) if len(buf) < needed_len: - buf += bytearray().zfill(needed_len - len(buf)) + buf += bytearray(needed_len - len(buf)) struct.pack_into(fmt, buf, offset, *args) diff --git a/ryu/tests/unit/ofproto/test_ofproto_parser.py b/ryu/tests/unit/ofproto/test_ofproto_parser.py index 114a699..9baf46a 100644 --- a/ryu/tests/unit/ofproto/test_ofproto_parser.py +++ b/ryu/tests/unit/ofproto/test_ofproto_parser.py @@ -252,7 +252,7 @@ class TestMsgPackInto(unittest.TestCase): def _test_msg_pack_into(self, offset_type='e'): fmt = '!HH' len_ = struct.calcsize(fmt) - buf = bytearray().zfill(len_) + buf = bytearray(len_) offset = len_ arg1 = 1 arg2 = 2 -- 1.7.9.5 ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://ad.doubleclick.net/clk;258768047;13503038;j? http://info.appdynamics.com/FreeJavaPerformanceDownload.html _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
