Allow explicit usage of NICClient even if whois binary is available
authorEvgeni Kunev <evgeni.kunev@gmail.com>
Fri, 15 Aug 2014 11:59:58 +0300
changeset 33 8c4c05eb65f4
parent 32 5f851e9c196a
child 34 f9da616f15cf
Allow explicit usage of NICClient even if whois binary is available
whois/__init__.py
--- a/whois/__init__.py	Thu Aug 14 18:25:14 2014 +0300
+++ b/whois/__init__.py	Fri Aug 15 11:59:58 2014 +0300
@@ -7,19 +7,23 @@
 from whois import NICClient
 
 
-def whois(url):
+def whois(url, experimental=False):
     # clean domain to expose netloc
     ip_match = re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", url)
     if ip_match:
         domain = url
     else:
         domain = extract_domain(url)
-    try:
-        # try native whois command first
-        r = subprocess.Popen(['whois', domain], stdout=subprocess.PIPE)
-        text = r.stdout.read()
-    except OSError:
-        # try experimental client
+    if not experimental:
+        try:
+            # try native whois command first
+            r = subprocess.Popen(['whois', domain], stdout=subprocess.PIPE)
+            text = r.stdout.read()
+        except OSError:
+            # try experimental client
+            nic_client = NICClient()
+            text = nic_client.whois_lookup(None, domain, 0)
+    else:
         nic_client = NICClient()
         text = nic_client.whois_lookup(None, domain, 0)
     return WhoisEntry.load(domain, text)