OpenQuizz
Une application de gestion des contenus pédagogiques
bson Namespace Reference

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
 

Function Documentation

◆ decode()

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

◆ decode_all()

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

◆ decode_file_iter()

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

◆ decode_iter()

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

◆ encode()

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

◆ gen_list_name()

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.

◆ get_data_and_view()

def get_data_and_view (   data)

◆ has_c()

def bson.has_c ( )
Is the C extension installed?

◆ is_valid()

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

Variable Documentation

◆ BSONARR

string BSONARR = b"\x04"

◆ BSONBIN

string BSONBIN = b"\x05"

◆ BSONBOO

string BSONBOO = b"\x08"

◆ BSONCOD

string BSONCOD = b"\x0D"

◆ BSONCWS

string BSONCWS = b"\x0F"

◆ BSONDAT

string BSONDAT = b"\x09"

◆ BSONDEC

string BSONDEC = b"\x13"

◆ BSONINT

string BSONINT = b"\x10"

◆ BSONLON

string BSONLON = b"\x12"

◆ BSONMAX

string BSONMAX = b"\x7F"

◆ BSONMIN

string BSONMIN = b"\xFF"

◆ BSONNUL

string BSONNUL = b"\x0A"

◆ BSONNUM

string BSONNUM = b"\x01"

◆ BSONOBJ

string BSONOBJ = b"\x03"

◆ BSONOID

string BSONOID = b"\x07"

◆ BSONREF

string BSONREF = b"\x0C"

◆ BSONRGX

string BSONRGX = b"\x0B"

◆ BSONSTR

string BSONSTR = b"\x02"

◆ BSONSYM

string BSONSYM = b"\x0E"

◆ BSONTIM

string BSONTIM = b"\x11"

◆ BSONUND

string BSONUND = b"\x06"

◆ decode_all

def decode_all = _cbson.decode_all

◆ EPOCH_AWARE

EPOCH_AWARE = datetime.datetime.fromtimestamp(0, utc)

◆ EPOCH_NAIVE

EPOCH_NAIVE = datetime.datetime.utcfromtimestamp(0)