Public Member Functions | |
| def | decode |
| def | encode |
| def | from_dict |
| def | to_dict |
BSON (Binary JSON) data.
Definition at line 420 of file bson/__init__.py.
| def bson::BSON::decode | ( | self, | ||
as_class = dict, |
||||
tz_aware = False | ||||
| ) |
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
.. versionadded:: 1.9
Definition at line 471 of file bson/__init__.py.
| def bson::BSON::encode | ( | cls, | ||
| document, | ||||
check_keys = False | ||||
| ) |
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`. 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
.. versionadded:: 1.9
Definition at line 436 of file bson/__init__.py.
| def bson::BSON::from_dict | ( | cls, | ||
| dct, | ||||
check_keys = False | ||||
| ) |
DEPRECATED - `from_dict` has been renamed to `encode`. .. versionchanged:: 1.9 Deprecated in favor of :meth:`encode`
Definition at line 425 of file bson/__init__.py.
| def bson::BSON::to_dict | ( | self, | ||
as_class = dict, |
||||
tz_aware = False | ||||
| ) |
DEPRECATED - `to_dict` has been renamed to `decode`. .. versionchanged:: 1.9 Deprecated in favor of :meth:`decode` .. versionadded:: 1.8 The `tz_aware` parameter. .. versionadded:: 1.7 The `as_class` parameter.
Definition at line 457 of file bson/__init__.py.