This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a simple pattern analizer for future use
- Loading branch information
Showing
3 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import sys | ||
import re | ||
from typing import ( | ||
# Optional, | ||
# List, | ||
Dict, | ||
) | ||
|
||
# most likely we can now introduce trailing whitespace trim on all lines from whois, | ||
# and simplefy trailing whitespace rules | ||
# as \r is already gone now and that was the most disticnt line ending | ||
# occasionally we need to detect \n\s+ for groups that belong together | ||
# mostly with indented blocks of nameservers | ||
|
||
# import whois | ||
from whois.tld_regexpr import ZZ | ||
|
||
|
||
def buildRegCollection(zz: Dict): | ||
regCollection = {} | ||
# get all regexes | ||
for name in zz: | ||
# print(name) | ||
z = zz[name] | ||
for key in z: | ||
if key is None: | ||
continue | ||
|
||
if key.startswith("_"): | ||
continue | ||
|
||
if key in ["extend"]: | ||
continue | ||
|
||
if key not in regCollection: | ||
regCollection[key] = {} | ||
|
||
reg = z[key] | ||
if reg is None: | ||
continue | ||
|
||
regCollection[key][reg] = None | ||
if isinstance(reg, str): | ||
regCollection[key][reg] = re.compile(reg, flags=re.IGNORECASE) | ||
|
||
return regCollection | ||
|
||
|
||
if __name__ == "__main__": | ||
regCollection = buildRegCollection(ZZ) | ||
|
||
for name in sorted(regCollection.keys()): | ||
print(f"## {name}", file=sys.stderr) | ||
for key in sorted(regCollection[name].keys()): | ||
if key: | ||
print(f"{name}: {key}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters