Decode a BSON subdocument to opts.document_class or bson.dbref.DBRef.
(
data: Any, view: Any, position: int, obj_end: int, opts: CodecOptions[Any], dummy: Any
)
| 311 | |
| 312 | |
| 313 | def _get_object( |
| 314 | data: Any, view: Any, position: int, obj_end: int, opts: CodecOptions[Any], dummy: Any |
| 315 | ) -> Tuple[Any, int]: |
| 316 | """Decode a BSON subdocument to opts.document_class or bson.dbref.DBRef.""" |
| 317 | obj_size, end = _get_object_size(data, position, obj_end) |
| 318 | if _raw_document_class(opts.document_class): |
| 319 | return (opts.document_class(data[position : end + 1], opts), position + obj_size) |
| 320 | |
| 321 | obj = _elements_to_dict(data, view, position + 4, end, opts) |
| 322 | |
| 323 | position += obj_size |
| 324 | # If DBRef validation fails, return a normal doc. |
| 325 | if ( |
| 326 | isinstance(obj.get("$ref"), str) |
| 327 | and "$id" in obj |
| 328 | and isinstance(obj.get("$db"), (str, type(None))) |
| 329 | ): |
| 330 | return (DBRef(obj.pop("$ref"), obj.pop("$id", None), obj.pop("$db", None), obj), position) |
| 331 | return obj, position |
| 332 | |
| 333 | |
| 334 | def _get_array( |
no test coverage detected