SequoiaDB
 All Classes Functions
Public Member Functions | List of all members
bson.BSON Class Reference
Inheritance diagram for bson.BSON:

Public Member Functions

def encode
 
def decode
 

Detailed Description

BSON (Binary JSON) data.

Member Function Documentation

def bson.BSON.decode (   self,
  as_class = dict,
  tz_aware = False,
  uuid_subtype = OLD_UUID_SUBTYPE,
  compile_re = True 
)
Decode this BSON data.

The default type to use for the resultant document is
:class:`dict`. Any other class that supports
:meth:`__setitem__` can be used instead by passing it as the
`as_class` parameter.

If `tz_aware` is ``True`` (recommended), any
:class:`~datetime.datetime` instances returned will be
timezone-aware, with their timezone set to
:attr:`bson.tz_util.utc`. Otherwise (default), all
:class:`~datetime.datetime` instances will be naive (but
contain UTC).

:Parameters:
  - `as_class` (optional): the class to use for the resulting
    document
  - `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``

.. versionchanged:: 2.7
   Added ``compile_re`` option.
.. versionadded:: 1.9
def bson.BSON.encode (   cls,
  document,
  check_keys = False,
  uuid_subtype = OLD_UUID_SUBTYPE,
  extend_obj = None 
)
Encode a document to a new :class:`BSON` instance.

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

If you want use special type, you should use the corresponding
special type class. like "$oid" corresponding ObjectId, in error eg,
document will be as common type rather than special type
    eg:
oid = ObjectId("5d035e2bb4d450b04fcd0dff")
document = {"_id" : oid}
    error eg:
document = {"_id":{"$oid":"5d035e2bb4d450b04fcd0dff"}}


.. versionadded:: 1.9

The documentation for this class was generated from the following file: