Description
PYTHON-1785 implemented support for BSON decoding from memoryview objects but it does not support memoryviews with offsets, eg:
>>> from bson import decode, encode
|
>>> decode(memoryview(encode({})))
|
{}
|
>>> decode(memoryview(b'123'+encode({}))[3:])
|
Traceback (most recent call last):
|
File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 484, in _bson_to_dict
|
_, end = _get_object_size(data, 0, len(data))
|
File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 232, in _get_object_size
|
if data[end] != _OBJEND:
|
IndexError: index out of range
|
|
During handling of the above exception, another exception occurred:
|
|
Traceback (most recent call last):
|
File "<stdin>", line 1, in <module>
|
File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 983, in decode
|
return _bson_to_dict(data, codec_options)
|
File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 491, in _bson_to_dict
|
reraise(InvalidBSON, exc_value, exc_tb)
|
File "/Users/shane/git/mongo-python-driver/bson/py3compat.py", line 53, in reraise
|
raise exctype(str(value)).with_traceback(trace)
|
File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 484, in _bson_to_dict
|
_, end = _get_object_size(data, 0, len(data))
|
File "/Users/shane/git/mongo-python-driver/bson/__init__.py", line 232, in _get_object_size
|
if data[end] != _OBJEND:
|
bson.errors.InvalidBSON: index out of range
|
Attachments
Issue Links
- is caused by
-
PYTHON-1785 Provide utility encode and decode methods in BSON module
-
- Closed
-