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

Commit 83112c5

Browse files
authored
Merge pull request #333 from maarten-boot/master
update to latest whoisdomain
2 parents 659ed08 + 417add6 commit 83112c5

28 files changed

+537
-342
lines changed

makefile renamed to Makefile

File renamed without changes.

README.md

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,83 +48,94 @@ Install the cli `whois` of your operating system if it is not present already
4848

4949
Install `whois` package from your distribution (e.g apt install whois)
5050

51-
```
52-
$pip install whois
5351

54-
>>> import whois
55-
>>> domain = whois.query('google.com')
52+
$pip install whois
5653

57-
>>> print(domain.__dict__)
58-
{
59-
'expiration_date': datetime.datetime(2020, 9, 14, 0, 0),
60-
'last_updated': datetime.datetime(2011, 7, 20, 0, 0),
61-
'registrar': 'MARKMONITOR INC.',
62-
'name': 'google.com',
63-
'creation_date': datetime.datetime(1997, 9, 15, 0, 0)
64-
}
54+
>>> import whois
55+
>>> domain = whois.query('google.com')
6556

66-
>>> print(domain.name)
67-
google.com
57+
>>> print(domain.__dict__)
58+
{
59+
'expiration_date': datetime.datetime(2020, 9, 14, 0, 0),
60+
'last_updated': datetime.datetime(2011, 7, 20, 0, 0),
61+
'registrar': 'MARKMONITOR INC.',
62+
'name': 'google.com',
63+
'creation_date': datetime.datetime(1997, 9, 15, 0, 0)
64+
}
6865

69-
>>> print(domain.expiration_date)
70-
2020-09-14 00:00:00
71-
```
66+
>>> print(domain.name)
67+
google.com
68+
69+
>>> print(domain.expiration_date)
70+
2020-09-14 00:00:00
7271

7372
## ccTLD & TLD support
7473
see the file: ./whois/tld_regexpr.py
7574
or call whois.validTlds()
7675

7776
## Issues
78-
Raise an issue https://github.com/DannyCork/python-whois/issues/new
77+
* Raise an issue https://github.com/DannyCork/python-whois/issues/new
7978

80-
## Changes:
81-
2022-06-09: maarten_boot:
79+
## Changes: 2022-06-09: maarten_boot:
8280
* the returned list of name_servers is now a sorted unique list and not a set
8381
* the help function whois.validTlds() now outputs the true tld with dots
8482

85-
2022-09-27: maarten_boot
83+
## 2022-09-27: maarten_boot
8684
* add test2.py to replace test.py
8785
* ./test2.py -h will show the possible usage
8886
* all tests from the original program are now files in the ./tests directory
8987
* test can be done on all supported tld's with -a or --all and limitest by regex with -r <pattern> or --reg=<pattern>
9088

91-
2022-11-04: maarten_boot
89+
## 2022-11-04: maarten_boot
9290
* add support for Iana example.com, example.net
9391

94-
2022-11-07: maarten_boot
92+
## 2022-11-07: maarten_boot
9593
* add testing against static known data in dir: ./testdata/<domain>/output
9694
* test.sh will test all domains in testdata without actually calling whois, the input data is instead read from testdata/<domain>/input
9795

98-
2022-11-11: maarten_boot
96+
## 2022-11-11: maarten_boot
97+
9998
* add support for returning the raw data from the whois command: flag include_raw_whois_text
10099
* add support for handling unsupported domains via whois raw text only: flag return_raw_text_for_unsupported_tld
101100

102-
2023-01-18: sorrowless
101+
## 2023-01-18: sorrowless
102+
103103
* add an opportunity to specify maximum cache age
104104

105-
2023-01-25: maarten_boot
105+
## 2023-01-25: maarten_boot
106+
106107
* convert the tld file to a Dict, we now no longer need a mappper for python keywords or second level domains.
107108
* utf8 level domains also need no mapper anymore an can be added as is with a translation to xn--<something>
108109
* added xn-- tlds for all known utf-8 domains we currently have
109110
* we can now add new domains on the fly or change them: whois.mergeExternalDictWithRegex(aDictToOverride) see example exampleExtend.py
110111

