Add compile_re support to decode_(file_)iter.
This commit is contained in:
parent
5c4556b013
commit
7858dcb868
@ -542,8 +542,8 @@ if _use_c:
|
||||
decode_all = _cbson.decode_all
|
||||
|
||||
|
||||
def decode_iter(data, as_class=dict,
|
||||
tz_aware=True, uuid_subtype=OLD_UUID_SUBTYPE):
|
||||
def decode_iter(data, as_class=dict, tz_aware=True,
|
||||
uuid_subtype=OLD_UUID_SUBTYPE, compile_re=True):
|
||||
"""Decode BSON data to multiple documents as a generator. Works
|
||||
similarly to the decode_all function, but yields one document
|
||||
at a time.
|
||||
@ -557,6 +557,13 @@ def decode_iter(data, as_class=dict,
|
||||
documents
|
||||
- `tz_aware` (optional): if ``True``, return timezone-aware
|
||||
:class:`~datetime.datetime` instances
|
||||
- `compile_re` (optional): if ``False``, don't attempt to compile
|
||||
BSON regular expressions into Python regular expressions. Return
|
||||
instances of
|
||||
:class:`~bson.regex.Regex` instead. Can avoid
|
||||
:exc:`~bson.errors.InvalidBSON` errors when receiving
|
||||
Python-incompatible regular expressions, for example from
|
||||
``currentOp``
|
||||
|
||||
.. versionadded:: 2.5
|
||||
"""
|
||||
@ -571,11 +578,12 @@ def decode_iter(data, as_class=dict,
|
||||
elements = data[position + 4:position + obj_size - 1]
|
||||
position += obj_size
|
||||
|
||||
yield _elements_to_dict(elements, as_class, tz_aware, uuid_subtype)
|
||||
yield _elements_to_dict(elements, as_class,
|
||||
tz_aware, uuid_subtype, compile_re)
|
||||
|
||||
|
||||
def decode_file_iter(file_obj, as_class=dict, tz_aware=True,
|
||||
uuid_subtype=OLD_UUID_SUBTYPE):
|
||||
uuid_subtype=OLD_UUID_SUBTYPE, compile_re=True):
|
||||
"""Decode bson data from a file to multiple documents as a generator. Works
|
||||
similarly to the decode_all function, but reads from the file object in
|
||||
chunks and parses bson in chunks, yielding one document at a time.
|
||||
@ -586,6 +594,13 @@ def decode_file_iter(file_obj, as_class=dict, tz_aware=True,
|
||||
documents
|
||||
- `tz_aware` (optional): if ``True``, return timezone-aware
|
||||
:class:`~datetime.datetime` instances
|
||||
- `compile_re` (optional): if ``False``, don't attempt to compile
|
||||
BSON regular expressions into Python regular expressions. Return
|
||||
instances of
|
||||
:class:`~bson.regex.Regex` instead. Can avoid
|
||||
:exc:`~bson.errors.InvalidBSON` errors when receiving
|
||||
Python-incompatible regular expressions, for example from
|
||||
``currentOp``
|
||||
|
||||
.. versionadded:: 2.5
|
||||
"""
|
||||
@ -615,7 +630,7 @@ def decode_file_iter(file_obj, as_class=dict, tz_aware=True,
|
||||
raise InvalidBSON("bad eoo")
|
||||
|
||||
yield _elements_to_dict(elements[:-1], as_class,
|
||||
tz_aware, uuid_subtype)
|
||||
tz_aware, uuid_subtype, compile_re)
|
||||
|
||||
|
||||
def is_valid(bson):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user