MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / parse_ipv6_literal_host

Function parse_ipv6_literal_host

pymongo/uri_parser_shared.py:149–169  ·  view source on GitHub ↗

Validates an IPv6 literal host:port string. Returns a 2-tuple of IPv6 literal followed by port where port is default_port if it wasn't specified in entity. :param entity: A string that represents an IPv6 literal enclosed in braces (e.g. '[::1]' or '[::1]:27017').

(
    entity: str, default_port: Optional[int]
)

Source from the content-addressed store, hash-verified

147
148
149def parse_ipv6_literal_host(
150 entity: str, default_port: Optional[int]
151) -> tuple[str, Optional[Union[str, int]]]:
152 """Validates an IPv6 literal host:port string.
153
154 Returns a 2-tuple of IPv6 literal followed by port where
155 port is default_port if it wasn't specified in entity.
156
157 :param entity: A string that represents an IPv6 literal enclosed
158 in braces (e.g. '[::1]' or '[::1]:27017').
159 :param default_port: The port number to use when one wasn't
160 specified in entity.
161 """
162 if entity.find("]") == -1:
163 raise ValueError(
164 "an IPv6 address literal must be enclosed in '[' and ']' according to RFC 2732."
165 )
166 i = entity.find("]:")
167 if i == -1:
168 return entity[1:-1], default_port
169 return entity[1:i], entity[i + 2 :]
170
171
172def parse_host(entity: str, default_port: Optional[int] = DEFAULT_PORT) -> _Address:

Callers 1

parse_hostFunction · 0.85

Calls 1

findMethod · 0.45

Tested by

no test coverage detected