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

Commit 58a5083

Browse files
authored
Merge pull request #326 from maarten-boot/master
sync with 1.20230720.2
2 parents 481595a + 4699e4a commit 58a5083

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ Raise an issue https://github.com/DannyCork/python-whois/issues/new
114114
* suppress messages to stderr if not verbose=True
115115

116116
2023-07-20: maarten_boot
117-
* sync with https://github.com/mboot-github/WhoisDomain (gov.tr), (com.ru, msk.ru, spb.ru), (option to preserve partial output after timeout)
117+
* 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)
118+
* sync with https://github.com/mboot-github/WhoisDomain; 1.20230720.2; add t_test hint support; fix some server hints
118119

119120
## Support
120121
* Python 3.x is supported for x >= 6

whois/_0_init_tld.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ def buildRegCollection(zz: Dict[str, Any]) -> Dict[str, Any]:
128128
if key is None:
129129
continue
130130

131-
if key.startswith("_"):
131+
if key.startswith("_"): # skip meta keys, they are not regexes
132132
continue
133133

134-
if key in ["extend"]:
134+
if key in ["extend"]: # this actually should have been a meta key: "_extend"
135135
continue
136136

137137
if key not in regCollection:

whois/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"QuotaStrings",
7878
"QuotaStringsAdd",
7979
"cleanupWhoisResponse",
80+
"getTestHint",
8081
]
8182

