mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-25 12:08:40 +02:00
Respond to PR feedback
This commit is contained in:
parent
07993a8d75
commit
90557c51e8
4 changed files with 47 additions and 22 deletions
|
@ -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://"):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue