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

Commit 855f0ed

Browse files
authored
Merge pull request #266 from maarten-boot/development
add configurable QuotaStrings and NoneStrings, add more NonStrings and QuotaStrings after detecting new ones; messages to stderr only with verbose=True
2 parents a7dfd1a + e98b6c3 commit 855f0ed

File tree

4 files changed

+78
-38
lines changed

4 files changed

+78
-38
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ Raise an issue https://github.com/DannyCork/python-whois/issues/new
8888
* refresh testdata now that tld has dot instead of _ if more then one level
8989
* add additional strings meaning domain does not exist
9090

91+
2023-02-02: maarten_boot
92+
* whois.QuotaStringsAdd(str) to add additional strings for over quota detection. whois.QuotaStrings() lists the current configured strings
93+
* whois.NoneStringsAdd(str) to add additional string for NoSuchDomainExists detection (whois.query() retuning None). whois.NoneStrings() lsts the current configured strings
94+
* suppress messages to stderr if not verbose=True
95+
9196
## Support
9297
* Python 3.x is supported.
9398
* Python 2.x IS NOT supported.

whois/_0_init_tld.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ def filterTldToSupportedPattern(
2929
# we have max 2 levels so first check if the last 2 are in our list
3030
tld = f"{d[-2]}.{d[-1]}"
3131
if tld in ZZ:
32-
print(f"we have {tld}", file=sys.stderr)
32+
if verbose:
33+
print(f"we have {tld}", file=sys.stderr)
3334
return tld
3435

3536
# if not check if the last item we have
3637
tld = f"{d[-1]}"
3738
if tld in ZZ:
38-
print(f"we have {tld}", file=sys.stderr)
39+
if verbose:
40+
print(f"we have {tld}", file=sys.stderr)
3941
return tld
4042

41-
print(f"we DONT have {tld}", file=sys.stderr)
43+
if verbose:
44+
print(f"we DONT have {tld}", file=sys.stderr)
4245

4346
# if not fail
4447
a = f"The TLD {tld} is currently not supported by this package."

whois/_2_parse.py

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,57 @@
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+
"restricted",
31+
"this domain is currently available"
32+
]
33+
34+
QUOTASTRINGS = [
35+
"limit exceeded",
36+
"quota exceeded",
37+
"try again later",
38+
"please try again",
39+
"exceeded the maximum allowable number",
40+
"can temporarily not be answered",
41+
"please try again.",
42+
"queried interval is too short",
43+
"number of allowed queries exceeded",
44+
]
45+
46+
47+
def NoneStrings() -> List:
48+
return sorted(NONESTRINGS)
49+
50+
51+
def NoneStringsAdd(aString: str):
52+
if aString and isinstance(aString, str) and len(aString) > 0:
53+
NONESTRINGS.append(aString)
54+
55+
56+
def QuotaStrings() -> List:
57+
return sorted(QUOTASTRINGS)
58+
59+
60+
def QuotaStringsAdd(aString: str):
61+
if aString and isinstance(aString, str) and len(aString) > 0:
62+
NONESTRINGS.append(aString)
63+
1364

1465
def cleanupWhoisResponse(
1566
whois_str: str,
@@ -85,54 +136,24 @@ def handleShortResponse(
85136

86137
# NOTE: from here s is lowercase only
87138
# ---------------------------------
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-
139+
noneStrings = NoneStrings()
107140
for i in noneStrings:
108141
if i in s:
109142
return None
110143

111144
# ---------------------------------
112145
# is there any error string in the result
113146
if s.count("error"):
147+
if verbose:
148+
print("i see 'error' in the result, return: None", file=sys.stderr)
114149
return None
115150

116151
# ---------------------------------
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-
152+
quotaStrings = QuotaStrings()
128153
for i in quotaStrings:
129154
if i in s:
130155
raise WhoisQuotaExceeded(whois_str)
131156

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

138159

whois/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
)
88

99
from ._1_query import do_query
10-
from ._2_parse import do_parse
10+
from ._2_parse import (
11+
do_parse,
12+
NoneStrings,
13+
NoneStringsAdd,
14+
QuotaStrings,
15+
QuotaStringsAdd,
16+
)
17+
1118
from ._3_adjust import Domain
1219
from ._0_init_tld import (
1320
ZZ,
@@ -57,6 +64,10 @@
5764
"get",
5865
"validTlds",
5966
"mergeExternalDictWithRegex",
67+
"NoneStrings",
68+
"NoneStringsAdd",
69+
"QuotaStrings",
70+
"QuotaStringsAdd",
6071
]
6172

6273

0 commit comments

Comments
 (0)