Skip to content

Commit

Permalink
refactor some parse methods with inheritence
Browse files Browse the repository at this point in the history
  • Loading branch information
Anvil committed May 25, 2024
1 parent 1473fc1 commit 45b5720
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions asyncwhois/tldparsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from datetime import datetime
import re
from typing import Any
from typing import Any, Union

from .parse import BaseParser, TLDBaseKeys

Expand Down Expand Up @@ -798,7 +798,7 @@ def _fix_timezone(date_string: str) -> str:
return date_string

@staticmethod
def _parse_date(date_string: str) -> datetime | str:
def _parse_date(date_string: str) -> Union[datetime, str]:
date = TLDParser._parse_date(date_string)
if isinstance(date, datetime):
return date
Expand Down Expand Up @@ -848,7 +848,7 @@ class RegexBY(TLDParser):
}


class RegexCR(TLDParser):
class RegexCR(RegexCZ):
tld_specific_expressions: ExpressionDict = {
TLDBaseKeys.DOMAIN_NAME: r"domain: *(.+)",
TLDBaseKeys.REGISTRANT_NAME: r"name: *(.+)",
Expand All @@ -860,10 +860,6 @@ class RegexCR(TLDParser):
TLDBaseKeys.REGISTRANT_ORGANIZATION: r"org: *(.+)",
}

def parse(self, blob: str) -> dict[str, Any]:
# CR server has the same format as CZ
return RegexCZ().parse(blob)


class RegexVE(TLDParser): # double check
tld_specific_expressions: ExpressionDict = {
Expand Down Expand Up @@ -1095,13 +1091,9 @@ class RegexLV(TLDParser):
}


class RegexGQ(TLDParser):
class RegexGQ(RegexTK):
tld_specific_expressions: ExpressionDict = {}

def parse(self, blob: str) -> dict[str, Any]:
# GQ server has the same format as TK
return RegexTK().parse(blob)


class RegexNL(TLDParser):
tld_specific_expressions: ExpressionDict = {
Expand Down

0 comments on commit 45b5720

Please sign in to comment.