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

Commit b0ac53a

Browse files
committed
add configurable list of quotastrings and nonestrings
1 parent 7767dba commit b0ac53a

File tree

1 file changed

+52
-34
lines changed

1 file changed

+52
-34
lines changed

whois/_2_parse.py

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,54 @@
1010

1111
Verbose = True
1212

13+
NONESTRINGS: List = [
14+
"the domain has not been registered",
15+
"no match found for",
16+
"no matching record",
17+
"not found",
18+
"no data found",
19+
"no entries found",
20+
"status: free",
21+
"no such domain",
22+
"the queried object does not exist",
23+
"domain you requested is not known",
24+
"status: available",
25+
"no whois server is known for this kind of object",
26+
"nameserver not found",
27+
"malformed request", # this means this domain is not in whois as it is on top of a registered domain
28+
"no match",
29+
"registration of this domain is restricted",
30+
]
31+
32+
QUOTASTRINGS = [
33+
"limit exceeded",
34+
"quota exceeded",
35+
"try again later",
36+
"please try again",
37+
"exceeded the maximum allowable number",
38+
"can temporarily not be answered",
39+
"please try again.",
40+
"queried interval is too short",
41+
]
42+
43+
44+
def NoneStrings() -> List:
45+
return sorted(NONESTRINGS)
46+
47+
48+
def NoneStringsAdd(aString: str):
49+
if aString and isinstance(aString, str) and len(aString) > 0:
50+
NONESTRINGS.append(aString)
51+
52+
53+
def QuotaStrings() -> List:
54+
return sorted(QUOTASTRINGS)
55+
56+
57+
def QuotaStringsAdd(aString: str):
58+
if aString and isinstance(aString, str) and len(aString) > 0:
59+
NONESTRINGS.append(aString)
60+
1361

1462
def cleanupWhoisResponse(
1563
whois_str: str,
@@ -85,54 +133,24 @@ def handleShortResponse(
85133

86134
# NOTE: from here s is lowercase only
87135
# ---------------------------------
88-
noneStrings = [
89-
"the domain has not been registered",
90-
"no match found for",
91-
"no matching record",
92-
"not found",
93-
"no data found",
94-
"no entries found",
95-
"status: free",
96-
"no such domain",
97-
"the queried object does not exist",
98-
"domain you requested is not known",
99-
"status: available",
100-
"no whois server is known for this kind of object",
101-
"nameserver not found",
102-
"malformed request", # this means this domain is not in whois as it is on top of a registered domain
103-
"no match",
104-
"registration of this domain is restricted",
105-
]
106-
136+
noneStrings = NoneStrings()
107137
for i in noneStrings:
108138
if i in s:
109139
return None
110140

111141
# ---------------------------------
112142
# is there any error string in the result
113143
if s.count("error"):
144+
if verbose:
145+
print("i see 'error' in the result, return: None", file=sys.stderr)
114146
return None
115147

116148
# ---------------------------------
117-
quotaStrings = [
118-
"limit exceeded",
119-
"quota exceeded",
120-
"try again later",
121-
"please try again",
122-
"exceeded the maximum allowable number",
123-
"can temporarily not be answered",
124-
"please try again.",
125-
"queried interval is too short",
126-
]
127-
149+
quotaStrings = QuotaStrings()
128150
for i in quotaStrings:
129151
if i in s:
130152
raise WhoisQuotaExceeded(whois_str)
131153

132-
# ---------------------------------
133-
# ToDo: Name or service not known
134-
135-
# ---------------------------------
136154
raise FailedParsingWhoisOutput(whois_str)
137155

138156

0 commit comments

Comments
 (0)