Skip to content

Commit

Permalink
simplify punycode logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Penman authored and Richard Penman committed Jan 15, 2025
1 parent 93748ea commit c634f85
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def read(filename):
version="0.9.5",
description="Whois querying and parsing of domain registration information.",
long_description=read("README.md"),
long_description_content_type='text/markdown',
long_description_content_type="text/markdown",
classifiers=[
"Environment :: Web Environment",
"Intended Audience :: Developers",
Expand Down
7 changes: 2 additions & 5 deletions whois/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ def whois(
# try builtin client
nic_client = NICClient()
if convert_punycode:
text = nic_client.whois_lookup(
None, domain.encode("idna").decode("utf-8"), flags, quiet=quiet
)
else:
text = nic_client.whois_lookup(None, domain, flags, quiet=quiet)
domain = domain.encode("idna").decode("utf-8")
text = nic_client.whois_lookup(None, domain, flags, quiet=quiet)
entry = WhoisEntry.load(domain, text)
if inc_raw:
entry["raw"] = text
Expand Down
9 changes: 4 additions & 5 deletions whois/whois.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,14 @@ def whois(
nhost = self.findwhois_server(response_str, hostname, query)
if nhost is not None and nhost != "":
response_str += self.whois(query, nhost, 0, quiet=True)
except (
socket.error
) as exc: # 'response' is assigned a value (also a str) even on socket timeout
except socket.error as e:
# 'response' is assigned a value (also a str) even on socket timeout
if not quiet:
logger.error(
"Error trying to connect to socket: closing socket - {}".format(exc)
"Error trying to connect to socket: closing socket - {}".format(e)
)
s.close()
response_str = "Socket not responding: {}".format(exc)
response_str = "Socket not responding: {}".format(e)
return response_str

def choose_server(self, domain: str) -> Optional[str]:
Expand Down

0 comments on commit c634f85

Please sign in to comment.