Merged in mariosantana/pywhois (pull request #7)
authorRichard Penman <richardbp@gmail.com>
Thu, 02 Jun 2016 14:05:21 -0700
changeset 98 3202436d89d0
parent 93 acdc2cb09f60 (diff)
parent 97 44522cd37b07 (current diff)
child 99 67b90bfc59c7
child 100 b5699d950712
Merged in mariosantana/pywhois (pull request #7) Regression in queries from python3
whois/__init__.py
--- a/whois/__init__.py	Fri Apr 15 18:29:24 2016 -0600
+++ b/whois/__init__.py	Thu Jun 02 14:05:21 2016 -0700
@@ -19,6 +19,12 @@
     ip_match = re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", url)
     if ip_match:
         domain = url
+        try:
+            result = socket.gethostbyaddr(url)
+        except socket.herror as e:
+            pass
+        else:
+            domain = result[0]
     else:
         domain = extract_domain(url)
     if command:
--- a/whois/parser.py	Fri Apr 15 18:29:24 2016 -0600
+++ b/whois/parser.py	Thu Jun 02 14:05:21 2016 -0700
@@ -135,6 +135,8 @@
                     if value and value not in values:
                         # avoid duplicates
                         values.append(value)
+                if values and attr in ('registrar', 'whois_server', 'referral_url'):
+                    values = values[-1] # ignore junk
                 if len(values) == 1:
                     values = values[0]
                 elif not values:
@@ -149,7 +151,7 @@
 
     def __getattr__(self, name):
         return self.get(name)
-        
+
 
     def __str__(self):
         handler = lambda e: str(e)
@@ -204,6 +206,8 @@
             return WhoisBg(domain, text)
         elif domain.endswith('.de'):
             return WhoisDe(domain, text)
+        elif domain.endswith('.at'):
+            return WhoisAt(domain, text)
         elif domain.endswith('.ca'):
             return WhoisCa(domain, text)
         elif domain.endswith('.be'):
@@ -222,6 +226,10 @@
             return WhoisBiz(domain, text)
         elif domain.endswith('.mobi'):
             return WhoisMobi(domain, text)
+        elif domain.endswith('.ch'):
+            return WhoisChLi(domain, text)
+        elif domain.endswith('.li'):
+            return WhoisChLi(domain, text)
         else:
             return WhoisEntry(domain, text)
 
@@ -261,7 +269,7 @@
         'status':           'Status: *(.+)', # list of statuses
         'emails':           EMAIL_REGEX, # list of email addresses
     }
-    
+
     def __init__(self, domain, text):
         if text.strip() == 'NOT FOUND':
             raise PywhoisError(text)
@@ -316,7 +324,7 @@
                 self['zip_code'], _, self['city'] = lines[2].partition(' ')
             self['country'] = lines[-1]
 
-                
+
 
 class WhoisName(WhoisEntry):
     """Whois parser for .name domains
@@ -561,7 +569,7 @@
         'domain_name': 'domain: *(.+)',
         'registrar': 'registrar: *(.+)',
         'creation_date': 'created: *(.+)',
-        'expiration_date': 'anniversary: *(.+)',
+        'expiration_date': 'Expir\w+ Date:\s?(.+)',
         'name_servers': 'nserver: *(.+)',  # list of name servers
         'status': 'status: *(.+)',  # list of statuses
         'emails': EMAIL_REGEX,  # list of email addresses
@@ -588,7 +596,7 @@
         'updated_date':                   'modified: *([\S]+)',
         'expiration_date':                'expires: *([\S]+)',
         'name_servers':                   'nserver: *([\S]+) \[\S+\]',  # list of name servers
-        'name_server_statuses':           'nserver: *([\S]+) \[(\S+)\]',  # list of name servers and statuses
+        'name_server_statuses':           'nserver: *([\S]+) \[\S+\]',  # list of name servers and statuses
         'dnssec':                         'dnssec: *([\S]+)',
     }
 
@@ -771,6 +779,26 @@
         else:
             WhoisEntry.__init__(self, domain, text, self.regex)
 
+class WhoisAt(WhoisEntry):
+    """Whois parser for .at domains
+    """
+    regex = {
+        'name': 'personname: *(.+)',
+        'org': 'organization: *(.+)',
+        'address': 'street address: *(.+)',
+        'zipcode': 'postal code: *(.+)',
+        'city': 'city: *(.+)',
+        'country': 'country: *(.+)',
+        'phone': 'phone: *(.+)',
+        'fax': 'fax-no: *(.+)',
+        'changed': 'changed: *(.+)',
+    }
+
+    def __init__(self, domain, text):
+        if 'Status: free' in text:
+            raise PywhoisError(text)
+        else:
+            WhoisEntry.__init__(self, domain, text, self.regex)
 
 class WhoisBe(WhoisEntry):
     """Whois parser for .be domains
@@ -970,3 +998,22 @@
             raise PywhoisError(text)
         else:
             WhoisEntry.__init__(self, domain, text, self.regex)
+
+
+class WhoisChLi(WhoisEntry):
+    """Whois Parser for .ch and .li domains
+    """
+    regex = {
+        'domain_name':                      '\nDomain name:\n*(.+)',
+        'registrant':                       'Holder of domain name:\n*([\n\s\S]+)\nContractual Language:',
+        'registrar':                        'Registrar:\n*(.+)',
+        'creation_date':                    'First registration date:\n*(.+)',
+        'dnssec':                           'DNSSEC:*([\S]+)',
+        'tech-c':                           'Technical contact:\n*([\n\s\S]+)\nRegistrar:',
+        'name_servers':                     'Name servers:\n *([\n\S\s]+)'
+    }
+    def __init__(self,domain,text):
+        if 'We do not have an entry in our database matching your query.' in text:
+            raise PywhoisError(text)
+        else:
+            WhoisEntry.__init__(self, domain, text, self.regex)