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

Function _parse_canonical_regex

bson/json_util.py:690–704  ·  view source on GitHub ↗

Decode a JSON regex to bson.regex.Regex.

(doc: Any, dummy0: Any)

Source from the content-addressed store, hash-verified

688
689
690def _parse_canonical_regex(doc: Any, dummy0: Any) -> Regex[str]:
691 """Decode a JSON regex to bson.regex.Regex."""
692 regex = doc["$regularExpression"]
693 if len(doc) != 1:
694 raise TypeError(f"Bad $regularExpression, extra field(s): {doc}")
695 if len(regex) != 2:
696 raise TypeError(
697 f'Bad $regularExpression must include only "pattern and "options" components: {doc}'
698 )
699 opts = regex["options"]
700 if not isinstance(opts, str):
701 raise TypeError(
702 "Bad $regularExpression options, options must be string, was type %s" % (type(opts))
703 )
704 return Regex(regex["pattern"], opts)
705
706
707def _parse_canonical_dbref(doc: Any, dummy0: Any) -> Any:

Callers

nothing calls this directly

Calls 1

RegexClass · 0.90

Tested by

no test coverage detected