Skip to content

Commit aa0a4fb

Browse files
committed
issues with chinese character encoding, utf-16
1 parent 25a2f3f commit aa0a4fb

File tree

8 files changed

+25
-3
lines changed

8 files changed

+25
-3
lines changed

domain_validation/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import unicode_literals
33
WHOIS_PORT = 43
44
WHOIS_RESPONSE_LEN_LIMIT = 10000
5-
WHOIS_PORTION_SIZE = 64
5+
WHOIS_PORTION_SIZE = 1024
66
SERVERS = {
77
"ac": "whois.nic.ac",
88
"ae": "whois.aeda.net.ae",

domain_validation/parse_date.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
import re
24
from datetime import datetime
35
from domain_validation.constants import MONTHS

domain_validation/registrar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
import re
24
from domain_validation.constants import SERVER_NOT_FOUND, REGISTRAR_NOT_FOUND
35

158 Bytes
Binary file not shown.
Binary file not shown.

domain_validation/test/test_whois_obj.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,38 @@ def test_WHOIS_com2():
1717
assert str(whois.creation_date()) == "1995-01-18"
1818
assert whois.registrar() == "MarkMonitor Inc."
1919

20+
2021
def test_WHOIS_org():
2122
sleep(.1)
2223
whois = WHOIS("npr.org")
2324
assert str(whois.creation_date()) == "1993-12-13"
2425
assert whois.registrar() == "Network Solutions, LLC"
2526

27+
2628
def test_WHOIS_uk():
2729
sleep(.1)
2830
whois = WHOIS("wow.uk")
2931
assert str(whois.creation_date()) == "2014-06-11"
3032
assert whois.registrar() == "Planet Hippo Internet Ltd t/a EUKHOST [Tag = PLANETHIPPO]"
3133

34+
3235
def test_WHOIS_com_silo():
3336
sleep(.1)
3437
whois = WHOIS("1shivom.com")
3538
assert str(whois.creation_date()) == "2018-07-30"
3639
assert whois.registrar() == "NameSilo, LLC"
3740

41+
3842
def test_WHOIS_cn():
3943
sleep(.1)
4044
whois = WHOIS("yo.cn")
4145
assert str(whois.creation_date()) == '2003-03-17'
4246
assert whois.registrar() == '浙江贰贰网络有限公司'
47+
48+
49+
def test_WHOIS_utf_encoding():
50+
sleep(.1)
51+
whois = WHOIS("我爱你.中国")
52+
assert str(whois.creation_date()) == '2004-01-06'
53+
assert whois.registrar() == '北京新网互联科技有限公司'
54+

domain_validation/whois.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
13
from domain_validation.whois_client import query_whois
24
from domain_validation.creation_date import get_domain_creation_date
35
from domain_validation.registrar import get_registrar

domain_validation/whois_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# -*- coding: utf-8 -*-
1+
# -*- coding: utf-8 -*-
2+
23
import socket
34
from domain_validation.constants import WHOIS_PORTION_SIZE, WHOIS_PORT, WHOIS_RESPONSE_LEN_LIMIT, SERVERS, SERVER_NOT_FOUND
45

@@ -13,7 +14,10 @@ def query_whois(domain):
1314
sock.send((domain + "\r\n").encode('utf-8'))
1415
whois_response = ''
1516
while len(whois_response) < WHOIS_RESPONSE_LEN_LIMIT:
16-
response_portion = sock.recv(WHOIS_PORTION_SIZE).decode('utf-8')
17+
try:
18+
response_portion = sock.recv(WHOIS_PORTION_SIZE).decode('utf-8')
19+
except Exception as e:
20+
response_portion = sock.recv(WHOIS_PORTION_SIZE).decode('utf-16')
1721
if response_portion == '':
1822
break
1923
whois_response += response_portion

0 commit comments

Comments
 (0)