File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5151
5252
5353def _is_valid_group (group : str ) -> bool :
54- """Return True iff group is 1-4 hex digits."""
54+ """Return True iff group is 1-4 hex digits.
55+ Args:
56+ group (str): The hex group to validate.
57+
58+ Returns:
59+ bool: True if the group is 1-4 hex digits, False otherwise.
60+
61+ Examples:
62+
63+ >>> _is_valid_group("1")
64+ True
65+ >>> _is_valid_group("abcd")
66+ True
67+ >>> _is_valid_group("12345") # too long
68+ False
69+ >>> _is_valid_group("g") # non-hex character
70+ False
71+ """
5572 return 1 <= len (group ) <= 4 and all (ch in _HEX_DIGITS for ch in group )
5673
5774
@@ -102,6 +119,9 @@ def is_ipv6_address_valid(address: str) -> bool:
102119
103120
104121if __name__ == "__main__" :
122+ from doctest import testmod
123+
124+ testmod ()
105125 ip = input ().strip ()
106126 valid_or_invalid = "valid" if is_ipv6_address_valid (ip ) else "invalid"
107127 print (f"{ ip } is a { valid_or_invalid } IPv6 address." )
You can’t perform that action at this time.
0 commit comments