From 72aa7b6143e7f476e8857fef165be95b95c16dc5 Mon Sep 17 00:00:00 2001
From: gpotter2 <gabriel@potter.fr>
Date: Tue, 2 May 2017 15:35:52 +0200
Subject: [PATCH] Better doc + small format fixes

---
 CONTRIBUTING.md        | 4 +++-
 scapy/arch/linux.py    | 2 +-
 scapy/asn1/ber.py      | 2 +-
 scapy/contrib/http2.py | 2 +-
 scapy/dadict.py        | 2 +-
 scapy/layers/dhcp6.py  | 4 ++--
 scapy/layers/isakmp.py | 2 +-
 7 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a1613cee..5e101fad 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -113,7 +113,9 @@ Scapy's performances.
 ### Python 2 and 3 compatibility
 
 The project aims to provide code that works both on Python 2 and Python 3. Therefore, some rules need to be apply to achieve compatibility:
-- byte-string must be defined as b"\x00\x01\x02"
+- byte-string must be defined as `b"\x00\x01\x02"`
+- exceptions must comply with the new Python 3 format: `except SomeError as e:`
+- lambdas must be written using a single argument when using tuples: use `lambda x_y: x_y[0] + f(x_y[1])` instead of `lambda (x, y): x + f(y)`.
 
 ### Code review
 
diff --git a/scapy/arch/linux.py b/scapy/arch/linux.py
index b6f94b6c..39117f9e 100644
--- a/scapy/arch/linux.py
+++ b/scapy/arch/linux.py
@@ -359,7 +359,7 @@ else:
 
 
 def _flush_fd(fd):
-    if not isinstance(fd, int):
+    if hasattr(fd, 'fileno'):
         fd = fd.fileno()
     while True:
         r,w,e = select([fd],[],[],0)
diff --git a/scapy/asn1/ber.py b/scapy/asn1/ber.py
index f1dc2901..0fd9b4f4 100644
--- a/scapy/asn1/ber.py
+++ b/scapy/asn1/ber.py
@@ -256,7 +256,7 @@ class BERcodec_Object:
 
     @classmethod
     def enc(cls, s):
-        if isinstance(s, str):
+        if isinstance(s, basestring):
             return BERcodec_STRING.enc(s)
         else:
             return BERcodec_INTEGER.enc(int(s))
diff --git a/scapy/contrib/http2.py b/scapy/contrib/http2.py
index a6a7356d..4ff53c1b 100644
--- a/scapy/contrib/http2.py
+++ b/scapy/contrib/http2.py
@@ -192,7 +192,7 @@ class AbstractUVarIntField(fields.Field):
         @return None
         @raise AssertionError
         """
-        assert(isinstance(default, type(None)) or (isinstance(default, (int, long)) and default >= 0))
+        assert(default is None or (isinstance(default, (int, long)) and default >= 0))
         assert(0 < size <= 8)
         super(AbstractUVarIntField, self).__init__(name, default)
         self.size = size
diff --git a/scapy/dadict.py b/scapy/dadict.py
index aa2e834c..67cb8515 100644
--- a/scapy/dadict.py
+++ b/scapy/dadict.py
@@ -35,7 +35,7 @@ class DADict:
     def __setitem__(self, attr, val):        
         return setattr(self, self.fixname(attr), val)
     def __iter__(self):
-        return iter(map(lambda x_y1:x_y1[1],filter(lambda x_y:x_y[0] and x_y[0][0]!="_", self.__dict__.items())))
+        return iter(map(lambda x_y1: x_y1[1],filter(lambda x_y: x_y[0] and x_y[0][0]!="_", self.__dict__.items())))
     def _show(self):
         for k in self.__dict__.keys():
             if k and k[0] != "_":
diff --git a/scapy/layers/dhcp6.py b/scapy/layers/dhcp6.py
index 62199d25..45eb8607 100644
--- a/scapy/layers/dhcp6.py
+++ b/scapy/layers/dhcp6.py
@@ -1408,7 +1408,7 @@ dhcp6d( dns="2001:500::1035", domain="localdomain, local", duid=None)
                 return False
             # provided server DUID must match ours
             duid = p[DHCP6OptServerId].duid
-            if (not isinstance(duid, type(self.duid))):
+            if not isinstance(duid, type(self.duid)):
                 return False
             if str(duid) != str(self.duid):
                 return False
@@ -1475,7 +1475,7 @@ dhcp6d( dns="2001:500::1035", domain="localdomain, local", duid=None)
         elif p.msgtype == 11: # Information-Request
             if DHCP6OptServerId in p:
                 duid = p[DHCP6OptServerId].duid
-                if (not isinstance(duid, type(self.duid))):
+                if not isinstance(duid, type(self.duid)):
                     return False
                 if str(duid) != str(self.duid):
                     return False
diff --git a/scapy/layers/isakmp.py b/scapy/layers/isakmp.py
index a1ec87f2..f612f280 100644
--- a/scapy/layers/isakmp.py
+++ b/scapy/layers/isakmp.py
@@ -103,7 +103,7 @@ del(val)
 class ISAKMPTransformSetField(StrLenField):
     islist=1
     def type2num(self, type_val_tuple):
-        (typ,val) = type_val_tuple
+        typ, val = type_val_tuple
         type_val,enc_dict,tlv = ISAKMPTransformTypes.get(typ, (typ,{},0))
         val = enc_dict.get(val, val)
         s = ""
-- 
GitLab