Ensure lookups work with both unicode and bytes objects
authorEvgeni Kunev <evgeni.kunev@gmail.com>
Mon, 18 Aug 2014 13:10:53 +0300
changeset 38 da8f2956db7e
parent 37 8ad334b5363b
child 39 68375a768598
Ensure lookups work with both unicode and bytes objects
whois/__init__.py
--- a/whois/__init__.py	Mon Aug 18 11:36:24 2014 +0300
+++ b/whois/__init__.py	Mon Aug 18 13:10:53 2014 +0300
@@ -56,14 +56,12 @@
         if not line.startswith('#')
     ]
 
-    url = re.sub('^.*://', '', url).split('/')[0].lower()
+    if type(url) is not unicode:
+        url = url.decode('utf-8')
+    url = re.sub('^.*://', '', url.encode('idna')).split('/')[0].lower()
     domain = []
-    url_sections = (
-        section.decode('utf-8').encode('idna')
-        for section in url.split('.')
-    )
 
-    for section in url_sections:
+    for section in url.split('.'):
         if section in suffixes:
             domain.append(section)
         else: