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)
| 123 | |
| 124 | |
| 125 | def 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 | |
| 149 | def parse_ipv6_literal_host( |