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

Function get_validated_options

pymongo/common.py:828–876  ·  view source on GitHub ↗

Validate each entry in options and raise a warning if it is not valid. Returns a copy of options with invalid entries removed. :param opts: A dict containing MongoDB URI options. :param warn: If ``True`` then warnings will be logged and invalid options will be ignored. Otherwi

(
    options: Mapping[str, Any], warn: bool = True
)

Source from the content-addressed store, hash-verified

826
827
828def get_validated_options(
829 options: Mapping[str, Any], warn: bool = True
830) -> MutableMapping[str, Any]:
831 """Validate each entry in options and raise a warning if it is not valid.
832 Returns a copy of options with invalid entries removed.
833
834 :param opts: A dict containing MongoDB URI options.
835 :param warn: If ``True`` then warnings will be logged and
836 invalid options will be ignored. Otherwise, invalid options will
837 cause errors.
838 """
839 validated_options: MutableMapping[str, Any]
840 if isinstance(options, _CaseInsensitiveDictionary):
841 validated_options = _CaseInsensitiveDictionary()
842
843 def get_normed_key(x: str) -> str:
844 return x
845
846 def get_setter_key(x: str) -> str:
847 return options.cased_key(x)
848
849 else:
850 validated_options = {}
851
852 def get_normed_key(x: str) -> str:
853 return x.lower()
854
855 def get_setter_key(x: str) -> str:
856 return x
857
858 for opt, value in options.items():
859 normed_key = get_normed_key(opt)
860 try:
861 validator = _get_validator(opt, URI_OPTIONS_VALIDATOR_MAP, normed_key=normed_key)
862 validated = validator(opt, value)
863 except (ValueError, TypeError, ConfigurationError) as exc:
864 if (
865 normed_key == "authmechanismproperties"
866 and any(p in str(exc) for p in _MECH_PROP_MUST_RAISE)
867 and "is not a supported auth mechanism property" not in str(exc)
868 ):
869 raise
870 if warn:
871 warnings.warn(str(exc), stacklevel=2)
872 else:
873 raise
874 else:
875 validated_options[get_setter_key(normed_key)] = validated
876 return validated_options
877
878
879def _esc_coll_name(encrypted_fields: Mapping[str, Any], name: str) -> Any:

Callers 1

validate_optionsFunction · 0.90

Calls 5

get_normed_keyFunction · 0.85
_get_validatorFunction · 0.85
get_setter_keyFunction · 0.85
itemsMethod · 0.80

Tested by

no test coverage detected