Decode a JSON regex to bson.regex.Regex.
(doc: Any, dummy0: Any)
| 688 | |
| 689 | |
| 690 | def _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 | |
| 707 | def _parse_canonical_dbref(doc: Any, dummy0: Any) -> Any: |