Commits

paulc  committed ec79657

Case insensitive label __eq__

  • Participants
  • Parent commits 91b303c
  • Branches py3

Comments (0)

Files changed (3)

File dnslib/dns.py

         """
         # Unknown rata - assume hexdump in zone format
         # (DiG prepends "\\# <len>" to the hexdump so get last item)
-        return cls(binascii.unhexlify(rd[-1]))
+        return cls(binascii.unhexlify(rd[-1].encode('ascii')))
 
     def __init__(self,data=b""):
         # Assume raw bytes

File dnslib/label.py

     >>> l2 = DNSLabel([b"aaa",b"bbb",b"ccc"])
     >>> l1 == l2
     True
+    >>> l3 = DNSLabel("AAA.BBB.CCC")
+    >>> l1 == l3
+    True
+    >>> l1 == 'AAA.BBB.CCC'
+    True
     >>> x = { l1 : 1 }
     >>> x[l1]
     1
     def __hash__(self):
         return hash(self.label)
 
+    def __ne__(self,other):
+        return not self == other
+
     def __eq__(self,other):
         if type(other) != DNSLabel:
-            return self.label == DNSLabel(other).label
+            return self.__eq__(DNSLabel(other))
         else:
-            return self.label == other.label
+            return [ l.lower() for l in self.label ] == \
+                   [ l.lower() for l in other.label ]
 
     def __len__(self):
         return len(b'.'.join(self.label))

File dnslib/test_decode.py

 
 import argparse,binascii,code,glob,os,os.path
 
+try: 
+    input = raw_input
+except NameError: 
+    pass
+
 def new_test(domain,qtype,address="8.8.8.8",port=53):
     tcp = False
     q = DNSRecord.question(domain,qtype)
 
             if errors == 0:
                 print("OK")
-            #elif raw_input("Inspect [y/n]?").lower().startswith('y'):
-            #    code.interact(local=locals())
+            elif input("Inspect [y/n]?").lower().startswith('y'):
+                code.interact(local=locals())