Skip to content

Commit

Permalink
'Refactored by Sourcery' (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: Sourcery AI <>
  • Loading branch information
sourcery-ai[bot] authored Nov 21, 2022
1 parent 0b781e2 commit 03f131b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions uwhoisd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_whois_server(self, zone):
if zone in self.overrides:
server = self.overrides[zone]
else:
server = zone + "." + self.suffix
server = f"{zone}.{self.suffix}"
if ":" in server:
server, port = server.split(":", 1)
port = int(port)
Expand All @@ -99,7 +99,7 @@ def whois(self, query):
"""
# Figure out the zone whose WHOIS server we're meant to be querying.
for zone in self.conservative:
if query.endswith("." + zone):
if query.endswith(f".{zone}"):
break
else:
_, zone = utils.split_fqdn(query)
Expand Down
13 changes: 7 additions & 6 deletions uwhoisd/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def whois(self, query):
bytes_whois = b""
self.sock.sendall("{0}\r\n".format(query).encode())
while True:
data = self.sock.recv(2048)
if data:
if data := self.sock.recv(2048):
bytes_whois += data
continue
break
Expand Down Expand Up @@ -97,10 +96,12 @@ def handle_stream(self, stream, address):
try:
whois_query = yield self.stream.read_until_regex(b"\n")
whois_query = whois_query.decode().strip().lower()
if not utils.is_well_formed_fqdn(whois_query):
whois_entry = "; Bad request: '{0}'\r\n".format(whois_query)
else:
whois_entry = self.whois(whois_query)
whois_entry = (
self.whois(whois_query)
if utils.is_well_formed_fqdn(whois_query)
else "; Bad request: '{0}'\r\n".format(whois_query)
)

yield self.stream.write(whois_entry.encode())
except tornado.iostream.StreamClosedError:
logger.warning("Connection closed by %s.", address)
Expand Down
6 changes: 3 additions & 3 deletions uwhoisd/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def scrape_whois_from_iana(root_zone_db_url, existing):

# Fallback to trying whois.nic.*
if whois_server == "":
whois_server = "whois.nic.%s" % zone
whois_server = f"whois.nic.{zone}"
logging.info("Trying fallback server: %s", whois_server)
try:
socket.gethostbyname(whois_server)
Expand Down Expand Up @@ -142,12 +142,12 @@ def main():
whois_servers[zone] = whois_server
print("[overrides]")
for zone in sorted(whois_servers):
print("%s=%s" % (zone, whois_servers[zone]))
print(f"{zone}={whois_servers[zone]}")

if args.ipv4:
print("[ipv4_assignments]")
for prefix, whois_server in fetch_ipv4_assignments(IPV4_ASSIGNMENTS):
print("%s=%s" % (prefix, whois_server))
print(f"{prefix}={whois_server}")

logging.info("Done")
return 0
Expand Down
4 changes: 1 addition & 3 deletions uwhoisd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def get_section_dict(self, section):
Pull a section out of the config as a dictionary safely.
"""
if self.has_section(section):
return dict(
(key, decode_value(value)) for key, value in self.items(section)
)
return {key: decode_value(value) for key, value in self.items(section)}
return {}


Expand Down

0 comments on commit 03f131b

Please sign in to comment.