whois/__init__.py
changeset 98 3202436d89d0
parent 86 d6fcfa5acc7b
parent 97 44522cd37b07
child 122 95feee1af1da
--- a/whois/__init__.py	Thu Jun 02 13:59:46 2016 -0700
+++ b/whois/__init__.py	Thu Jun 02 14:05:21 2016 -0700
@@ -57,17 +57,18 @@
         return socket.gethostbyaddr(url)[0]
 
     tlds_path = os.path.join(os.getcwd(), os.path.dirname(__file__), 'data', 'tlds.txt')
-    suffixes = [
-        line.lower().strip().encode('utf-8')
-        for line in open(tlds_path).readlines()
-        if not line.startswith('#')
-    ]
+    with open(tlds_path) as tlds_fil:
+        suffixes = [line.lower().encode('utf-8')
+                    for line in (x.strip() for x in tlds_fil)
+                    if not line.startswith('#')]
+    suff = 'xn--p1ai'
 
     if not isinstance(url, str):
         url = url.decode('utf-8')
-    url = re.sub(b'^.*://', b'', url.encode('idna')).split(b'/')[0].lower()
+    url = re.sub('^.*://', '', url)
+    url = url.split('/')[0].lower().encode('idna')
+
     domain = []
-
     for section in url.split(b'.'):
         if section in suffixes:
             domain.append(section)