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

Commit f6c5188

Browse files
authored
Merge pull request #328 from mboot-github/master
sync with whoisdomain 1.20230811.1
2 parents 58a5083 + 2404a6a commit f6c5188

30 files changed

+2068
-1367
lines changed

.github/workflows/lint.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ jobs:
77
steps:
88
- name: Check out repository
99
uses: actions/checkout@v3
10-
- name: Set up Python 3.x
10+
- name: Set up Python 3.9
1111
uses: actions/setup-python@v4
1212
with:
13-
python-version: 3.x
13+
python-version: 3.9
1414
- name: Install dependencies
1515
run: |
1616
python -m pip install --upgrade pip
17-
pip install mypy
17+
pip install mypy tld
18+
python3 -m pip install types-redis
1819
- name: Run mypy
19-
run: mypy --strict whois
20+
run: mypy --strict *.py whois

.github/workflows/python-publish.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
# This workflow will upload a Python Package using Twine when a release is created
2-
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3-
4-
# This workflow uses actions that are not certified by GitHub.
5-
# They are provided by a third-party and are governed by
6-
# separate terms of service, privacy policy, and support
7-
# documentation.
8-
92
name: Upload Python Package
103

114
on:
@@ -17,23 +10,25 @@ permissions:
1710

1811
jobs:
1912
deploy:
20-
2113
runs-on: ubuntu-latest
2214

2315
steps:
2416
- uses: actions/checkout@v3
17+
2518
- name: Set up Python
26-
uses: actions/setup-python@v3
19+
uses: actions/setup-python@v4
2720
with:
28-
python-version: '3.x'
21+
python-version: '3.9'
22+
2923
- name: Install dependencies
3024
run: |
3125
python -m pip install --upgrade pip
3226
pip install build
27+
3328
- name: Build package
3429
run: python -m build
30+
3531
- name: Publish package
36-
# uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
3732
uses: pypa/gh-action-pypi-publish@release/v1
3833
with:
3934
user: __token__

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# whois
2-
A Python package for retrieving WHOIS information of domains.
3-
This package will not support querying ip CIDR ranges or AS information
2+
* A Python package for retrieving WHOIS information of domains.
3+
* This package will not support querying ip CIDR ranges or AS information
4+
* It requires the whois cli component of your os to be installed: e.g. `/usr/bin/whois` on Linux
45

56
## NOTE
67
* 2023-04-25: mboot
@@ -9,14 +10,19 @@ This package will not support querying ip CIDR ranges or AS information
910
* and new pypi releases will come from: https://pypi.org/project/whoisdomain/
1011
* efforts will be made to keep the v1.x.y version of whoisdomain compatible with this repo
1112
* changes will be verified and back copied also here for the time being
13+
* starting 2024-02, this repo will be abandon-ware
14+
15+
## Support
16+
* Python 3.x is supported for x >= 9
17+
* Python 2.x IS NOT supported.
1218

1319

1420
## Features
1521
* Python wrapper for the "whois" cli command of your operating system.
1622
* Simple interface to access parsed WHOIS data for a given domain.
1723
* Able to extract data for all the popular TLDs (com, org, net, biz, info, pl, jp, uk, nz, ...).
1824
* Query a WHOIS server directly instead of going through an intermediate web service like many others do.
19-
* Works with Python >= 3.6
25+
* Works with Python >= 3.9
2026
* All dates as datetime objects.
2127
* Possibility to cache results.
2228
* Verbose output on stderr during debugging to see how the internal functions are doing their work
@@ -117,6 +123,8 @@ Raise an issue https://github.com/DannyCork/python-whois/issues/new
117123
* sync with https://github.com/mboot-github/WhoisDomain; 1.20230720.1; (gov.tr), (com.ru, msk.ru, spb.ru), (option to preserve partial output after timeout)
118124
* sync with https://github.com/mboot-github/WhoisDomain; 1.20230720.2; add t_test hint support; fix some server hints
119125

