Issue appropriate warnings when deprecated options are present in the options dictionary. Removes deprecated option key, value pairs if the options dictionary is found to also have the renamed option. :param options: Instance of _CaseInsensitiveDictionary containing MongoDB UR
(options: _CaseInsensitiveDictionary)
| 304 | |
| 305 | |
| 306 | def _handle_option_deprecations(options: _CaseInsensitiveDictionary) -> _CaseInsensitiveDictionary: |
| 307 | """Issue appropriate warnings when deprecated options are present in the |
| 308 | options dictionary. Removes deprecated option key, value pairs if the |
| 309 | options dictionary is found to also have the renamed option. |
| 310 | |
| 311 | :param options: Instance of _CaseInsensitiveDictionary containing |
| 312 | MongoDB URI options. |
| 313 | """ |
| 314 | for optname in list(options): |
| 315 | if optname in URI_OPTIONS_DEPRECATION_MAP: |
| 316 | mode, message = URI_OPTIONS_DEPRECATION_MAP[optname] |
| 317 | if mode == "renamed": |
| 318 | newoptname = message |
| 319 | if newoptname in options: |
| 320 | warn_msg = "Deprecated option '%s' ignored in favor of '%s'." |
| 321 | warnings.warn( |
| 322 | warn_msg % (options.cased_key(optname), options.cased_key(newoptname)), |
| 323 | DeprecationWarning, |
| 324 | stacklevel=2, |
| 325 | ) |
| 326 | options.pop(optname) |
| 327 | continue |
| 328 | warn_msg = "Option '%s' is deprecated, use '%s' instead." |
| 329 | warnings.warn( |
| 330 | warn_msg % (options.cased_key(optname), newoptname), |
| 331 | DeprecationWarning, |
| 332 | stacklevel=2, |
| 333 | ) |
| 334 | elif mode == "removed": |
| 335 | warn_msg = "Option '%s' is deprecated. %s." |
| 336 | warnings.warn( |
| 337 | warn_msg % (options.cased_key(optname), message), |
| 338 | DeprecationWarning, |
| 339 | stacklevel=2, |
| 340 | ) |
| 341 | |
| 342 | return options |
| 343 | |
| 344 | |
| 345 | def _normalize_options(options: _CaseInsensitiveDictionary) -> _CaseInsensitiveDictionary: |
no test coverage detected