Respond to PR feedback

This commit is contained in:
Seamus Johnston 2022-12-06 15:51:41 -06:00
parent 07993a8d75
commit 90557c51e8
No known key found for this signature in database
GPG key ID: 2F21225985069105
4 changed files with 47 additions and 22 deletions

View file

@ -93,10 +93,17 @@ class Domain(TimeStampedModel):
DOMAIN_REGEX = re.compile(r"^(?!-)[A-Za-z0-9-]{1,63}(?<!-)\.[A-Za-z]{2,6}")
@classmethod
def normalize(cls, domain: str, tld=None) -> str: # noqa: C901
"""Return `domain` in form `<second level>.<tld>`, if possible.
def normalize(cls, domain: str, tld=None, blank=False) -> str: # noqa: C901
"""Return `domain` in form `<second level>.<tld>`.
This does not guarantee the returned string is a valid domain name."""
Raises ValueError if string cannot be normalized.
This does not guarantee the returned string is a valid domain name.
Set `blank` to True to allow empty strings.
"""
if blank and len(domain.strip()) == 0:
return ""
cleaned = domain.lower()
# starts with https or http
if cleaned.startswith("https://"):