@@ -136,16 +136,22 @@ def _get_connection_settings(
136136 if uri_dict .get (param ):
137137 conn_settings [param ] = uri_dict [param ]
138138
139- uri_options = uri_dict [
140- "options"
141- ] # uri_options is a _CaseInsensitiveDictionary
142- if "replicaset" in uri_options :
143- conn_settings ["replicaSet" ] = uri_options ["replicaset" ]
144- if "authsource" in uri_options :
145- conn_settings ["authentication_source" ] = uri_options ["authsource" ]
146- if "authmechanism" in uri_options :
147- conn_settings ["authentication_mechanism" ] = uri_options ["authmechanism" ]
148- if "readpreference" in uri_options :
139+ uri_options = uri_dict ["options" ]
140+ normalized_uri_options = {
141+ key .lower (): value for key , value in uri_options .items ()
142+ }
143+
144+ if "replicaset" in normalized_uri_options :
145+ conn_settings ["replicaSet" ] = normalized_uri_options ["replicaset" ]
146+ if "authsource" in normalized_uri_options :
147+ conn_settings ["authentication_source" ] = normalized_uri_options [
148+ "authsource"
149+ ]
150+ if "authmechanism" in normalized_uri_options :
151+ conn_settings ["authentication_mechanism" ] = normalized_uri_options [
152+ "authmechanism"
153+ ]
154+ if "readpreference" in normalized_uri_options :
149155 read_preferences = (
150156 ReadPreference .NEAREST ,
151157 ReadPreference .PRIMARY ,
@@ -159,7 +165,7 @@ def _get_connection_settings(
159165 # int (e.g. 3).
160166 # TODO simplify the code below once we drop support for
161167 # PyMongo v3.4.
162- read_pf_mode = uri_options ["readpreference" ]
168+ read_pf_mode = normalized_uri_options ["readpreference" ]
163169 if isinstance (read_pf_mode , str ):
164170 read_pf_mode = read_pf_mode .lower ()
165171 for preference in read_preferences :
@@ -170,23 +176,23 @@ def _get_connection_settings(
170176 ReadPrefClass = preference .__class__
171177 break
172178
173- if "readpreferencetags" in uri_options :
179+ if "readpreferencetags" in normalized_uri_options :
174180 conn_settings ["read_preference" ] = ReadPrefClass (
175- tag_sets = uri_options ["readpreferencetags" ]
181+ tag_sets = normalized_uri_options ["readpreferencetags" ]
176182 )
177183 else :
178184 conn_settings ["read_preference" ] = ReadPrefClass ()
179185
180- if "authmechanismproperties" in uri_options :
181- conn_settings ["authmechanismproperties" ] = uri_options [
186+ if "authmechanismproperties" in normalized_uri_options :
187+ conn_settings ["authmechanismproperties" ] = normalized_uri_options [
182188 "authmechanismproperties"
183189 ]
184- if "uuidrepresentation" in uri_options :
190+ if "uuidrepresentation" in normalized_uri_options :
185191 REV_UUID_REPRESENTATIONS = {
186192 v : k for k , v in _UUID_REPRESENTATIONS .items ()
187193 }
188194 conn_settings ["uuidrepresentation" ] = REV_UUID_REPRESENTATIONS [
189- uri_options ["uuidrepresentation" ]
195+ normalized_uri_options ["uuidrepresentation" ]
190196 ]
191197 else :
192198 resolved_hosts .append (entity )
0 commit comments