# HG changeset patch # User Evgeni Kunev # Date 1408093198 -10800 # Node ID 8c4c05eb65f4dec16070f1e83081d23a84fc15d5 # Parent 5f851e9c196ad727ac6f02ba43119950f64c9abb Allow explicit usage of NICClient even if whois binary is available diff -r 5f851e9c196a -r 8c4c05eb65f4 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)