models: use .format everywhere
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 11 Feb 2015 10:28:15 +0000 (11:28 +0100)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Wed, 11 Feb 2015 10:28:15 +0000 (11:28 +0100)
liteeth/test/arp_tb.py
liteeth/test/ip_tb.py
liteeth/test/model/arp.py
liteeth/test/model/icmp.py
liteeth/test/model/ip.py
liteeth/test/model/mac.py
liteeth/test/model/phy.py
liteeth/test/model/udp.py

index 373a4801843d789e6a01d900e2b58c63adda072a..3cd9ad3626bd66ca44545b93fd2b48960b547990 100644 (file)
@@ -50,7 +50,7 @@ class TB(Module):
                while selfp.arp.table.response.stb != 1:
                        selfp.arp.table.response.ack = 1
                        yield
-               print("Model's MAC : 0x%12x" %selfp.arp.table.response.mac_address)
+               print("Received MAC : 0x{:12x}".format(selfp.arp.table.response.mac_address))
 
 
 if __name__ == "__main__":
index 96b6d3418c27c3cef9f862754d27d285f1a2446c..1c21ffa5c1fc92138bd6629b5a2869dbdd6f32b8 100644 (file)
@@ -51,7 +51,7 @@ class TB(Module):
 
                        selfp.ip_port.source.ack = 1
                        if selfp.ip_port.source.stb == 1 and selfp.ip_port.source.sop == 1:
-                               print("IP Packet / from ip_address %08x" %selfp.ip_port.sink.ip_address)
+                               print("packet from from IP 0x{:08x}".format(selfp.ip_port.sink.ip_address))
 
                        yield
 
index 7a23f23ff1a4f51e202d1d3169094215807e61dc..677904cc74dce0c0fe730bc05649e552786c4f98 100644 (file)
@@ -33,10 +33,10 @@ class ARPPacket(Packet):
        def __repr__(self):
                r = "--------\n"
                for k in sorted(arp_header.keys()):
-                       r += k + " : 0x%x" %getattr(self,k) + "\n"
+                       r += k + " : 0x{:0x}\n".format(getattr(self,k))
                r += "payload: "
                for d in self:
-                       r += "%02x" %d
+                       r += "{:02x}".format(d)
                return r
 
 class ARP(Module):
index 8a27b61f9d8711ae2662c95acae6784663cc29b2..cf54b17c34f71867961fe2c0bf1f10c7dde2c1fa 100644 (file)
@@ -31,10 +31,10 @@ class ICMPPacket(Packet):
        def __repr__(self):
                r = "--------\n"
                for k in sorted(icmp_header.keys()):
-                       r += k + " : 0x%x" %getattr(self,k) + "\n"
+                       r += k + " : 0x{:0x}\n".format(getattr(self,k))
                r += "payload: "
                for d in self:
-                       r += "%02x" %d
+                       r += "{:02x}".format(d)
                return r
 
 class ICMP(Module):
index 9642844705ae2a35d370a3d0de89f172c97ff96b..03c5f8b5863281987f256be33cd76512a0c8949d 100644 (file)
@@ -55,10 +55,10 @@ class IPPacket(Packet):
        def __repr__(self):
                r = "--------\n"
                for k in sorted(ipv4_header.keys()):
-                       r += k + " : 0x%x" %getattr(self,k) + "\n"
+                       r += k + " : 0x{:0x}\n".format(getattr(self,k))
                r += "payload: "
                for d in self:
-                       r += "%02x" %d
+                       r += "{:02x}".format(d)
                return r
 
 class IP(Module):
@@ -101,7 +101,7 @@ class IP(Module):
                        received = packet.get_checksum()
                        packet.insert_checksum()
                        expected = packet.get_checksum()
-                       raise ValueError("Checksum error received %04x / expected %04x" %(received, expected))
+                       raise ValueError("Checksum error received {:04x} / expected {:04x}".format(received, expected))
                packet.decode()
                if self.debug:
                        print_ip("<<<<<<<<")
index f18f499062f793a3d13f6157e30281520820013f..9267f88bb62b8bfb10e1412043eb38d4a5a42bc5 100644 (file)
@@ -77,10 +77,10 @@ class MACPacket(Packet):
        def __repr__(self):
                r = "--------\n"
                for k in sorted(mac_header.keys()):
-                       r += k + " : 0x%x" %getattr(self,k) + "\n"
+                       r += k + " : 0x{:0x}\n".format(getattr(self,k))
                r += "payload: "
                for d in self:
-                       r += "%02x" %d
+                       r += "{:02x}".format(d)
                return r
 
 class MAC(Module):
index 8fc71629578425a80b258dc4827d04b3b850bb84..1401110feb14b88e4ac860b73373aa9f7eeb9599 100644 (file)
@@ -35,7 +35,7 @@ class PHY(Module):
                        r = ">>>>>>>>\n"
                        r += "length " + str(len(datas)) + "\n"
                        for d in datas:
-                               r += "%02x" %d
+                               r += "{:02x}".format(d)
                        print_phy(r)
                self.phy_source.send(packet)
 
@@ -45,7 +45,7 @@ class PHY(Module):
                        r = "<<<<<<<<\n"
                        r += "length " + str(len(self.phy_sink.packet)) + "\n"
                        for d in self.phy_sink.packet:
-                               r += "%02x" %d
+                               r += "{:02x}".format(d)
                        print_phy(r)
                self.packet = self.phy_sink.packet
 
index 7179b9ff2ac4564ce8230a7709a3ff09de1cf729..1892a2d56e07d079cdbcebeab7b569dcaf7af253 100644 (file)
@@ -31,10 +31,10 @@ class UDPPacket(Packet):
        def __repr__(self):
                r = "--------\n"
                for k in sorted(udp_header.keys()):
-                       r += k + " : 0x%x" %getattr(self,k) + "\n"
+                       r += k + " : 0x{:0x}\n".format(getattr(self,k))
                r += "payload: "
                for d in self:
-                       r += "%02x" %d
+                       r += "{:02x}".format(d)
                return r
 
 class UDP(Module):