MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / _bson_to_dict

Function _bson_to_dict

bson/__init__.py:621–634  ·  view source on GitHub ↗

Decode a BSON string to document_class.

(data: Any, opts: CodecOptions[_DocumentType])

Source from the content-addressed store, hash-verified

619
620
621def _bson_to_dict(data: Any, opts: CodecOptions[_DocumentType]) -> _DocumentType:
622 """Decode a BSON string to document_class."""
623 data, view = get_data_and_view(data)
624 try:
625 if _raw_document_class(opts.document_class):
626 return opts.document_class(data, opts) # type:ignore[call-arg]
627 _, end = _get_object_size(data, 0, len(data))
628 return cast("_DocumentType", _elements_to_dict(data, view, 4, end, opts))
629 except InvalidBSON:
630 raise
631 except Exception:
632 # Change exception type to InvalidBSON but preserve traceback.
633 _, exc_value, exc_tb = sys.exc_info()
634 raise InvalidBSON(str(exc_value)).with_traceback(exc_tb) from None
635
636
637if _USE_C:

Callers 10

test__bson_to_dictMethod · 0.90
test__bson_to_dictMethod · 0.90
try_nextMethod · 0.90
try_nextMethod · 0.90
decodeFunction · 0.85
_decode_selectiveFunction · 0.85
_decode_all_selectiveFunction · 0.85
decode_iterFunction · 0.85
decode_file_iterFunction · 0.85
is_validFunction · 0.85

Calls 5

_raw_document_classFunction · 0.90
InvalidBSONClass · 0.90
get_data_and_viewFunction · 0.85
_get_object_sizeFunction · 0.85
_elements_to_dictFunction · 0.85

Tested by 2

test__bson_to_dictMethod · 0.72
test__bson_to_dictMethod · 0.72