diff --git a/gridfs/__init__.py b/gridfs/__init__.py index 4a4ccde6b..dbec83ff9 100644 --- a/gridfs/__init__.py +++ b/gridfs/__init__.py @@ -28,6 +28,7 @@ from pymongo import (ASCENDING, DESCENDING) from pymongo.database import Database + class GridFS(object): """An instance of GridFS on top of a single Database. """ diff --git a/gridfs/errors.py b/gridfs/errors.py index 0c1c94146..8c787bae2 100644 --- a/gridfs/errors.py +++ b/gridfs/errors.py @@ -35,12 +35,14 @@ class NoFile(GridFSError): .. versionadded:: 1.6 """ + class FileExists(GridFSError): """Raised when trying to create a file that already exists. .. versionadded:: 1.7 """ + class UnsupportedAPI(GridFSError): """Raised when trying to use the old GridFS API. diff --git a/gridfs/grid_file.py b/gridfs/grid_file.py index ffcd71ec3..f2a7649cd 100644 --- a/gridfs/grid_file.py +++ b/gridfs/grid_file.py @@ -36,7 +36,8 @@ try: _SEEK_SET = os.SEEK_SET _SEEK_CUR = os.SEEK_CUR _SEEK_END = os.SEEK_END -except AttributeError: # before 2.5 +# before 2.5 +except AttributeError: _SEEK_SET = 0 _SEEK_CUR = 1 _SEEK_END = 2 @@ -55,6 +56,7 @@ def _create_property(field_name, docstring, raise AttributeError("can only get %r on a closed file" % field_name) return self._file.get(field_name, None) + def setter(self, value): if self._closed: raise AttributeError("cannot set %r on a closed file" % @@ -112,7 +114,8 @@ class GridIn(object): - `**kwargs` (optional): file level options (see above) """ if not isinstance(root_collection, Collection): - raise TypeError("root_collection must be an instance of Collection") + raise TypeError("root_collection must be an " + "instance of Collection") # Handle alternative naming if "content_type" in kwargs: @@ -124,7 +127,8 @@ class GridIn(object): kwargs["_id"] = kwargs.get("_id", ObjectId()) kwargs["chunkSize"] = kwargs.get("chunkSize", DEFAULT_CHUNK_SIZE) - root_collection.chunks.ensure_index([("files_id", ASCENDING), ("n", ASCENDING)], + root_collection.chunks.ensure_index([("files_id", ASCENDING), + ("n", ASCENDING)], unique=True) object.__setattr__(self, "_coll", root_collection) object.__setattr__(self, "_chunks", root_collection.chunks) @@ -204,7 +208,6 @@ class GridIn(object): except DuplicateKeyError: raise FileExists("file with _id %r already exists" % self._id) - def close(self): """Flush the file and close it. @@ -236,7 +239,8 @@ class GridIn(object): if self._closed: raise ValueError("cannot write to a closed file") - try: # file-like + # file-like + try: if self._buffer.tell() > 0: space = self.chunk_size - self._buffer.tell() self._buffer.write(data.read(space)) @@ -246,7 +250,8 @@ class GridIn(object): self.__flush_data(to_write) to_write = data.read(self.chunk_size) self._buffer.write(to_write) - except AttributeError: # string + # string + except AttributeError: if not isinstance(data, str): raise TypeError("can only write strings or file-like objects") @@ -280,7 +285,9 @@ class GridIn(object): Close the file and allow exceptions to propogate. """ self.close() - return False # propogate exceptions + + # propogate exceptions + return False class GridOut(object): @@ -301,7 +308,8 @@ class GridOut(object): - `file_id`: value of ``"_id"`` for the file to read """ if not isinstance(root_collection, Collection): - raise TypeError("root_collection must be an instance of Collection") + raise TypeError("root_collection must be an " + "instance of Collection") self.__chunks = root_collection.chunks self._file = root_collection.files.find_one({"_id": file_id}) diff --git a/pymongo/binary.py b/pymongo/binary.py index b31ef20f6..5f25e73ca 100644 --- a/pymongo/binary.py +++ b/pymongo/binary.py @@ -18,7 +18,8 @@ BINARY_SUBTYPE = 0 """BSON binary subtype for binary data. -This is becomming the default subtype and should be the most commonly used. +This is becomming the default subtype and should be the most commonly +used. .. versionadded:: 1.5 """ @@ -32,7 +33,8 @@ FUNCTION_SUBTYPE = 1 OLD_BINARY_SUBTYPE = 2 """Old BSON binary subtype for binary data. -This is still the default subtype, but that is changing to :data:`BINARY_SUBTYPE`. +This is still the default subtype, but that is changing to +:data:`BINARY_SUBTYPE`. .. versionadded:: 1.7 """ diff --git a/pymongo/bson.py b/pymongo/bson.py index edc94a530..caddc88f1 100644 --- a/pymongo/bson.py +++ b/pymongo/bson.py @@ -212,8 +212,7 @@ _element_getter = { "\x11": _get_timestamp, "\x12": _get_long, "\xFF": lambda x, y, z: (MinKey(), x), - "\x7F": lambda x, y, z: (MaxKey(), x) -} + "\x7F": lambda x, y, z: (MaxKey(), x)} def _element_to_dict(data, as_class, tz_aware): diff --git a/pymongo/collection.py b/pymongo/collection.py index e428daab3..fc6983651 100644 --- a/pymongo/collection.py +++ b/pymongo/collection.py @@ -274,7 +274,7 @@ class Collection(object): instance specifying the document to be used for the update or (in the case of an upsert) insert - see docs on MongoDB `update modifiers`_ - - `upsert` (optional): perform an `upsert`_ if ``True`` + - `upsert` (optional): perform an upsert if ``True`` - `manipulate` (optional): manipulate the document before updating? If ``True`` all instances of :mod:`~pymongo.son_manipulator.SONManipulator` added to @@ -294,7 +294,6 @@ class Collection(object): The `multi` parameter. .. _update modifiers: http://www.mongodb.org/display/DOCS/Updating - .. _upsert: http://www.mongodb.org/display/DOCS/Updating#Updating-Upserts .. mongodoc:: update """ @@ -434,8 +433,7 @@ class Collection(object): result set - `fields` (optional): a list of field names that should be returned in the result set ("_id" will always be - included), or a dict specifying the `fields to return - `_ + included), or a dict specifying the fields to return - `skip` (optional): the number of documents to omit (from the start of the result set) when returning the results - `limit` (optional): the maximum number of results to @@ -450,7 +448,7 @@ class Collection(object): returned, or objects missed, which were present at both the start and end of the query's execution. For details, see the `snapshot documentation - `_. + `_. - `tailable` (optional): the result of this find call will be a tailable cursor - tailable cursors aren't closed when the last data is retrieved but are kept open and the @@ -514,8 +512,8 @@ class Collection(object): >>> my_collection.create_index("mike") - For a `compound index`_ on ``'mike'`` descending and - ``'eliot'`` ascending we need to use a list of tuples: + For a compound index on ``'mike'`` descending and ``'eliot'`` + ascending we need to use a list of tuples: >>> my_collection.create_index([("mike", pymongo.DESCENDING), ... ("eliot", pymongo.ASCENDING)]) @@ -553,8 +551,6 @@ class Collection(object): .. seealso:: :meth:`ensure_index` - .. _compound index: http://www.mongodb.org/display/DOCS/Indexes#Indexes-CompoundKeysIndexes - .. mongodoc:: indexes """ keys = helpers._index_list(key_or_list) diff --git a/pymongo/connection.py b/pymongo/connection.py index 38b75f0bb..8bacc65a1 100644 --- a/pymongo/connection.py +++ b/pymongo/connection.py @@ -266,7 +266,6 @@ class Connection(object): # TODO support auth for pooling warnings.warn("The timeout parameter to Connection is deprecated", DeprecationWarning) - self.__host = None self.__port = None @@ -459,7 +458,9 @@ class Connection(object): # TODO support auth for pooling primary = self.__try_node(first) if primary is True: return first - if self.__slave_okay and primary is not None: # no network error + + # no network error + if self.__slave_okay and primary is not None: return first # Wasn't the first node, but we got a primary - let's try it: diff --git a/pymongo/cursor.py b/pymongo/cursor.py index ed218ac7b..8c88cea5d 100644 --- a/pymongo/cursor.py +++ b/pymongo/cursor.py @@ -490,7 +490,8 @@ class Cursor(object): try: response = helpers._unpack_response(response, self.__id, - self.__as_class, self.__tz_aware) + self.__as_class, + self.__tz_aware) except AutoReconnect: db.connection.disconnect() raise diff --git a/pymongo/database.py b/pymongo/database.py index 18e8e249d..dc0efaf20 100644 --- a/pymongo/database.py +++ b/pymongo/database.py @@ -586,7 +586,7 @@ class SystemJS(object): manual instantiation of this class should not be necessary. :class:`SystemJS` instances allow for easy manipulation and - access to `server-side JavaScript`_: + access to server-side JavaScript: .. doctest:: @@ -602,8 +602,6 @@ class SystemJS(object): .. note:: Requires server version **>= 1.1.1** .. versionadded:: 1.5 - - .. _server-side JavaScript: http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Storingfunctionsserverside """ # can't just assign it since we've overridden __setattr__ object.__setattr__(self, "_database", database) diff --git a/pymongo/dbref.py b/pymongo/dbref.py index 07d9ebb60..da202b9c4 100644 --- a/pymongo/dbref.py +++ b/pymongo/dbref.py @@ -93,16 +93,19 @@ class DBRef(object): return doc def __repr__(self): - extra = "".join([", %s=%r" % (k,v) for k,v in self.__kwargs.iteritems()]) + extra = "".join([", %s=%r" % (k, v) + for k, v in self.__kwargs.iteritems()]) if self.database is None: return "DBRef(%r, %r%s)" % (self.collection, self.id, extra) - return "DBRef(%r, %r, %r%s)" % (self.collection, self.id, self.database, - extra) + return "DBRef(%r, %r, %r%s)" % (self.collection, self.id, + self.database, extra) def __cmp__(self, other): if isinstance(other, DBRef): - return cmp([self.__database, self.__collection, self.__id, self.__kwargs], - [other.__database, other.__collection, other.__id, other.__kwargs]) + return cmp([self.__database, self.__collection, + self.__id, self.__kwargs], + [other.__database, other.__collection, + other.__id, other.__kwargs]) return NotImplemented def __hash__(self): @@ -110,4 +113,5 @@ class DBRef(object): .. versionadded:: 1.1 """ - return hash((self.__collection, self.__id, self.__database, self.__kwargs)) + return hash((self.__collection, self.__id, + self.__database, self.__kwargs)) diff --git a/pymongo/master_slave_connection.py b/pymongo/master_slave_connection.py index bbf5da4ba..61a238007 100644 --- a/pymongo/master_slave_connection.py +++ b/pymongo/master_slave_connection.py @@ -130,8 +130,9 @@ class MasterSlaveConnection(object): """ if _connection_to_use is not None: if _connection_to_use == -1: - return (-1, self.__master._send_message_with_response(message, - **kwargs)) + return (-1, + self.__master._send_message_with_response(message, + **kwargs)) else: return (_connection_to_use, self.__slaves[_connection_to_use] diff --git a/pymongo/max_key.py b/pymongo/max_key.py index a245133da..fe28fc3a7 100644 --- a/pymongo/max_key.py +++ b/pymongo/max_key.py @@ -15,6 +15,7 @@ """Representation for the MongoDB internal MaxKey type. """ + class MaxKey(object): """MongoDB internal MaxKey type. """ diff --git a/pymongo/min_key.py b/pymongo/min_key.py index 88d71dec3..225b30e50 100644 --- a/pymongo/min_key.py +++ b/pymongo/min_key.py @@ -15,6 +15,7 @@ """Representation for the MongoDB internal MinKey type. """ + class MinKey(object): """MongoDB internal MinKey type. """