Merged in aseques/pywhois (pull request #31)
authorRichard <richardbp@gmail.com>
Mon, 05 Feb 2018 19:47:43 +0000
changeset 163 faaa3ce1af3e
parent 160 c385321ec3e4 (diff)
parent 162 93f6f3021941 (current diff)
child 164 c89f5d13d9d8
child 166 6cbe4891d62a
Merged in aseques/pywhois (pull request #31) Add date format used in .ie domains
whois/parser.py
whois/whois.py
--- a/setup.py	Sat Jan 27 00:34:23 2018 +0100
+++ b/setup.py	Mon Feb 05 19:47:43 2018 +0000
@@ -1,7 +1,7 @@
 import sys, os
 import setuptools
 
-version = '0.6.7'
+version = '0.6.8'
 
 setuptools.setup(
     name='python-whois',
--- a/whois/__init__.py	Sat Jan 27 00:34:23 2018 +0100
+++ b/whois/__init__.py	Mon Feb 05 19:47:43 2018 +0000
@@ -33,7 +33,7 @@
     if command:
         # try native whois command
         r = subprocess.Popen(['whois', domain], stdout=subprocess.PIPE)
-        text = r.stdout.read()
+        text = r.stdout.read().decode()
     else:
         # try builtin client
         nic_client = NICClient()
--- a/whois/parser.py	Sat Jan 27 00:34:23 2018 +0100
+++ b/whois/parser.py	Mon Feb 05 19:47:43 2018 +0000
@@ -272,6 +272,8 @@
             return WhoisCat(domain, text)
         elif domain.endswith('.ie'):
             return WhoisIe(domain, text)
+        elif domain.endswith('.nz'):
+            return WhoisNz(domain, text)
         else:
             return WhoisEntry(domain, text)
 
@@ -1358,3 +1360,29 @@
             raise PywhoisError(text)
         else:
             WhoisEntry.__init__(self, domain, text, self.regex)
+
+
+class WhoisNz(WhoisEntry):
+    """Whois parser for .nz domains
+    """
+    regex = {
+        'domain_name':          'domain_name:\s*([^\n\r]+)',
+        'registrar':            'registrar_name:\s*([^\n\r]+)',
+        'updated_date':         'domain_datelastmodified:\s*([^\n\r]+)',
+        'creation_date':        'domain_dateregistered:\s*([^\n\r]+)',
+        'expiration_date':      'domain_datebilleduntil:\s*([^\n\r]+)',
+        'name_servers':         'ns_name_\d*:\s*([^\n\r]+)',  # list of name servers
+        'status':               'status:\s*([^\n\r]+)',  # list of statuses
+        'emails':               EMAIL_REGEX,  # list of email s
+        'name':                 'registrant_contact_name:\s*([^\n\r]+)',
+        'address':              'registrant_contact_address\d*:\s*([^\n\r]+)',
+        'city':                 'registrant_contact_city:\s*([^\n\r]+)',
+        'zipcode':              'registrant_contact_postalcode:\s*([^\n\r]+)',
+        'country':              'registrant_contact_country:\s*([^\n\r]+)',
+    }
+
+    def __init__(self, domain, text):
+        if 'no matching objects' in text:
+            raise PywhoisError(text)
+        else:
+            WhoisEntry.__init__(self, domain, text, self.regex)
--- a/whois/whois.py	Sat Jan 27 00:34:23 2018 +0100
+++ b/whois/whois.py	Mon Feb 05 19:47:43 2018 +0000
@@ -75,7 +75,7 @@
         whois server for getting contact details.
         """
         nhost = None
-        match = re.compile('Domain Name: ' + query + '\s*.*?Whois Server: (.*?)\s', flags=re.IGNORECASE|re.DOTALL).search(buf)
+        match = re.compile('Domain Name: {}\s*.*?Whois Server: (.*?)\s'.format(query), flags=re.IGNORECASE|re.DOTALL).search(buf)
         if match:
             nhost = match.groups()[0]
             # if the whois address is domain.tld/something then