Encode a single key, value pair.
(key: Any, value: Any, check_keys: bool, opts: CodecOptions[Any])
| 981 | |
| 982 | |
| 983 | def _element_to_bson(key: Any, value: Any, check_keys: bool, opts: CodecOptions[Any]) -> bytes: |
| 984 | """Encode a single key, value pair.""" |
| 985 | if not isinstance(key, str): |
| 986 | raise InvalidDocument(f"documents must have only string keys, key was {key!r}") |
| 987 | if check_keys: |
| 988 | if key.startswith("$"): |
| 989 | raise InvalidDocument(f"key {key!r} must not start with '$'") |
| 990 | if "." in key: |
| 991 | raise InvalidDocument(f"key {key!r} must not contain '.'") |
| 992 | |
| 993 | name = _make_name(key) |
| 994 | return _name_value_to_bson(name, value, check_keys, opts) |
| 995 | |
| 996 | |
| 997 | def _dict_to_bson( |
no test coverage detected