8283
WHOISDOMAIN: str = ""
@@ -178,6 +179,7 @@ def _doServerHintsForThisTld(
178179
server: Optional[str],
179180
verbose: bool = False,
180181
) -> Optional[str]:
182+
# note _server hints currently are not passes down when using "extend", that may have been my error during the initial implementation
181183
# allow server hints using "_server" from the tld_regexpr.py file
182184
thisTldServer = thisTld.get("_server")
183185
if server is None and thisTldServer:
@@ -495,3 +497,14 @@ def query(
495497

496498
def getVersion() -> str:
497499
return VERSION
500+
501+
502+
def getTestHint(tld: str) -> Optional[str]:
503+
if tld not in ZZ:
504+
return None
505+
506+
k: str = "_test"
507+
if k not in ZZ[tld]:
508+
return None
509+
510+
return str(ZZ[tld][k])

whois/main.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
Failures: Dict[str, Any] = {}
3030
IgnoreReturncode: bool = False
31+
TestAllTld: bool = False
3132

3233

3334
class ResponseCleaner:
@@ -209,6 +210,7 @@ def testItem(
209210
global PrintGetRawWhoisResult
210211
global SIMPLISTIC
211212
global WithRedacted
213+
global TestAllTld
212214

213215
timeout = 30 # seconds
214216

@@ -350,13 +352,26 @@ def makeMetaAllCurrentTld(
350352
allHaving: Optional[str] = None,
351353
allRegex: Optional[str] = None,
352354
) -> List[str]:
355+
global TestAllTld
356+
357+
def appendHint(
358+
allRegex: Optional[str],
359+
tld: str,
360+
) -> None:
361+
if TestAllTld is True:
362+
hint = whois.getTestHint(tld)
363+
hint = hint if hint else f"meta.{tld}"
364+
rr.append(f"{hint}")
365+
else:
366+
rr.append(f"meta.{tld}")
367+
353368
rr: List[str] = []
354369
for tld in getAllCurrentTld():
355370
if allRegex:
356371
if re.search(allRegex, tld):
357-
rr.append(f"meta.{tld}")
372+
appendHint(allRegex, tld)
358373
else:
359-
rr.append(f"meta.{tld}")
374+
appendHint(allRegex, tld)
360375

361376
return rr
362377

@@ -478,6 +493,7 @@ def main() -> None:
478493
global Ruleset
479494
global SIMPLISTIC
480495
global WithRedacted
496+
global TestAllTld
481497

482498
name: str = os.path.basename(sys.argv[0])
483499
if name == "test2.py":
@@ -511,7 +527,7 @@ def main() -> None:
511527
usage()
512528
sys.exit(2)
513529

514-
testAllTld: bool = False
530+
# TestAllTld: bool = False
515531

516532
allHaving: Optional[str] = None # from all supported tld only process the ones having this :: TODO ::
517533
allRegex: Optional[str] = None # from all supported tld process only the ones matching this regex
@@ -545,14 +561,14 @@ def main() -> None:
545561
WithRedacted = True
546562

547563
if opt in ("-a", "--all"):
548-
testAllTld = True
564+
TestAllTld = True
549565

550566
if opt in ("-H", "--having"):
551-
testAllTld = True
567+
TestAllTld = True
552568
allHaving = str(arg)
553569

554570
if opt in ("-r", "--reg"):
555-
testAllTld = True
571+
TestAllTld = True
556572
allRegex = str(arg)
557573

558574
if opt in ("-v", "--verbose"):
@@ -595,7 +611,7 @@ def main() -> None:
595611

596612
if filename not in files:
597613
files.append(filename)
598-
testAllTld = False
614+
TestAllTld = False
599615

600616
if opt in ("-d", "--domain"):
601617
domain = arg
@@ -610,7 +626,7 @@ def main() -> None:
610626
ShowRuleset(domain)
611627
sys.exit(0)
612628

613-
if testAllTld:
629+
if TestAllTld:
614630
allMetaTld = makeMetaAllCurrentTld(allHaving, allRegex)
615631
testDomains(allMetaTld)
616632
showFailures()

whois/tld_regexpr.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,22 +298,21 @@
298298
"creation_date": r"Created on\.+:\s?(.+).",
299299
"expiration_date": r"Expires on\.+:\s?(.+).", # note the trailing . on both dates fields
300300
"updated_date": "",
301-
# "name_servers": r"\*\* Domain Servers:\n(?:(\S+)\n)(?:(\S+)\n)?(?:(\S+)\n)?(?:(\S+)\n)?(?:(\S+)\n)?(?:(\S+)\n)\n?",
302301
"name_servers": r"\*\* Domain Servers:\n(?:(\S+).*\n)?(?:(\S+).*\n)?(?:(\S+).*\n)?(?:(\S+).*\n)?", # allow for ip addresses after the name server
303302
"status": None,
304303
"_server": "whois.trabis.gov.tr",
305-
# "_test": "googl.com.tr"
304+
"_test": "google.com.tr",
306305
}
307306

308307
ZZ["gov.tr"] = {
309308
"extend": "com.tr",
310-
# "name_servers": r"\*\* Domain Servers:\n(?:(\S+).*\n)?(?:(\S+).*\n)?(?:(\S+).*\n)?(?:(\S+).*\n)?", # this has ip addresses after the nameserver
311-
# "_test": "www.turkiye.gov.tr",
309+
"_server": "whois.trabis.gov.tr",
310+
"_test": "www.turkiye.gov.tr",
312311
}
313312

314-
ZZ["edu.tr"] = {"extend": "com.tr"}
315-
ZZ["org.tr"] = {"extend": "com.tr"}
316-
ZZ["net.tr"] = {"extend": "com.tr"}
313+
ZZ["edu.tr"] = {"extend": "com.tr", "_server": "whois.trabis.gov.tr", "_test": "anadolu.edu.tr"}
314+
ZZ["org.tr"] = {"extend": "com.tr", "_server": "whois.trabis.gov.tr", "_test": "dergipark.org.tr"}
315+
ZZ["net.tr"] = {"extend": "com.tr", "_server": "whois.trabis.gov.tr", "_test": "trt.net.tr"}
317316

318317

319318
ZZ["co.il"] = {

whois/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "1.20230718.3"
1+
VERSION = "1.20230720.2"

0 commit comments

Comments
 (0)