From a2279bd2fa08ac1c2a4ac03a711f72d7647f0b49 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Wed, 11 Feb 2015 11:28:15 +0100 Subject: [PATCH] models: use .format everywhere --- liteeth/test/arp_tb.py | 2 +- liteeth/test/ip_tb.py | 2 +- liteeth/test/model/arp.py | 4 ++-- liteeth/test/model/icmp.py | 4 ++-- liteeth/test/model/ip.py | 6 +++--- liteeth/test/model/mac.py | 4 ++-- liteeth/test/model/phy.py | 4 ++-- liteeth/test/model/udp.py | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/liteeth/test/arp_tb.py b/liteeth/test/arp_tb.py index 373a4801..3cd9ad36 100644 --- a/liteeth/test/arp_tb.py +++ b/liteeth/test/arp_tb.py @@ -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__": diff --git a/liteeth/test/ip_tb.py b/liteeth/test/ip_tb.py index 96b6d341..1c21ffa5 100644 --- a/liteeth/test/ip_tb.py +++ b/liteeth/test/ip_tb.py @@ -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 diff --git a/liteeth/test/model/arp.py b/liteeth/test/model/arp.py index 7a23f23f..677904cc 100644 --- a/liteeth/test/model/arp.py +++ b/liteeth/test/model/arp.py @@ -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): diff --git a/liteeth/test/model/icmp.py b/liteeth/test/model/icmp.py index 8a27b61f..cf54b17c 100644 --- a/liteeth/test/model/icmp.py +++ b/liteeth/test/model/icmp.py @@ -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): diff --git a/liteeth/test/model/ip.py b/liteeth/test/model/ip.py index 96428447..03c5f8b5 100644 --- a/liteeth/test/model/ip.py +++ b/liteeth/test/model/ip.py @@ -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("<<<<<<<<") diff --git a/liteeth/test/model/mac.py b/liteeth/test/model/mac.py index f18f4990..9267f88b 100644 --- a/liteeth/test/model/mac.py +++ b/liteeth/test/model/mac.py @@ -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): diff --git a/liteeth/test/model/phy.py b/liteeth/test/model/phy.py index 8fc71629..1401110f 100644 --- a/liteeth/test/model/phy.py +++ b/liteeth/test/model/phy.py @@ -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 diff --git a/liteeth/test/model/udp.py b/liteeth/test/model/udp.py index 7179b9ff..1892a2d5 100644 --- a/liteeth/test/model/udp.py +++ b/liteeth/test/model/udp.py @@ -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): -- 2.30.2