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

Public Member Functions

def __init__
 
def __new__
 
def __repr__
 
def __setitem__
 
def __delitem__
 
def keys
 
def copy
 
def __iter__
 
def has_key
 
def __contains__
 
def iteritems
 
def iterkeys
 
def itervalues
 
def values
 
def items
 
def clear
 
def setdefault
 
def pop
 
def popitem
 
def update
 
def get
 
def __eq__
 
def __ne__
 
def __len__
 
def to_dict
 
def __deepcopy__
 

Detailed Description

SON data.

A subclass of dict that maintains ordering of keys and provides a
few extra niceties for dealing with SON. SON objects can be
converted to and from BSON.

The mapping from Python types to BSON types is as follows:

=======================================  =============  ===================
Python Type                              BSON Type      Supported Direction
=======================================  =============  ===================
None                                     null           both
bool                                     boolean        both
int [#int]_                              int32 / int64  py -> bson
long                                     int64          both
float                                    number (real)  both
string                                   string         py -> bson
unicode                                  string         both
list                                     array          both
dict / `SON`                             object         both
datetime.datetime [#dt]_ [#dt2]_         date           both
`bson.regex.Regex` / compiled re [#re]_  regex          both
`bson.binary.Binary`                     binary         both
`bson.objectid.ObjectId`                 oid            both
`bson.dbref.DBRef`                       dbref          both
None                                     undefined      bson -> py
unicode                                  code           bson -> py
`bson.code.Code`                         code           py -> bson
unicode                                  symbol         bson -> py
bytes (Python 3) [#bytes]_               binary         both
=======================================  =============  ===================

Note that to save binary data it must be wrapped as an instance of
`bson.binary.Binary`. Otherwise it will be saved as a BSON string
and retrieved as unicode.

.. [#int] A Python int will be saved as a BSON int32 or BSON int64 depending
   on its size. A BSON int32 will always decode to a Python int. In Python 2.x
   a BSON int64 will always decode to a Python long. In Python 3.x a BSON
   int64 will decode to a Python int since there is no longer a long type.
.. [#dt] datetime.datetime instances will be rounded to the nearest
   millisecond when saved
.. [#dt2] all datetime.datetime instances are treated as *naive*. clients
   should always use UTC.
.. [#re] :class:`~bson.regex.Regex` instances and regular expression
   objects from ``re.compile()`` are both saved as BSON regular expressions.
   BSON regular expressions are decoded as Python regular expressions by
   default, or as :class:`~bson.regex.Regex` instances if the ``compile_re``
   option is set to ``False``.
.. [#bytes] The bytes type from Python 3.x is encoded as BSON binary with
   subtype 0. In Python 3.x it will be decoded back to bytes. In Python 2.x
   it will be decoded to an instance of :class:`~bson.binary.Binary` with
   subtype 0.

Member Function Documentation

def bson.son.SON.__eq__ (   self,
  other 
)
Comparison to another SON is order-sensitive while comparison to a
regular dictionary is order-insensitive.
def bson.son.SON.to_dict (   self)
Convert a SON document to a normal Python dictionary instance.

This is trickier than just *dict(...)* because it needs to be
recursive.

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