Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit a18c7d0

Browse files
committed
add support for iana domains
1 parent a700549 commit a18c7d0

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

whois/_2_parse.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,18 @@ def doDnsSec(whois_str: str) -> bool:
150150
return False
151151

152152

153-
def doSourceIana(tld: str, r: Dict, whois_str: str, verbose: bool = False) -> str:
154-
# here we can handle the example.com and example.net permanent IANA domains
155-
156-
if verbose:
157-
msg = "i have seen source: IANA"
158-
print(msg, file=sys.stderr)
159-
160-
whois_splitted = whois_str.split("source: IANA")
161-
if len(whois_splitted) == 2 and whois_splitted[1].strip() != "":
162-
# if we see source: IANA and the part after is not only whitespace
153+
def doIfServerNameLookForDomainName(whois_str: str, verbose: bool = False) -> str:
154+
# not often available anymore
155+
if re.findall(r"Server Name:\s?(.+)", whois_str, re.IGNORECASE):
163156
if verbose:
164-
msg = f"after IANA: {whois_splitted[1]}"
157+
msg = "i have seen Server Name:, looking for Domain Name:"
165158
print(msg, file=sys.stderr)
159+
whois_str = whois_str[whois_str.find("Domain Name:") :]
160+
return whois_str
166161

167-
return whois_splitted[1], None
168-
169-
# try to parse this as a IANA domain as after is only whitespace
170-
# this will require us to fill in sufficient default values that the code expects to be there
171-
r = doExtractPattensFromWhoisString(tld, r, whois_str, verbose)
172162

163+
def doExtractPattensIanaFromWhoisString(tld: str, r: Dict, whois_str: str, verbose: bool = False):
164+
# now handle the actual format if this whois response
173165
iana = {
174166
"domain_name": r"domain:\s?([^\n]+)",
175167
"registar": r"organisation:\s?([^\n]+)",
@@ -179,23 +171,34 @@ def doSourceIana(tld: str, r: Dict, whois_str: str, verbose: bool = False) -> st
179171
zz = re.findall(v, whois_str)
180172
if zz:
181173
if verbose:
182-
print(zz, file=sys.stderr)
174+
print(tld, zz, file=sys.stderr)
183175
r[k] = zz
176+
return r
184177

185-
if verbose:
186-
print(r, file=sys.stderr)
187178

188-
return whois_str, r
179+
def doSourceIana(tld: str, r: Dict, whois_str: str, verbose: bool = False) -> str:
180+
# here we can handle the example.com and example.net permanent IANA domains
189181

182+
if verbose:
183+
msg = "i have seen source: IANA"
184+
print(msg, file=sys.stderr)
190185

191-
def doIfServerNameLookForDomainName(whois_str: str, verbose: bool = False) -> str:
192-
# not often available anymore
193-
if re.findall(r"Server Name:\s?(.+)", whois_str, re.IGNORECASE):
186+
whois_splitted = whois_str.split("source: IANA")
187+
if len(whois_splitted) == 2 and whois_splitted[1].strip() != "":
188+
# if we see source: IANA and the part after is not only whitespace
194189
if verbose:
195-
msg = "i have seen Server Name:, looking for Domain Name:"
190+
msg = f"after IANA: {whois_splitted[1]}"
196191
print(msg, file=sys.stderr)
197-
whois_str = whois_str[whois_str.find("Domain Name:") :]
198-
return whois_str
192+
193+
return whois_splitted[1], None
194+
195+
# try to parse this as a IANA domain as after is only whitespace
196+
r = doExtractPattensFromWhoisString(tld, r, whois_str, verbose) # set default values
197+
198+
# now handle the actual format if this whois response
199+
r = doExtractPattensIanaFromWhoisString(tld, r, whois_str, verbose)
200+
201+
return whois_str, r
199202

200203

201204
def doExtractPattensFromWhoisString(tld: str, r: Dict, whois_str: str, verbose: bool = False):

0 commit comments

Comments
 (0)