Skip to content

Commit 79af46c

Browse files
committed
Fix Punycode and Normal Text conversion.
1 parent 393857b commit 79af46c

5 files changed

Lines changed: 16 additions & 16 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ip2whois_init = ip2whois.Api('YOUR_API_KEY')
3737

3838

3939
# Convert normal text to punycode
40-
result = ip2whois_init.getPunycode('xn--tst-qla.de')
40+
result = ip2whois_init.getPunycode('täst.de')
4141
print(result)
4242
```
4343

@@ -51,7 +51,7 @@ ip2whois_init = ip2whois.Api('YOUR_API_KEY')
5151

5252

5353
# Convert punycode to normal text
54-
result = ip2whois_init.getNormalText('täst.de')
54+
result = ip2whois_init.getNormalText('xn--tst-qla.de')
5555
print(result)
5656
```
5757

example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
print(results)
99

1010
# Convert normal text to punycode
11-
result = ip2whois_init.getPunycode('xn--tst-qla.de')
11+
result = ip2whois_init.getPunycode('täst.de')
1212
print(result)
1313

1414
# Convert punycode to normal text
15-
result = ip2whois_init.getNormalText('täst.de')
15+
result = ip2whois_init.getNormalText('xn--tst-qla.de')
1616
print(result)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="IP2WHOIS",
8-
version="2.0.0",
8+
version="2.1.0",
99
author="IP2WHOIS",
1010
author_email="support@ip2whois.com",
1111
description="IP2WHOIS Python SDK to help user to check WHOIS information for a particular domain.",

src/ip2whois/api.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ def lookup(self, domain = ''):
4848
return None
4949

5050
def getPunycode(self, domain = ''):
51-
if sys.version < '3':
52-
converted_result = unicode(domain if domain else '').encode('ascii').decode('idna')
51+
domain = domain if domain else ''
52+
if sys.version < '3':
53+
converted_result = domain.encode('idna').decode('ascii')
5354
return converted_result.encode('utf-8')
54-
else:
55-
return domain.encode('ascii').decode('idna')
55+
else:
56+
return domain.encode('idna').decode('ascii')
5657

5758
def getNormalText(self, domain = ''):
58-
domain = domain if domain else ''
5959
if sys.version < '3':
60-
converted_result = domain.encode('idna').decode('ascii')
60+
converted_result = unicode(domain if domain else '').encode('ascii').decode('idna')
6161
return converted_result.encode('utf-8')
6262
else:
63-
return domain.encode('idna').decode('ascii')
63+
return domain.encode('ascii').decode('idna')

tests/test_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def test_function_exist(global_data):
3636

3737
def test_get_puny_code(global_data):
3838
ip2whois_init = ip2whois.Api(global_data["apikey"])
39-
result = ip2whois_init.getPunycode('xn--tst-qla.de')
40-
assert result == "täst.de"
39+
result = ip2whois_init.getPunycode('täst.de')
40+
assert result == "xn--tst-qla.de"
4141

4242
def test_get_normal_text(global_data):
4343
ip2whois_init = ip2whois.Api(global_data["apikey"])
44-
result = ip2whois_init.getNormalText('täst.de')
45-
assert result == "xn--tst-qla.de"
44+
result = ip2whois_init.getNormalText('xn--tst-qla.de')
45+
assert result == "täst.de"

0 commit comments

Comments
 (0)