|
OpenQuizz
Une application de gestion des contenus pédagogiques
|
Namespaces | |
| binary | |
| code | |
| codec_options | |
| dbref | |
| decimal128 | |
| errors | |
| int64 | |
| json_util | |
| max_key | |
| min_key | |
| objectid | |
| py3compat | |
| raw_bson | |
| regex | |
| son | |
| timestamp | |
| tz_util | |
Data Structures | |
| class | BSON |
Functions | |
| def | get_data_and_view (data) |
| def | gen_list_name () |
| def | encode (document, check_keys=False, codec_options=DEFAULT_CODEC_OPTIONS) |
| def | decode (data, codec_options=DEFAULT_CODEC_OPTIONS) |
| def | decode_all (data, codec_options=DEFAULT_CODEC_OPTIONS) |
| def | decode_iter (data, codec_options=DEFAULT_CODEC_OPTIONS) |
| def | decode_file_iter (file_obj, codec_options=DEFAULT_CODEC_OPTIONS) |
| def | is_valid (bson) |
| def | has_c () |
Variables | |
| EPOCH_AWARE = datetime.datetime.fromtimestamp(0, utc) | |
| EPOCH_NAIVE = datetime.datetime.utcfromtimestamp(0) | |
| string | BSONNUM = b"\x01" |
| string | BSONSTR = b"\x02" |
| string | BSONOBJ = b"\x03" |
| string | BSONARR = b"\x04" |
| string | BSONBIN = b"\x05" |
| string | BSONUND = b"\x06" |
| string | BSONOID = b"\x07" |
| string | BSONBOO = b"\x08" |
| string | BSONDAT = b"\x09" |
| string | BSONNUL = b"\x0A" |
| string | BSONRGX = b"\x0B" |
| string | BSONREF = b"\x0C" |
| string | BSONCOD = b"\x0D" |
| string | BSONSYM = b"\x0E" |
| string | BSONCWS = b"\x0F" |
| string | BSONINT = b"\x10" |
| string | BSONTIM = b"\x11" |
| string | BSONLON = b"\x12" |
| string | BSONDEC = b"\x13" |
| string | BSONMIN = b"\xFF" |
| string | BSONMAX = b"\x7F" |
| def | decode_all = _cbson.decode_all |
| def bson.decode | ( | data, | |
codec_options = DEFAULT_CODEC_OPTIONS |
|||
| ) |
Decode BSON to a document.
By default, returns a BSON document represented as a Python
:class:`dict`. To use a different :class:`MutableMapping` class,
configure a :class:`~bson.codec_options.CodecOptions`::
>>> import collections # From Python standard library.
>>> import bson
>>> from bson.codec_options import CodecOptions
>>> data = bson.encode({'a': 1})
>>> decoded_doc = bson.decode(data)
<type 'dict'>
>>> options = CodecOptions(document_class=collections.OrderedDict)
>>> decoded_doc = bson.decode(data, codec_options=options)
>>> type(decoded_doc)
<class 'collections.OrderedDict'>
:Parameters:
- `data`: the BSON to decode. Any bytes-like object that implements
the buffer protocol.
- `codec_options` (optional): An instance of
:class:`~bson.codec_options.CodecOptions`.
.. versionadded:: 3.9
| def bson.decode_all | ( | data, | |
codec_options = DEFAULT_CODEC_OPTIONS |
|||
| ) |
Decode BSON data to multiple documents.
`data` must be a bytes-like object implementing the buffer protocol that
provides concatenated, valid, BSON-encoded documents.
:Parameters:
- `data`: BSON data
- `codec_options` (optional): An instance of
:class:`~bson.codec_options.CodecOptions`.
.. versionchanged:: 3.9
Supports bytes-like objects that implement the buffer protocol.
.. versionchanged:: 3.0
Removed `compile_re` option: PyMongo now always represents BSON regular
expressions as :class:`~bson.regex.Regex` objects. Use
:meth:`~bson.regex.Regex.try_compile` to attempt to convert from a
BSON regular expression to a Python regular expression object.
Replaced `as_class`, `tz_aware`, and `uuid_subtype` options with
`codec_options`.
.. versionchanged:: 2.7
Added `compile_re` option. If set to False, PyMongo represented BSON
regular expressions as :class:`~bson.regex.Regex` objects instead of
attempting to compile BSON regular expressions as Python native
regular expressions, thus preventing errors for some incompatible
patterns, see `PYTHON-500`_.
.. _PYTHON-500: https://jira.mongodb.org/browse/PYTHON-500
| def bson.decode_file_iter | ( | file_obj, | |
codec_options = DEFAULT_CODEC_OPTIONS |
|||
| ) |
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.
:Parameters:
- `file_obj`: A file object containing BSON data.
- `codec_options` (optional): An instance of
:class:`~bson.codec_options.CodecOptions`.
.. versionchanged:: 3.0
Replaced `as_class`, `tz_aware`, and `uuid_subtype` options with
`codec_options`.
.. versionadded:: 2.8
| def bson.decode_iter | ( | data, | |
codec_options = DEFAULT_CODEC_OPTIONS |
|||
| ) |
Decode BSON data to multiple documents as a generator.
Works similarly to the decode_all function, but yields one document at a
time.
`data` must be a string of concatenated, valid, BSON-encoded
documents.
:Parameters:
- `data`: BSON data
- `codec_options` (optional): An instance of
:class:`~bson.codec_options.CodecOptions`.
.. versionchanged:: 3.0
Replaced `as_class`, `tz_aware`, and `uuid_subtype` options with
`codec_options`.
.. versionadded:: 2.8
| def bson.encode | ( | document, | |
check_keys = False, |
|||
codec_options = DEFAULT_CODEC_OPTIONS |
|||
| ) |
Encode a document to BSON.
A document can be any mapping type (like :class:`dict`).
Raises :class:`TypeError` if `document` is not a mapping type,
or contains keys that are not instances of
:class:`basestring` (:class:`str` in python 3). Raises
:class:`~bson.errors.InvalidDocument` if `document` cannot be
converted to :class:`BSON`.
:Parameters:
- `document`: mapping type representing a document
- `check_keys` (optional): check if keys start with '$' or
contain '.', raising :class:`~bson.errors.InvalidDocument` in
either case
- `codec_options` (optional): An instance of
:class:`~bson.codec_options.CodecOptions`.
.. versionadded:: 3.9
| def bson.gen_list_name | ( | ) |
Generate "keys" for encoded lists in the sequence b"0\x00", b"1\x00", b"2\x00", ... The first 1000 keys are returned from a pre-built cache. All subsequent keys are generated on the fly.
| def get_data_and_view | ( | data | ) |
| def bson.has_c | ( | ) |
Is the C extension installed?
| def bson.is_valid | ( | bson | ) |
Check that the given string represents valid :class:`BSON` data. Raises :class:`TypeError` if `bson` is not an instance of :class:`str` (:class:`bytes` in python 3). Returns ``True`` if `bson` is valid :class:`BSON`, ``False`` otherwise. :Parameters: - `bson`: the data to be validated
| string BSONARR = b"\x04" |
| string BSONBIN = b"\x05" |
| string BSONBOO = b"\x08" |
| string BSONCOD = b"\x0D" |
| string BSONCWS = b"\x0F" |
| string BSONDAT = b"\x09" |
| string BSONDEC = b"\x13" |
| string BSONINT = b"\x10" |
| string BSONLON = b"\x12" |
| string BSONMAX = b"\x7F" |
| string BSONMIN = b"\xFF" |
| string BSONNUL = b"\x0A" |
| string BSONNUM = b"\x01" |
| string BSONOBJ = b"\x03" |
| string BSONOID = b"\x07" |
| string BSONREF = b"\x0C" |
| string BSONRGX = b"\x0B" |
| string BSONSTR = b"\x02" |
| string BSONSYM = b"\x0E" |
| string BSONTIM = b"\x11" |
| string BSONUND = b"\x06" |
| def decode_all = _cbson.decode_all |
| EPOCH_AWARE = datetime.datetime.fromtimestamp(0, utc) |
| EPOCH_NAIVE = datetime.datetime.utcfromtimestamp(0) |