From 512dbae4020ea33ec15fc10e81b8303e5fa26e1f Mon Sep 17 00:00:00 2001 From: "omer.gul" Date: Fri, 11 Oct 2024 00:12:07 +0300 Subject: [PATCH 1/7] tr domains not support idna encoded decoded whois requests --- whois/parser.py | 2 +- whois/whois.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/whois/parser.py b/whois/parser.py index 2f89b7f..7037496 100644 --- a/whois/parser.py +++ b/whois/parser.py @@ -173,7 +173,7 @@ def __str__(self): def handler(e): return str(e) - return json.dumps(self, indent=2, default=handler) + return json.dumps(self, indent=2, default=handler, ensure_ascii=False) def __getstate__(self): return self.__dict__ diff --git a/whois/whois.py b/whois/whois.py index 64a3691..9c238e4 100644 --- a/whois/whois.py +++ b/whois/whois.py @@ -255,6 +255,8 @@ def choose_server(self, domain): """Choose initial lookup NIC host""" try: domain = domain.encode("idna").decode("utf-8") + if domain.endswith(".tr"): + domain = domain except TypeError: domain = domain.decode("utf-8").encode("idna").decode("utf-8") except AttributeError: From 5283311662cf4b4a6cbfd5caf0882c19815b133c Mon Sep 17 00:00:00 2001 From: "omer.gul" Date: Fri, 11 Oct 2024 00:19:32 +0300 Subject: [PATCH 2/7] set request for tr domains without idna --- whois/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/whois/__init__.py b/whois/__init__.py index 3c1d9ff..9d480f6 100644 --- a/whois/__init__.py +++ b/whois/__init__.py @@ -43,7 +43,10 @@ def whois(url, command=False, flags=0, executable="whois", inc_raw=False, quiet= else: # try builtin client nic_client = NICClient() - text = nic_client.whois_lookup(None, domain.encode("idna"), flags, quiet=quiet) + if domain.endswith(".tr"): + text = nic_client.whois_lookup(None, domain, flags, quiet=quiet) + else: + text = nic_client.whois_lookup(None, domain.encode("idna"), flags, quiet=quiet) entry = WhoisEntry.load(domain, text) if inc_raw: entry["raw"] = text From 1415edfa183dbc7dad1ffce3aaeb2358e0c99698 Mon Sep 17 00:00:00 2001 From: "omer.gul" Date: Thu, 31 Oct 2024 16:25:12 +0300 Subject: [PATCH 3/7] quick fix for tr domain --- whois/whois.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/whois/whois.py b/whois/whois.py index 9c238e4..2b82521 100644 --- a/whois/whois.py +++ b/whois/whois.py @@ -254,9 +254,8 @@ def whois(self, query, hostname, flags, many_results=False, quiet=False, timeout def choose_server(self, domain): """Choose initial lookup NIC host""" try: - domain = domain.encode("idna").decode("utf-8") - if domain.endswith(".tr"): - domain = domain + if not domain.endswith(".tr"): + domain = domain.encode("idna").decode("utf-8") except TypeError: domain = domain.decode("utf-8").encode("idna").decode("utf-8") except AttributeError: From e23ea2e3151ecc3fc16b33dafdf0188b43fcaa43 Mon Sep 17 00:00:00 2001 From: "omer.gul" Date: Thu, 31 Oct 2024 18:53:01 +0300 Subject: [PATCH 4/7] add convert_punycode flag --- .DS_Store | Bin 0 -> 6148 bytes whois/__init__.py | 9 ++++----- whois/whois.py | 13 ++++++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..9d0beb06c1f3d9024cbba3ae6746353f5822c1a9 GIT binary patch literal 6148 zcmeH~J&pn~427S8m5{cfq)fvBxIu*26YK@hLID!e6lg`8qx0;zVU`+=R?m|2Vke%T zub7Mh*zWhV1y%r-bXRPA7@0Btz#V4{xZrlW9j`ybaP>51xz__aukpN|%MuX~0TB=Z z5fFh15r{*a=l|z~o=J})0wORC0{(p{bk~~Ny2hu2L$moUem+4UVK8WsjVwBH2nw! K1`Q(cRss)A+!Lb! literal 0 HcmV?d00001 diff --git a/whois/__init__.py b/whois/__init__.py index 9d480f6..8e081d3 100644 --- a/whois/__init__.py +++ b/whois/__init__.py @@ -23,7 +23,7 @@ ) -def whois(url, command=False, flags=0, executable="whois", inc_raw=False, quiet=False): +def whois(url, command=False, flags=0, executable="whois", inc_raw=False, quiet=False, convert_punycode=True): # clean domain to expose netloc ip_match = IPV4_OR_V6.match(url) if ip_match: @@ -43,10 +43,9 @@ def whois(url, command=False, flags=0, executable="whois", inc_raw=False, quiet= else: # try builtin client nic_client = NICClient() - if domain.endswith(".tr"): - text = nic_client.whois_lookup(None, domain, flags, quiet=quiet) - else: - text = nic_client.whois_lookup(None, domain.encode("idna"), flags, quiet=quiet) + if convert_punycode: + domain = domain.encode("idna") + text = nic_client.whois_lookup(None, domain, flags, quiet=quiet) entry = WhoisEntry.load(domain, text) if inc_raw: entry["raw"] = text diff --git a/whois/whois.py b/whois/whois.py index 2b82521..e9a12b4 100644 --- a/whois/whois.py +++ b/whois/whois.py @@ -254,8 +254,7 @@ def whois(self, query, hostname, flags, many_results=False, quiet=False, timeout def choose_server(self, domain): """Choose initial lookup NIC host""" try: - if not domain.endswith(".tr"): - domain = domain.encode("idna").decode("utf-8") + domain = domain.encode("idna").decode("utf-8") except TypeError: domain = domain.decode("utf-8").encode("idna").decode("utf-8") except AttributeError: @@ -563,6 +562,14 @@ def parse_command_line(argv): dest="whoishost", help="Lookup using host " + NICClient.RNICHOST, ) + parser.add_option( + "-P", + "--no-punycode", + action="store_false", + dest="nopunycode", + help="No convert punycode", + default = True, + ) parser.add_option( "-R", "--ru", @@ -598,4 +605,4 @@ def parse_command_line(argv): options, args = parse_command_line(sys.argv) if options.b_quicklookup: flags = flags | NICClient.WHOIS_QUICK - logger.debug(nic_client.whois_lookup(options.__dict__, args[1], flags)) + logger.debug(nic_client.whois_lookup(options.__dict__, args[1], flags, options.nopunycode)) From a1fd74dcd2c62745002dd14c3a330ef9283621b1 Mon Sep 17 00:00:00 2001 From: "omer.gul" Date: Thu, 31 Oct 2024 18:53:46 +0300 Subject: [PATCH 5/7] remove .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 9d0beb06c1f3d9024cbba3ae6746353f5822c1a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~J&pn~427S8m5{cfq)fvBxIu*26YK@hLID!e6lg`8qx0;zVU`+=R?m|2Vke%T zub7Mh*zWhV1y%r-bXRPA7@0Btz#V4{xZrlW9j`ybaP>51xz__aukpN|%MuX~0TB=Z z5fFh15r{*a=l|z~o=J})0wORC0{(p{bk~~Ny2hu2L$moUem+4UVK8WsjVwBH2nw! K1`Q(cRss)A+!Lb! From dcb71371af69404d98eb9a25a25cf9a117a16f3b Mon Sep 17 00:00:00 2001 From: "omer.gul" Date: Thu, 31 Oct 2024 18:59:20 +0300 Subject: [PATCH 6/7] quick-fix --- whois/whois.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/whois/whois.py b/whois/whois.py index e9a12b4..64a3691 100644 --- a/whois/whois.py +++ b/whois/whois.py @@ -562,14 +562,6 @@ def parse_command_line(argv): dest="whoishost", help="Lookup using host " + NICClient.RNICHOST, ) - parser.add_option( - "-P", - "--no-punycode", - action="store_false", - dest="nopunycode", - help="No convert punycode", - default = True, - ) parser.add_option( "-R", "--ru", @@ -605,4 +597,4 @@ def parse_command_line(argv): options, args = parse_command_line(sys.argv) if options.b_quicklookup: flags = flags | NICClient.WHOIS_QUICK - logger.debug(nic_client.whois_lookup(options.__dict__, args[1], flags, options.nopunycode)) + logger.debug(nic_client.whois_lookup(options.__dict__, args[1], flags)) From efe3ec39c71f76efc9234c2914d8def728fbdd4b Mon Sep 17 00:00:00 2001 From: "omer.gul" Date: Sat, 2 Nov 2024 00:56:45 +0300 Subject: [PATCH 7/7] fix tests --- whois/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/whois/__init__.py b/whois/__init__.py index 8e081d3..a099dd3 100644 --- a/whois/__init__.py +++ b/whois/__init__.py @@ -44,8 +44,9 @@ def whois(url, command=False, flags=0, executable="whois", inc_raw=False, quiet= # try builtin client nic_client = NICClient() if convert_punycode: - domain = domain.encode("idna") - text = nic_client.whois_lookup(None, domain, flags, quiet=quiet) + text = nic_client.whois_lookup(None, domain.encode("idna"), flags, quiet=quiet) + else: + text = nic_client.whois_lookup(None, domain, flags, quiet=quiet) entry = WhoisEntry.load(domain, text) if inc_raw: entry["raw"] = text