diff --git a/pymongo/__init__.py b/pymongo/__init__.py index 4eff1e1a7..cd5221870 100644 --- a/pymongo/__init__.py +++ b/pymongo/__init__.py @@ -45,6 +45,7 @@ version = "1.6+" Connection = PyMongo_Connection """Alias for :class:`pymongo.connection.Connection`.""" + def has_c(): """Is the C extension installed? diff --git a/pymongo/binary.py b/pymongo/binary.py index c70b950ef..d014f6bc7 100644 --- a/pymongo/binary.py +++ b/pymongo/binary.py @@ -50,6 +50,7 @@ USER_DEFINED_SUBTYPE = 128 .. versionadded:: 1.5 """ + class Binary(str): """Representation of binary data to be stored in or retrieved from MongoDB. diff --git a/pymongo/bson.py b/pymongo/bson.py index de04e4ab4..40cccb5cf 100644 --- a/pymongo/bson.py +++ b/pymongo/bson.py @@ -195,17 +195,17 @@ _element_getter = { "\x03": _get_object, "\x04": _get_array, "\x05": _get_binary, - "\x06": _get_null, # undefined + "\x06": _get_null, # undefined "\x07": _get_oid, "\x08": _get_boolean, "\x09": _get_date, "\x0A": _get_null, "\x0B": _get_regex, "\x0C": _get_ref, - "\x0D": _get_string, # code - "\x0E": _get_string, # symbol + "\x0D": _get_string, # code + "\x0E": _get_string, # symbol "\x0F": _get_code_w_scope, - "\x10": _get_int, # number_int + "\x10": _get_int, # number_int "\x11": _get_timestamp, "\x12": _get_long, "\xFF": lambda x, y: (MinKey(), x), @@ -297,9 +297,9 @@ def _element_to_bson(key, value, check_keys): return "\x08" + name + "\x00" if isinstance(value, (int, long)): # TODO this is a really ugly way to check for this... - if value > 2**64 / 2 - 1 or value < -2**64 / 2: + if value > 2 ** 64 / 2 - 1 or value < -2 ** 64 / 2: raise OverflowError("MongoDB can only handle up to 8-byte ints") - if value > 2**32 / 2 - 1 or value < -2**32 / 2: + if value > 2 ** 32 / 2 - 1 or value < -2 ** 32 / 2: return "\x12" + name + struct.pack(" 4 * 1024 * 1024: - raise InvalidDocument("document too large - BSON documents are limited " - "to 4 MB") + raise InvalidDocument("document too large - BSON documents are" + "limited to 4 MB") return struct.pack("