Skip to content

Commit eca83e6

Browse files
committed
fix: fixing the codacy issue
Signed-off-by: Daniel Ntege <danientege785@gmail.com>
1 parent af32647 commit eca83e6

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/hiero_sdk_python/address_book/registered_service_endpoint.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,18 @@ def _validate_ip_address(self) -> None:
5454
def _validate_domain_name(self) -> None:
5555
"""Validate the endpoint domain name."""
5656
domain_name = self.domain_name
57+
self._validate_domain_name_presence(domain_name)
58+
self._validate_domain_name_length_and_ascii(domain_name)
59+
normalized_domain = self._normalize_domain_name(domain_name)
60+
self._validate_domain_labels(normalized_domain)
61+
62+
def _validate_domain_name_presence(self, domain_name: str | None) -> None:
63+
"""Ensure the domain name is present."""
5764
if not domain_name:
5865
raise ValueError("domain_name must not be empty.")
5966

67+
def _validate_domain_name_length_and_ascii(self, domain_name: str) -> None:
68+
"""Ensure the domain name length and charset are valid."""
6069
if len(domain_name) > 250:
6170
raise ValueError("domain_name must not exceed 250 ASCII characters.")
6271

@@ -65,10 +74,16 @@ def _validate_domain_name(self) -> None:
6574
except UnicodeEncodeError as exc:
6675
raise ValueError("domain_name must contain only ASCII characters.") from exc
6776

77+
def _normalize_domain_name(self, domain_name: str) -> str:
78+
"""Normalize a domain name for validation."""
6879
normalized_domain = domain_name[:-1] if domain_name.endswith(".") else domain_name
6980
if not normalized_domain:
7081
raise ValueError("domain_name must not be empty.")
7182

83+
return normalized_domain
84+
85+
def _validate_domain_labels(self, normalized_domain: str) -> None:
86+
"""Validate each label in the normalized domain name."""
7287
labels = normalized_domain.split(".")
7388
if any(not label for label in labels):
7489
raise ValueError("domain_name must be a valid domain name.")

0 commit comments

Comments
 (0)