111-
2023-01-27: maarten_boot
112+
## 2023-01-27: maarten_boot
113+
112114
* add autodetect via iana tld file (this has only tld's)
113115
* add a central collection of all compiled regexes and reuse them: REG_COLLECTION_BY_KEY in _0_init_tld.py
114116
* refresh testdata now that tld has dot instead of _ if more then one level
115117
* add additional strings meaning domain does not exist
116118

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

122-
2023-07-20: maarten_boot
123-
* 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)
124-
* sync with https://github.com/mboot-github/WhoisDomain; 1.20230720.2; add t_test hint support; fix some server hints
125+
## 2023-07-20: maarten_boot
126+
127+
* 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)
128+
* sync with https://github.com/mboot-github/WhoisDomain; 1.20230720.2; add t_test hint support; fix some server hints
129+
130+
## 2023-08-21: mboot-github (maarten_boot)
131+
132+
* abandon any python below 3.9 (mypy compatibilities)
133+
* major refactor into more object based approch and parameterContext
134+
* allow custom caching backends (e.g. redis, dbm, ...)
125135

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, ...)
136+
## 2023-09-22 see new paramaters in whois/context/parameterContext.oy
130137

138+
* Sync with latest whoisdomain
139+
* Allow cleaning up the http(s) info in the status response.
140+
* Allow correlation with tld (pip install tld) public_suffix.
141+
* Allow display of what whois-servers were used until we reach the final item.

whois/__init__.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
# pylint: disable=duplicate-code
2+
"""
3+
Module providing all public accessible functions and data for the whoisdomain package
4+
5+
## optional modules supported:
6+
7+
- if the tld library is installed you can use the `withPublicSuffix:bool` option
8+
9+
All public data is vizible via the __all__ List
10+
"""
11+
112
import sys
213
import os
14+
import logging
315

416
from functools import wraps
517

@@ -56,12 +68,15 @@
5668
initLastWhois,
5769
)
5870

71+
log = logging.getLogger(__name__)
72+
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
73+
5974
HAS_REDIS = False
6075
try:
6176
import redis
6277

6378
HAS_REDIS = True
64-
except Exception as e:
79+
except ImportError as e:
6580
_ = e
6681

6782
if HAS_REDIS:
@@ -82,7 +97,7 @@
8297
import tld as libTld
8398

8499
TLD_LIB_PRESENT = True
85-
except Exception as e:
100+
except ImportError as e:
86101
_ = e # ignore any error
87102

88103
__all__ = [
@@ -196,6 +211,8 @@ def query(
196211
tryInstallMissingWhoisOnWindows: bool = False,
197212
shortResponseLen: int = 5,
198213
withPublicSuffix: bool = False,
214+
extractServers: bool = False,
215+
stripHttpStatus: bool = False,
199216
# if you use pc as argument all above params (except domain are ignored)
200217
) -> Optional[Domain]:
201218
# see documentation about paramaters in parameterContext.py
@@ -223,10 +240,12 @@ def query(
223240
withPublicSuffix=withPublicSuffix,
224241
shortResponseLen=shortResponseLen,
225242
tryInstallMissingWhoisOnWindows=tryInstallMissingWhoisOnWindows,
243+
extractServers=extractServers,
244+
stripHttpStatus=stripHttpStatus,
226245
)
227246

228-
if verbose:
229-
print(pc, file=sys.stderr)
247+
msg = f"{pc}"
248+
log.debug(msg)
230249

231250
return q2(domain=domain, pc=pc)
232251

whois/cache/dbmCache.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import sys
1+
# import sys
22
import dbm
3+
import os
4+
import logging
35

46
from typing import (
57
Optional,
68
)
79

10+
log = logging.getLogger(__name__)
11+
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
12+
813

914
class DBMCache:
1015
def __init__(
@@ -14,22 +19,20 @@ def __init__(
1419
) -> None:
1520
self.verbose = verbose
1621
self.dbmFile = dbmFile
17-
if self.verbose:
18-
print(f"{type(self).__name__} verbose: {self.verbose}", file=sys.stderr)
1922

2023
def get(
2124
self,
2225
keyString: str,
2326
) -> Optional[str]:
24-
if self.verbose:
25-
print(f"{type(self).__name__} get: {keyString}", file=sys.stderr)
27+
msg = f"{type(self).__name__} get: {keyString}"
28+
log.debug(msg)
2629

2730
with dbm.open(self.dbmFile, "c") as db:
2831
data = db.get(keyString, None)
2932
if data:
3033
sdata: str = data.decode("utf-8")
31-
if self.verbose:
32-
print(sdata, file=sys.stderr)
34+
msg = f"{sdata}"
35+
log.debug(msg)
3336
return sdata
3437
return None
3538

@@ -38,8 +41,8 @@ def put(
3841
keyString: str,
3942
data: str,
4043
) -> str:
41-
if self.verbose:
42-
print(f"{type(self).__name__} put: {keyString}", file=sys.stderr)
44+
msg = f"{type(self).__name__} put: {keyString}"
45+
log.debug(msg)
4346

4447
with dbm.open(self.dbmFile, "c") as db:
4548
db[keyString] = bytes(data, "utf-8")

whois/cache/dummyCache.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
import sys
1+
# import sys
2+
import os
3+
import logging
24

35
from typing import (
46
Optional,
57
)
68

9+
log = logging.getLogger(__name__)
10+
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
11+
712

813
class DummyCache:
914
def __init__(
1015
self,
1116
verbose: bool = False,
1217
) -> None:
1318
self.verbose = verbose
14-
if self.verbose:
15-
print(f"{type(self).__name__} verbose: {self.verbose}", file=sys.stderr)
1619

1720
def get(
1821
self,
1922
keyString: str,
2023
) -> Optional[str]:
21-
if self.verbose:
22-
print(f"{type(self).__name__} get: {keyString}", file=sys.stderr)
2324
return None
2425

2526
def put(
2627
self,
2728
keyString: str,
2829
data: str,
2930
) -> str:
30-
if self.verbose:
31-
print(f"{type(self).__name__} put: {keyString}", file=sys.stderr)
3231
return data

whois/cache/redisCache.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
#! /usr/bin/env python3
2+
# pylint: disable=duplicate-code
3+
# pylint disable=broad-exception-caught
4+
5+
import os
6+
import logging
27

3-
import sys
48
from typing import (
59
Optional,
610
)
711

12+
log = logging.getLogger(__name__)
13+
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
14+
815
HAS_REDIS = False
916
try:
1017
import redis
1118

1219
HAS_REDIS = True
13-
except Exception as e:
20+
except ImportError as e:
1421
_ = e
1522

1623
if HAS_REDIS:
@@ -28,21 +35,14 @@ def __init__(self, verbose: bool = False, host: str = "localhost", port: int = 6
2835
connection_pool=self.pool,
2936
)
3037

31-
if self.verbose:
32-
print(f"{type(self).__name__} verbose: {self.verbose}", file=sys.stderr)
33-
3438
def get(
3539
self,
3640
keyString: str,
3741
) -> Optional[str]:
38-
if self.verbose:
39-
print(f"{type(self).__name__} get: {keyString}", file=sys.stderr)
4042

4143
data = self.redis.get(keyString)
4244
if data:
4345
sdata: str = data.decode("utf-8")
44-
if self.verbose:
45-
print(sdata, file=sys.stderr)
4646
return sdata
4747
return None
4848

@@ -51,8 +51,6 @@ def put(
5151
keyString: str,
5252
data: str,
5353
) -> str:
54-
if self.verbose:
55-
print(f"{type(self).__name__} put: {keyString}", file=sys.stderr)
5654

5755
self.redis.set(
5856
keyString,

0 commit comments

Comments
 (0)