MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / parse_userinfo

Function parse_userinfo

pymongo/uri_parser_shared.py:125–146  ·  view source on GitHub ↗

Validates the format of user information in a MongoDB URI. Reserved characters that are gen-delimiters (":", "/", "?", "#", "[", "]", "@") as per RFC 3986 must be escaped. Returns a 2-tuple containing the unescaped username followed by the unescaped password. :param userinfo: A

(userinfo: str)

Source from the content-addressed store, hash-verified

123
124
125def parse_userinfo(userinfo: str) -> tuple[str, str]:
126 """Validates the format of user information in a MongoDB URI.
127 Reserved characters that are gen-delimiters (":", "/", "?", "#", "[",
128 "]", "@") as per RFC 3986 must be escaped.
129
130 Returns a 2-tuple containing the unescaped username followed
131 by the unescaped password.
132
133 :param userinfo: A string of the form <username>:<password>
134 """
135 if "@" in userinfo or userinfo.count(":") > 1 or _unquoted_percent(userinfo):
136 raise InvalidURI(
137 "Username and password must be escaped according to "
138 "RFC 3986, use urllib.parse.quote_plus"
139 )
140
141 user, _, passwd = userinfo.partition(":")
142 # No password is expected with GSSAPI authentication.
143 if not user:
144 raise InvalidURI("The empty string is not valid username")
145
146 return unquote_plus(user), unquote_plus(passwd)
147
148
149def parse_ipv6_literal_host(

Callers 2

_validate_uriFunction · 0.85

Calls 2

InvalidURIClass · 0.90
_unquoted_percentFunction · 0.85

Tested by 1