Merged in rothi83/pywhois (pull request #6)
authorRichard Penman <richardbp@gmail.com>
Thu, 02 Jun 2016 13:59:46 -0700
changeset 93 acdc2cb09f60
parent 91 4382433c1fe0 (diff)
parent 92 7d3efe9ad172 (current diff)
child 98 3202436d89d0
Merged in rothi83/pywhois (pull request #6) Extended parser.py to parse .ch and .li domains
whois/parser.py
--- a/whois/__init__.py	Sat Mar 26 18:44:28 2016 +0100
+++ b/whois/__init__.py	Thu Jun 02 13:59:46 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	Sat Mar 26 18:44:28 2016 +0100
+++ b/whois/parser.py	Thu Jun 02 13:59:46 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:
@@ -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'):
@@ -565,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
@@ -592,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]+)',
     }
 
@@ -775,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
--- a/whois/whois.py	Sat Mar 26 18:44:28 2016 +0100
+++ b/whois/whois.py	Thu Jun 02 13:59:46 2016 -0700
@@ -121,7 +121,7 @@
         else:
             nhost = None
             response = response.decode('utf-8', errors='replace')
-            if b'with "=xxx"' in response:
+            if 'with "=xxx"' in response:
                 return self.whois(query, hostname, flags, True)
             if flags & NICClient.WHOIS_RECURSE and nhost is None:
                 nhost = self.findwhois_server(response, hostname, query)