diff --git a/netarch/__init__.py b/netarch/__init__.py index 6317f23..73ff574 100644 --- a/netarch/__init__.py +++ b/netarch/__init__.py @@ -75,6 +75,7 @@ dbch = (u'·☺☻♥♦♣♠•◘○◙♂♀♪♫☼' u'αßΓπΣσµτΦΘΩδ∞φε∩' u'⁰¹²³⁴⁵⁶⁷⁸⁹ⁱⁿ⁽⁼⁾¤') + def unpack(fmt, buf): """Unpack buf based on fmt, return the rest as a string.""" diff --git a/netarch/crypto.py b/netarch/crypto.py index c6f860d..52f9a56 100644 --- a/netarch/crypto.py +++ b/netarch/crypto.py @@ -138,7 +138,7 @@ def freqgraph(f): return 0 items = [] for c, n in f.iteritems(): - if type(n) != type(0): + if not isinstance(n, int): n = len(n) items.append((c, n)) items.sort(cmp2) @@ -171,8 +171,7 @@ def rot(n, txt): for c in txt: if c.isalpha(): o = ord(c) + n - if ((c.islower() and o > ord('z')) or - (c.isupper() and o > ord('Z'))): + if ((c.islower() and o > ord('z')) or (c.isupper() and o > ord('Z'))): o -= 26 out += chr(o) else: @@ -223,7 +222,7 @@ def adds(txt): class XorMask(object): def __init__(self, mask, stick=False): self.offset = 0 - if type(mask) == type(''): + if isinstance(mask, str): self._mask = tuple(ord(m) for m in mask) else: self._mask = tuple(mask) diff --git a/netarch/ip.py b/netarch/ip.py index c34127e..126e8c7 100644 --- a/netarch/ip.py +++ b/netarch/ip.py @@ -159,9 +159,10 @@ class Frame(object): len(self.payload))) def __arp_repr__(self): - return ' %s(%s)>' % (self.name, - str_of_eth(self.ar_sha), self.src_addr, - str_of_eth(self.ar_tha), self.dst_addr) + return ' %s(%s)>' % ( + self.name, + str_of_eth(self.ar_sha), self.src_addr, + str_of_eth(self.ar_tha), self.dst_addr) class TCP_Recreate(object): @@ -601,7 +602,7 @@ class Packet(UserDict.DictMixin): """Handle data from a Session class.""" data = self.parse(data) - if self.opcode != None: + if self.opcode is not None: try: f = getattr(self, 'opcode_%s' % self.opcode) except AttributeError: