Skip to content

Commit fad3686

Browse files
committed
introduce frozenset of proper cased uri options
1 parent 45de7e6 commit fad3686

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

pymongo/asynchronous/uri_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
SCHEME_LEN,
3030
SRV_SCHEME_LEN,
3131
_check_options,
32+
_make_options_case_sensative,
3233
_validate_uri,
3334
split_hosts,
3435
split_options,
@@ -113,7 +114,7 @@ async def parse_uri(
113114
srv_max_hosts,
114115
)
115116
)
116-
result["options"] = result["options"].as_dict()
117+
result["options"] = _make_options_case_sensative(result["options"])
117118
return result
118119

119120

pymongo/common.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,6 @@ def update(self, other: Mapping[str, Any]) -> None: # type: ignore[override]
10831083
def cased_key(self, key: str) -> Any:
10841084
return self.__casedkeys[key.lower()]
10851085

1086-
def as_dict(self) -> dict[str, Any]:
1087-
return {self.__casedkeys[k]: self.__data[k] for k in self}
1088-
10891086

10901087
def has_c() -> bool:
10911088
"""Is the C extension installed?"""

pymongo/synchronous/uri_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
SCHEME_LEN,
3030
SRV_SCHEME_LEN,
3131
_check_options,
32+
_make_options_case_sensative,
3233
_validate_uri,
3334
split_hosts,
3435
split_options,
@@ -113,7 +114,7 @@ def parse_uri(
113114
srv_max_hosts,
114115
)
115116
)
116-
result["options"] = result["options"].as_dict()
117+
result["options"] = _make_options_case_sensative(result["options"])
117118
return result
118119

119120

pymongo/uri_parser_shared.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,57 @@
5454
SRV_SCHEME_LEN = len(SRV_SCHEME)
5555
DEFAULT_PORT = 27017
5656

57+
URI_OPTIONS = frozenset(
58+
[
59+
"appname",
60+
"authMechanism",
61+
"authMechanismProperties",
62+
"authSource",
63+
"compressors",
64+
"connectTimeoutMS",
65+
"directConnection",
66+
"heartbeatFrequencyMS",
67+
"journal",
68+
"loadBalanced",
69+
"localThresholdMS",
70+
"maxIdleTimeMS",
71+
"maxPoolSize",
72+
"maxConnecting",
73+
"maxStalenessSeconds",
74+
"minPoolSize",
75+
"proxyHost",
76+
"proxyPort",
77+
"proxyUsername",
78+
"proxyPassword",
79+
"readConcernLevel",
80+
"readPreference",
81+
"readPreferenceTags",
82+
"replicaSet",
83+
"retryReads",
84+
"retryWrites",
85+
"serverMonitoringMode",
86+
"serverSelectionTimeoutMS",
87+
"serverSelectionTryOnce",
88+
"socketTimeoutMS",
89+
"srvMaxHosts",
90+
"srvServiceName",
91+
"ssl",
92+
"tls",
93+
"tlsAllowInvalidCertificates",
94+
"tlsAllowInvalidHostnames",
95+
"tlsCAFile",
96+
"tlsCertificateKeyFile",
97+
"tlsCertificateKeyFilePassword",
98+
"tlsDisableCertificateRevocationCheck",
99+
"tlsDisableOCSPEndpointCheck",
100+
"tlsInsecure",
101+
"w",
102+
"waitQueueTimeoutMS",
103+
"wTimeoutMS",
104+
"zlibCompressionLevel",
105+
]
106+
)
107+
57108

58109
def _unquoted_percent(s: str) -> bool:
59110
"""Check for unescaped percent signs.
@@ -550,3 +601,11 @@ def _validate_uri(
550601
"options": options,
551602
"fqdn": fqdn,
552603
}
604+
605+
606+
def _make_options_case_sensative(options: _CaseInsensitiveDictionary) -> dict[str, Any]:
607+
case_sensative = {}
608+
for option in URI_OPTIONS:
609+
if option.lower() in options:
610+
case_sensative[option] = options[option]
611+
return case_sensative

0 commit comments

Comments
 (0)