Skip to content

Commit

Permalink
Merge pull request #65 from pogzyb/fix-mismatched-rdap-keys
Browse files Browse the repository at this point in the history
Fix mismatched rdap keys
  • Loading branch information
pogzyb authored Oct 12, 2023
2 parents 9dc7ad0 + 7b3260d commit edc88d9
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 127 deletions.
64 changes: 62 additions & 2 deletions asyncwhois/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def __str__(self):


class IPBaseKeys(str, Enum):

NET_RANGE = "net_range"
CIDR = "cidr"
NET_NAME = "net_name"
Expand Down Expand Up @@ -173,8 +172,69 @@ def __str__(self):
return self.value


class BaseParser:
def convert_whodap_keys(parser_output: dict) -> dict:
# keys in both, but with mismatched names
conversions = [
(TLDBaseKeys.EXPIRES, "expires_date", False),
(TLDBaseKeys.UPDATED, "updated_date", False),
(TLDBaseKeys.CREATED, "created_date", False),
(TLDBaseKeys.NAME_SERVERS, "nameservers", False),
(TLDBaseKeys.REGISTRAR_ABUSE_EMAIL, "abuse_email", False),
(TLDBaseKeys.REGISTRAR_ABUSE_PHONE, "abuse_phone", False),
(TLDBaseKeys.TECH_EMAIL, "technical_email", False),
(TLDBaseKeys.TECH_ADDRESS, "technical_address", False),
(TLDBaseKeys.TECH_ORGANIZATION, "technical_organization", False),
(TLDBaseKeys.TECH_NAME, "technical_name", False),
(TLDBaseKeys.TECH_PHONE, "technical_phone", False),
(TLDBaseKeys.TECH_FAX, "technical_fax", False),
(TLDBaseKeys.REGISTRAR, "registrar_name", False),
]
for asyncwhois_key, whodap_key, keep in conversions:
if keep:
parser_output[asyncwhois_key] = parser_output.get(whodap_key)
else:
parser_output[asyncwhois_key] = parser_output.pop(whodap_key)
# asyncwhois keys not in whodap
non_whodap_keys = [
TLDBaseKeys.ADMIN_ID,
TLDBaseKeys.ADMIN_CITY,
TLDBaseKeys.ADMIN_STATE,
TLDBaseKeys.ADMIN_COUNTRY,
TLDBaseKeys.ADMIN_ZIPCODE,
TLDBaseKeys.BILLING_ID,
TLDBaseKeys.BILLING_CITY,
TLDBaseKeys.BILLING_STATE,
TLDBaseKeys.BILLING_COUNTRY,
TLDBaseKeys.BILLING_ZIPCODE,
TLDBaseKeys.TECH_ID,
TLDBaseKeys.TECH_CITY,
TLDBaseKeys.TECH_STATE,
TLDBaseKeys.TECH_COUNTRY,
TLDBaseKeys.TECH_ZIPCODE,
TLDBaseKeys.REGISTRANT_CITY,
TLDBaseKeys.REGISTRANT_STATE,
TLDBaseKeys.REGISTRANT_COUNTRY,
TLDBaseKeys.REGISTRANT_ZIPCODE,
TLDBaseKeys.REGISTRAR,
TLDBaseKeys.REGISTRAR_IANA_ID,
TLDBaseKeys.REGISTRAR_URL,
TLDBaseKeys.DNSSEC,
]
for key in non_whodap_keys:
parser_output[key] = None
# whodap keys not in asyncwhois
non_asyncwhois_keys = [
"registrar_email",
"registrar_phone",
"registrar_address",
"registrar_fax",
]
for key in non_asyncwhois_keys:
parser_output.pop(key)
return parser_output


class BaseParser:
reg_expressions = {}

date_keys = ()
Expand Down
5 changes: 0 additions & 5 deletions asyncwhois/parse_rir.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class RIRParser(BaseParser):

date_keys = (
IPBaseKeys.ORG_REG_DATE,
IPBaseKeys.ORG_UPDATED,
Expand Down Expand Up @@ -86,7 +85,6 @@ def __init__(self):


class AFRINICParser(RIRParser):

_afrinic = {
IPBaseKeys.NET_RANGE: r"inetnum: *(.+)",
IPBaseKeys.NET_NAME: r"netname: *(.+)",
Expand Down Expand Up @@ -150,7 +148,6 @@ def parse(self, blob: str) -> Dict[IPBaseKeys, Any]:


class APNICParser(RIRParser):

_apnic = {
IPBaseKeys.NET_RANGE: r"inetnum: *(.+)",
IPBaseKeys.NET_NAME: r"netname: *(.+)",
Expand Down Expand Up @@ -221,7 +218,6 @@ def parse(self, blob: str) -> Dict[IPBaseKeys, Any]:


class LACNICParser(RIRParser):

_lacnic = {
IPBaseKeys.NET_RANGE: r"inetnum: *(.+)",
IPBaseKeys.CIDR: r"inetrev: *(.+)",
Expand Down Expand Up @@ -291,7 +287,6 @@ def parse(self, blob: str) -> Dict[IPBaseKeys, Any]:


class RIPEParser(RIRParser):

_ripe = {
IPBaseKeys.NET_RANGE: r"inetnum: *(.+)",
IPBaseKeys.NET_NAME: r"netname: *(.+)",
Expand Down
Loading

0 comments on commit edc88d9

Please sign in to comment.