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

Commit

Permalink
Merge pull request #266 from maarten-boot/development
Browse files Browse the repository at this point in the history
add configurable QuotaStrings and NoneStrings, add more NonStrings and QuotaStrings after detecting new ones; messages to stderr only with verbose=True
  • Loading branch information
maarten-boot authored Feb 2, 2023
2 parents a7dfd1a + e98b6c3 commit 855f0ed
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 38 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ Raise an issue https://github.com/DannyCork/python-whois/issues/new
* refresh testdata now that tld has dot instead of _ if more then one level
* add additional strings meaning domain does not exist

2023-02-02: maarten_boot
* whois.QuotaStringsAdd(str) to add additional strings for over quota detection. whois.QuotaStrings() lists the current configured strings
* whois.NoneStringsAdd(str) to add additional string for NoSuchDomainExists detection (whois.query() retuning None). whois.NoneStrings() lsts the current configured strings
* suppress messages to stderr if not verbose=True

## Support
* Python 3.x is supported.
* Python 2.x IS NOT supported.
9 changes: 6 additions & 3 deletions whois/_0_init_tld.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ def filterTldToSupportedPattern(
# we have max 2 levels so first check if the last 2 are in our list
tld = f"{d[-2]}.{d[-1]}"
if tld in ZZ:
print(f"we have {tld}", file=sys.stderr)
if verbose:
print(f"we have {tld}", file=sys.stderr)
return tld

# if not check if the last item we have
tld = f"{d[-1]}"
if tld in ZZ:
print(f"we have {tld}", file=sys.stderr)
if verbose:
print(f"we have {tld}", file=sys.stderr)
return tld

print(f"we DONT have {tld}", file=sys.stderr)
if verbose:
print(f"we DONT have {tld}", file=sys.stderr)

# if not fail
a = f"The TLD {tld} is currently not supported by this package."
Expand Down
89 changes: 55 additions & 34 deletions whois/_2_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,57 @@

Verbose = True

NONESTRINGS: List = [
"the domain has not been registered",
"no match found for",
"no matching record",
"not found",
"no data found",
"no entries found",
"status: free",
"no such domain",
"the queried object does not exist",
"domain you requested is not known",
"status: available",
"no whois server is known for this kind of object",
"nameserver not found",
"malformed request", # this means this domain is not in whois as it is on top of a registered domain
"no match",
"registration of this domain is restricted",
"restricted",
"this domain is currently available"
]

QUOTASTRINGS = [
"limit exceeded",
"quota exceeded",
"try again later",
"please try again",
"exceeded the maximum allowable number",
"can temporarily not be answered",
"please try again.",
"queried interval is too short",
"number of allowed queries exceeded",
]


def NoneStrings() -> List:
return sorted(NONESTRINGS)


def NoneStringsAdd(aString: str):
if aString and isinstance(aString, str) and len(aString) > 0:
NONESTRINGS.append(aString)


def QuotaStrings() -> List:
return sorted(QUOTASTRINGS)


def QuotaStringsAdd(aString: str):
if aString and isinstance(aString, str) and len(aString) > 0:
NONESTRINGS.append(aString)


def cleanupWhoisResponse(
whois_str: str,
Expand Down Expand Up @@ -85,54 +136,24 @@ def handleShortResponse(

# NOTE: from here s is lowercase only
# ---------------------------------
noneStrings = [
"the domain has not been registered",
"no match found for",
"no matching record",
"not found",
"no data found",
"no entries found",
"status: free",
"no such domain",
"the queried object does not exist",
"domain you requested is not known",
"status: available",
"no whois server is known for this kind of object",
"nameserver not found",
"malformed request", # this means this domain is not in whois as it is on top of a registered domain
"no match",
"registration of this domain is restricted",
]

noneStrings = NoneStrings()
for i in noneStrings:
if i in s:
return None

# ---------------------------------
# is there any error string in the result
if s.count("error"):
if verbose:
print("i see 'error' in the result, return: None", file=sys.stderr)
return None

# ---------------------------------
quotaStrings = [
"limit exceeded",
"quota exceeded",
"try again later",
"please try again",
"exceeded the maximum allowable number",
"can temporarily not be answered",
"please try again.",
"queried interval is too short",
]

quotaStrings = QuotaStrings()
for i in quotaStrings:
if i in s:
raise WhoisQuotaExceeded(whois_str)

# ---------------------------------
# ToDo: Name or service not known

# ---------------------------------
raise FailedParsingWhoisOutput(whois_str)


Expand Down
13 changes: 12 additions & 1 deletion whois/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
)

from ._1_query import do_query
from ._2_parse import do_parse
from ._2_parse import (
do_parse,
NoneStrings,
NoneStringsAdd,
QuotaStrings,
QuotaStringsAdd,
)

from ._3_adjust import Domain
from ._0_init_tld import (
ZZ,
Expand Down Expand Up @@ -57,6 +64,10 @@
"get",
"validTlds",
"mergeExternalDictWithRegex",
"NoneStrings",
"NoneStringsAdd",
"QuotaStrings",
"QuotaStringsAdd",
]


Expand Down

0 comments on commit 855f0ed

Please sign in to comment.