only focus whois search after find many results, to avoid search failure
authorRichard Penman
Mon, 14 Sep 2015 15:13:50 +0100
changeset 64 2ed54e885571
parent 63 56499470d942
child 65 50b5966b5566
only focus whois search after find many results, to avoid search failure
setup.py
whois/parser.py
whois/whois.py
--- a/setup.py	Tue Sep 08 11:09:27 2015 +0800
+++ b/setup.py	Mon Sep 14 15:13:50 2015 +0100
@@ -1,7 +1,7 @@
 import sys, os
 import setuptools
 
-version = '0.5'
+version = '0.5.1'
 
 setuptools.setup(
     name='python-whois',
--- a/whois/parser.py	Tue Sep 08 11:09:27 2015 +0800
+++ b/whois/parser.py	Mon Sep 14 15:13:50 2015 +0100
@@ -296,12 +296,13 @@
 
         match = re.compile('Registrar:(.*?)DNSSEC', re.DOTALL).search(text)
         if match:
-            lines = match.groups()[0].strip().splitlines()
-            self.name = lines[0]
-            self.address = lines[1]
+            lines = [line.strip() for line in match.groups()[0].strip().splitlines()]
+            self['name'] = lines[0]
+            self['address'] = lines[1]
             if len(lines) == 4:
-                self.zip_code, _, self.city = lines[2].partition(' ')
-            self.country = lines[-1]
+                self['zip_code'], _, self['city'] = lines[2].partition(' ')
+            self['country'] = lines[-1]
+
                 
 
 class WhoisName(WhoisEntry):
--- a/whois/whois.py	Tue Sep 08 11:09:27 2015 +0800
+++ b/whois/whois.py	Mon Sep 14 15:13:50 2015 +0100
@@ -90,7 +90,7 @@
                     break
         return nhost
 
-    def whois(self, query, hostname, flags):
+    def whois(self, query, hostname, flags, many_results=False):
         """Perform initial lookup with TLD whois server
         then, if the quick flag is false, search that result
         for the region-specifc whois server and do a lookup
@@ -107,7 +107,7 @@
 
             if hostname == NICClient.DENICHOST:
                 queryBytes = "-T dn,ace -C UTF-8 " + query
-            elif hostname.endswith(NICClient.QNICHOST_TAIL):
+            elif hostname.endswith(NICClient.QNICHOST_TAIL) and many_results:
                 queryBytes = '=' + query
             else:
                 queryBytes = query
@@ -121,9 +121,11 @@
                     break
             s.close()
         except socket.error as socketerror:
-            print 'Error: ', socketerror
+            print 'Socket Error:', socketerror
         nhost = None
         response = enforce_ascii(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.decode(), hostname, query)
         if nhost is not None: