-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Modified the way dates are handled.
- Loading branch information
1 parent
202c7b4
commit 2cd8f4a
Showing
4 changed files
with
44 additions
and
21 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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
import json | ||
import socket | ||
import string | ||
from typing import Any, Set, Dict, Tuple, Union, Optional, Sequence | ||
from typing import Any, Set, Dict, List, Tuple, Union, Optional, Sequence | ||
from datetime import datetime | ||
|
||
import log21 | ||
|
@@ -26,7 +26,7 @@ | |
domain_registration_data_lookup, | ||
domain_registration_data_lookup_) | ||
|
||
__version__ = '1.4.2' | ||
__version__ = '1.4.3' | ||
__github__ = 'https://github.com/MPCodeWriter21/whois21' | ||
__author__ = 'CodeWriter21' | ||
__email__ = '[email protected]' | ||
|
@@ -206,9 +206,9 @@ def __init__( | |
self.registry_domain_id = None | ||
self.registrar_whois_server = None | ||
self.registrar_url = None | ||
self.updated_date: Optional[datetime] = None | ||
self.creation_date: Optional[datetime] = None | ||
self.expires_date: Optional[datetime] = None | ||
self.updated_date: Optional[List[datetime]] = None | ||
self.creation_date: Optional[List[datetime]] = None | ||
self.expires_date: Optional[List[datetime]] = None | ||
self.registrar_name: Union[str, set] = '' | ||
self.registrar_iana_id = None | ||
self.registrar_abuse_contact_email = None | ||
|
@@ -324,16 +324,34 @@ def __set_attrs(self): | |
self.status = data.get('DOMAIN STATUS', []) | ||
self.name_servers = data.get('NAME SERVER', []) + data.get('NSERVER', []) | ||
|
||
def parse_time(date_time: str) -> Union[datetime, None]: | ||
def parse_time( | ||
date_time: Union[str, Sequence[str]] | ||
) -> Union[List[datetime], None]: | ||
"""Parses a date time string. | ||
:param date_time: The date time string. | ||
:return: The parsed date time. | ||
""" | ||
try: | ||
return datetime.fromisoformat(date_time) | ||
except ValueError: | ||
return None | ||
if isinstance(date_time, str): | ||
try: | ||
return [datetime.fromisoformat(date_time)] | ||
except ValueError: | ||
return None | ||
else: | ||
if isinstance(date_time, Sequence): | ||
result = [] | ||
for date in date_time: | ||
try: | ||
result.append(datetime.fromisoformat(date)) | ||
except ValueError: | ||
pass | ||
except TypeError: | ||
log21.debug( | ||
"WHOIS: __set_attrs: parse_time: TypeError:", | ||
f"{date_time = }, {type(date_time) = }" | ||
) | ||
return result if result else None | ||
return None | ||
|
||
# Convert the dates to datetime objects. | ||
updated_date = ( | ||
|
@@ -577,10 +595,11 @@ def __parse_whois_data(self): | |
if (key := key_name.strip(STRIP_CHARS).upper()) not in data: | ||
data[key] = value.strip(STRIP_CHARS) | ||
else: | ||
if isinstance(data[key], list): | ||
data[key].append(value.strip(STRIP_CHARS)) | ||
elif isinstance(data[key], str): | ||
data[key] = [data[key], value.strip(STRIP_CHARS)] | ||
if (value := value.strip(STRIP_CHARS)): | ||
if isinstance(data[key], list): | ||
data[key].append(value) | ||
elif isinstance(data[key], str): | ||
data[key] = [data[key], value] | ||
i += 1 | ||
|
||
if not data: | ||
|
@@ -765,7 +784,7 @@ def domain(self) -> Union[str, int]: | |
return self.__domain | ||
|
||
@property | ||
def expiration_date(self) -> Optional[datetime]: | ||
def expiration_date(self) -> Optional[List[datetime]]: | ||
"""The expiration date of the domain (if available).""" | ||
return self.expires_date | ||
|
||
|