120-
## Support
121-
* Python 3.x is supported for x >= 6
122-
* Python 2.x IS NOT supported.
126+
2023-08-21: mboot-github (maarten_boot)
127+
* abandon any python below 3.9 (mypy compatibilities)
128+
* major refactor into more object based approcj and paramaterContext
129+
* allow custom caching backends (e.g. redis, dbm, ...)
130+

exampleExtend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"""
1414

1515

16-
def t1(domain: str, text: str):
16+
def t1(domain: str, text: str) -> None:
1717
print(f"{text}: {domain}")
1818
try:
1919
d = whois.query(domain)
@@ -25,7 +25,7 @@ def t1(domain: str, text: str):
2525
print(domain, e)
2626

2727

28-
def xMain():
28+
def xMain() -> None:
2929
aDictToTestOverride = {
3030
"si": { # changing a existing one
3131
"domain_name": r"domain:\s+(.+)",

setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@
2727
"Intended Audience :: Developers",
2828
"Environment :: Console",
2929
"Programming Language :: Python",
30-
"Programming Language :: Python :: 3.6",
31-
"Programming Language :: Python :: 3.7",
32-
"Programming Language :: Python :: 3.8",
3330
"Programming Language :: Python :: 3.9",
3431
"Programming Language :: Python :: 3.10",
3532
"Programming Language :: Python :: 3.11",
3633
"Topic :: Internet",
3734
"Topic :: Software Development :: Libraries :: Python Modules",
3835
],
39-
python_requires=">=3.6",
36+
python_requires=">=3.9",
4037
)
4138

4239
'''

whois/_0_init_tld.py

100644100755
Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,17 @@
1212
UnknownTld,
1313
)
1414

15+
# from .parameterContext import ParameterContext # not needed yet here
16+
1517
Verbose: bool = False
1618
TLD_RE: Dict[str, Dict[str, Any]] = {}
1719
REG_COLLECTION_BY_KEY: Dict[str, Any] = {}
1820

1921

20-
def validTlds() -> List[str]:
21-
return sorted(TLD_RE.keys())
22-
23-
24-
def filterTldToSupportedPattern(
25-
domain: str,
26-
d: List[str],
27-
verbose: bool = False,
28-
) -> str:
29-
# we have max 2 levels so first check if the last 2 are in our list
30-
tld = f"{d[-2]}.{d[-1]}"
31-
if tld in ZZ:
32-
if verbose:
33-
print(f"we have {tld}", file=sys.stderr)
34-
return tld
35-
36-
# if not check if the last item we have
37-
tld = f"{d[-1]}"
38-
if tld in ZZ:
39-
if verbose:
40-
print(f"we have {tld}", file=sys.stderr)
41-
return tld
42-
43-
if verbose:
44-
print(f"we DONT have {tld}", file=sys.stderr)
45-
46-
# if not fail
47-
a = f"The TLD {tld} is currently not supported by this package."
48-
b = "Use validTlds() to see what toplevel domains are supported."
49-
msg = f"{a} {b}"
50-
raise UnknownTld(msg)
51-
52-
53-
def get_tld_re(tld: str, override: bool = False) -> Dict[str, Any]:
22+
def _get_tld_re(
23+
tld: str,
24+
override: bool = False,
25+
) -> Dict[str, Any]:
5426
if override is False:
5527
if tld in TLD_RE:
5628
return TLD_RE[tld]
@@ -59,7 +31,7 @@ def get_tld_re(tld: str, override: bool = False) -> Dict[str, Any]:
5931

6032
extend = v.get("extend")
6133
if extend:
62-
e = get_tld_re(extend) # call recursive
34+
e = _get_tld_re(extend) # call recursive
6335
tmp = e.copy()
6436
tmp.update(v) # and merge results in tmp with caller data in v
6537
# The update() method updates the dictionary with the elements
@@ -87,22 +59,14 @@ def get_tld_re(tld: str, override: bool = False) -> Dict[str, Any]:
8759
return tld_re
8860

8961

90-
def mergeExternalDictWithRegex(aDict: Dict[str, Any] = {}) -> None:
91-
# merge in ZZ, this extends ZZ with new tld's and overrides existing tld's
92-
for tld in aDict.keys():
93-
ZZ[tld] = aDict[tld]
94-
95-
# reprocess te regexes we newly defined or overrode
96-
override = True
97-
for tld in aDict.keys():
98-
initOne(tld, override)
99-
100-
101-
def initOne(tld: str, override: bool = False) -> None:
62+
def _initOne(
63+
tld: str,
64+
override: bool = False,
65+
) -> None:
10266
if tld[0] == "_": # skip meta domain patterns , these are not domains just handles we reuse
10367
return
10468

105-
what = get_tld_re(tld, override)
69+
what = _get_tld_re(tld, override)
10670

10771
# test if the string is identical after idna conversion
10872
d = tld.split(".")
@@ -117,7 +81,9 @@ def initOne(tld: str, override: bool = False) -> None:
11781
print(f"{tld} -> {tld2}", file=sys.stderr)
11882

11983

120-
def buildRegCollection(zz: Dict[str, Any]) -> Dict[str, Any]:
84+
def _buildRegCollection(
85+
zz: Dict[str, Any],
86+
) -> Dict[str, Any]:
12187
regCollection: Dict[str, Any] = {}
12288

12389
# get all regexes
@@ -152,15 +118,65 @@ def buildRegCollection(zz: Dict[str, Any]) -> Dict[str, Any]:
152118
return regCollection
153119

154120

155-
def initOnImport() -> None:
121+
def _initOnImport() -> None:
156122
global REG_COLLECTION_BY_KEY
157123
# here we run the import processing
158124
# we load all tld's on import so we dont lose time later
159125
# we keep ZZ so we can later reuse it if we want to aoverrid or update tld's
160-
REG_COLLECTION_BY_KEY = buildRegCollection(ZZ)
126+
REG_COLLECTION_BY_KEY = _buildRegCollection(ZZ)
161127
override = False
162128
for tld in ZZ.keys():
163-
initOne(tld, override)
129+
_initOne(tld, override)
130+
131+
132+
# ========================================
133+
# external use
134+
135+
136+
def filterTldToSupportedPattern(
137+
domain: str,
138+
d: List[str],
139+
verbose: bool = False,
140+
) -> str:
141+
# we have max 2 levels so first check if the last 2 are in our list
142+
tld = f"{d[-2]}.{d[-1]}"
143+
if tld in ZZ:
144+
if verbose:
145+
print(f"we have {tld}", file=sys.stderr)
146+
return tld
147+
148+
# if not check if the last item we have
149+
tld = f"{d[-1]}"
150+
if tld in ZZ:
151+
if verbose:
152+
print(f"we have {tld}", file=sys.stderr)
153+
return tld
154+
155+
if verbose:
156+
print(f"we DONT have {tld}", file=sys.stderr)
157+
158+
# if not fail
159+
a = f"The TLD {tld} is currently not supported by this package."
160+
b = "Use validTlds() to see what toplevel domains are supported."
161+
msg = f"{a} {b}"
162+
raise UnknownTld(msg)
163+
164+
165+
def mergeExternalDictWithRegex(
166+
aDict: Dict[str, Any] = {},
167+
) -> None:
168+
# merge in ZZ, this extends ZZ with new tld's and overrides existing tld's
169+
for tld in aDict.keys():
170+
ZZ[tld] = aDict[tld]
171+
172+
# reprocess te regexes we newly defined or overrode
173+
override = True
174+
for tld in aDict.keys():
175+
_initOne(tld, override)
176+
177+
178+
def validTlds() -> List[str]:
179+
return sorted(TLD_RE.keys())
164180

165181

166-
initOnImport()
182+
_initOnImport()

0 commit comments

Comments
 (0)