Decode a BSON string to document_class.
(data: Any, opts: CodecOptions[_DocumentType])
| 619 | |
| 620 | |
| 621 | def _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 | |
| 637 | if _USE_C: |