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

Function _get_object

bson/__init__.py:313–331  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

311
312
313def _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
334def _get_array(

Callers 1

_get_code_w_scopeFunction · 0.85

Calls 6

_raw_document_classFunction · 0.90
DBRefClass · 0.90
_get_object_sizeFunction · 0.85
_elements_to_dictFunction · 0.85
getMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected