models: use .format everywhere

This commit is contained in:
Florent Kermarrec 2015-02-11 11:28:15 +01:00
parent 227fc4f5e5
commit a2279bd2fa
8 changed files with 15 additions and 15 deletions

View File

@ -50,7 +50,7 @@ class TB(Module):
while selfp.arp.table.response.stb != 1: while selfp.arp.table.response.stb != 1:
selfp.arp.table.response.ack = 1 selfp.arp.table.response.ack = 1
yield 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__": if __name__ == "__main__":

View File

@ -51,7 +51,7 @@ class TB(Module):
selfp.ip_port.source.ack = 1 selfp.ip_port.source.ack = 1
if selfp.ip_port.source.stb == 1 and selfp.ip_port.source.sop == 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 yield

View File

@ -33,10 +33,10 @@ class ARPPacket(Packet):
def __repr__(self): def __repr__(self):
r = "--------\n" r = "--------\n"
for k in sorted(arp_header.keys()): 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: " r += "payload: "
for d in self: for d in self:
r += "%02x" %d r += "{:02x}".format(d)
return r return r
class ARP(Module): class ARP(Module):

View File

@ -31,10 +31,10 @@ class ICMPPacket(Packet):
def __repr__(self): def __repr__(self):
r = "--------\n" r = "--------\n"
for k in sorted(icmp_header.keys()): 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: " r += "payload: "
for d in self: for d in self:
r += "%02x" %d r += "{:02x}".format(d)
return r return r
class ICMP(Module): class ICMP(Module):

View File

@ -55,10 +55,10 @@ class IPPacket(Packet):
def __repr__(self): def __repr__(self):
r = "--------\n" r = "--------\n"
for k in sorted(ipv4_header.keys()): 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: " r += "payload: "
for d in self: for d in self:
r += "%02x" %d r += "{:02x}".format(d)
return r return r
class IP(Module): class IP(Module):
@ -101,7 +101,7 @@ class IP(Module):
received = packet.get_checksum() received = packet.get_checksum()
packet.insert_checksum() packet.insert_checksum()
expected = packet.get_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() packet.decode()
if self.debug: if self.debug:
print_ip("<<<<<<<<") print_ip("<<<<<<<<")

View File

@ -77,10 +77,10 @@ class MACPacket(Packet):
def __repr__(self): def __repr__(self):
r = "--------\n" r = "--------\n"
for k in sorted(mac_header.keys()): 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: " r += "payload: "
for d in self: for d in self:
r += "%02x" %d r += "{:02x}".format(d)
return r return r
class MAC(Module): class MAC(Module):

View File

@ -35,7 +35,7 @@ class PHY(Module):
r = ">>>>>>>>\n" r = ">>>>>>>>\n"
r += "length " + str(len(datas)) + "\n" r += "length " + str(len(datas)) + "\n"
for d in datas: for d in datas:
r += "%02x" %d r += "{:02x}".format(d)
print_phy(r) print_phy(r)
self.phy_source.send(packet) self.phy_source.send(packet)
@ -45,7 +45,7 @@ class PHY(Module):
r = "<<<<<<<<\n" r = "<<<<<<<<\n"
r += "length " + str(len(self.phy_sink.packet)) + "\n" r += "length " + str(len(self.phy_sink.packet)) + "\n"
for d in self.phy_sink.packet: for d in self.phy_sink.packet:
r += "%02x" %d r += "{:02x}".format(d)
print_phy(r) print_phy(r)
self.packet = self.phy_sink.packet self.packet = self.phy_sink.packet

View File

@ -31,10 +31,10 @@ class UDPPacket(Packet):
def __repr__(self): def __repr__(self):
r = "--------\n" r = "--------\n"
for k in sorted(udp_header.keys()): 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: " r += "payload: "
for d in self: for d in self:
r += "%02x" %d r += "{:02x}".format(d)
return r return r
class UDP(Module): class UDP(Module):