Skip to content

Commit 69a8792

Browse files
jbergstroemMike Dirolf
authored andcommitted
PEP8 fixes (only .py for now)
Signed-off-by: Mike Dirolf <[email protected]>
1 parent 359fbd8 commit 69a8792

File tree

15 files changed

+68
-49
lines changed

15 files changed

+68
-49
lines changed

pymongo/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
Connection = PyMongo_Connection
4646
"""Alias for :class:`pymongo.connection.Connection`."""
4747

48+
4849
def has_c():
4950
"""Is the C extension installed?
5051

pymongo/binary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
.. versionadded:: 1.5
5151
"""
5252

53+
5354
class Binary(str):
5455
"""Representation of binary data to be stored in or retrieved from MongoDB.
5556

pymongo/bson.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ def _get_long(data, as_class):
195195
"\x03": _get_object,
196196
"\x04": _get_array,
197197
"\x05": _get_binary,
198-
"\x06": _get_null, # undefined
198+
"\x06": _get_null, # undefined
199199
"\x07": _get_oid,
200200
"\x08": _get_boolean,
201201
"\x09": _get_date,
202202
"\x0A": _get_null,
203203
"\x0B": _get_regex,
204204
"\x0C": _get_ref,
205-
"\x0D": _get_string, # code
206-
"\x0E": _get_string, # symbol
205+
"\x0D": _get_string, # code
206+
"\x0E": _get_string, # symbol
207207
"\x0F": _get_code_w_scope,
208-
"\x10": _get_int, # number_int
208+
"\x10": _get_int, # number_int
209209
"\x11": _get_timestamp,
210210
"\x12": _get_long,
211211
"\xFF": lambda x, y: (MinKey(), x),
@@ -297,9 +297,9 @@ def _element_to_bson(key, value, check_keys):
297297
return "\x08" + name + "\x00"
298298
if isinstance(value, (int, long)):
299299
# TODO this is a really ugly way to check for this...
300-
if value > 2**64 / 2 - 1 or value < -2**64 / 2:
300+
if value > 2 ** 64 / 2 - 1 or value < -2 ** 64 / 2:
301301
raise OverflowError("MongoDB can only handle up to 8-byte ints")
302-
if value > 2**32 / 2 - 1 or value < -2**32 / 2:
302+
if value > 2 ** 32 / 2 - 1 or value < -2 ** 32 / 2:
303303
return "\x12" + name + struct.pack("<q", value)
304304
return "\x10" + name + struct.pack("<i", value)
305305
if isinstance(value, datetime.datetime):
@@ -355,8 +355,8 @@ def _dict_to_bson(dict, check_keys, top_level=True):
355355

356356
length = len(elements) + 5
357357
if length > 4 * 1024 * 1024:
358-
raise InvalidDocument("document too large - BSON documents are limited "
359-
"to 4 MB")
358+
raise InvalidDocument("document too large - BSON documents are"
359+
"limited to 4 MB")
360360
return struct.pack("<i", length) + elements + "\x00"
361361
if _use_c:
362362
_dict_to_bson = _cbson._dict_to_bson

pymongo/code.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Tools for representing JavaScript code to be evaluated by MongoDB.
1616
"""
1717

18+
1819
class Code(str):
1920
"""JavaScript code to be evaluated by MongoDB.
2021

pymongo/collection.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ def count(self):
481481
"""
482482
return self.find().count()
483483

484-
def create_index(self, key_or_list, deprecated_unique=None, ttl=300, **kwargs):
484+
def create_index(self, key_or_list, deprecated_unique=None,
485+
ttl=300, **kwargs):
485486
"""Creates an index on this collection.
486487
487488
Takes either a single key or a list of (key, direction) pairs.
@@ -564,7 +565,8 @@ def create_index(self, key_or_list, deprecated_unique=None, ttl=300, **kwargs):
564565
check_keys=False)
565566
return name
566567

567-
def ensure_index(self, key_or_list, deprecated_unique=None, ttl=300, **kwargs):
568+
def ensure_index(self, key_or_list, deprecated_unique=None,
569+
ttl=300, **kwargs):
568570
"""Ensures that an index exists on this collection.
569571
570572
Takes either a single key or a list of (key, direction) pairs.
@@ -631,7 +633,8 @@ def ensure_index(self, key_or_list, deprecated_unique=None, ttl=300, **kwargs):
631633

632634
if self.__database.connection._cache_index(self.__database.name,
633635
self.__name, name, ttl):
634-
return self.create_index(key_or_list, deprecated_unique, ttl, **kwargs)
636+
return self.create_index(key_or_list, deprecated_unique,
637+
ttl, **kwargs)
635638
return None
636639

637640
def drop_indexes(self):

pymongo/connection.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def return_socket(self):
9494
self.sock = None
9595

9696

97-
class Connection(object): # TODO support auth for pooling
97+
class Connection(object): # TODO support auth for pooling
9898
"""Connection to MongoDB.
9999
"""
100100

@@ -189,7 +189,8 @@ def __partition(source, sub):
189189
i = source.find(sub)
190190
if i == -1:
191191
return (source, None)
192-
return (source[:i], source[i+len(sub):])
192+
193+
return (source[:i], source[i + len(sub):])
193194

194195
@staticmethod
195196
def _parse_uri(uri):
@@ -198,7 +199,8 @@ def _parse_uri(uri):
198199
if uri.startswith("mongodb://"):
199200
uri = uri[len("mongodb://"):]
200201
elif "://" in uri:
201-
raise InvalidURI("Invalid uri scheme: %s" % Connection.__partition(uri, "://")[0])
202+
raise InvalidURI("Invalid uri scheme: %s"
203+
% Connection.__partition(uri, "://")[0])
202204

203205
(hosts, database) = Connection.__partition(uri, "/")
204206

@@ -211,7 +213,8 @@ def _parse_uri(uri):
211213
(auth, hosts) = Connection.__partition(hosts, "@")
212214

213215
if ":" not in auth:
214-
raise InvalidURI("auth must be specified as 'username:password@'")
216+
raise InvalidURI("auth must be specified as "
217+
"'username:password@'")
215218
(username, password) = Connection.__partition(auth, ":")
216219

217220
host_list = []
@@ -441,7 +444,7 @@ def __find_master(self):
441444
self.__port = port
442445
return
443446
except socket.error, e:
444-
sock_error=True
447+
sock_error = True
445448
finally:
446449
if sock is not None:
447450
sock.close()
@@ -499,9 +502,10 @@ def set_cursor_manager(self, manager_class):
499502
"""Set this connection's cursor manager.
500503
501504
Raises :class:`TypeError` if `manager_class` is not a subclass of
502-
:class:`~pymongo.cursor_manager.CursorManager`. A cursor manager handles
503-
closing cursors. Different managers can implement different policies in
504-
terms of when to actually kill a cursor that has been closed.
505+
:class:`~pymongo.cursor_manager.CursorManager`. A cursor manager
506+
handles closing cursors. Different managers can implement different
507+
policies in terms of when to actually kill a cursor that has
508+
been closed.
505509
506510
:Parameters:
507511
- `manager_class`: cursor manager to use
@@ -562,7 +566,8 @@ def _send_message(self, message, with_last_error=False):
562566
# lastError) and raise OperationFailure if it is an error
563567
# response.
564568
if with_last_error:
565-
response = self.__receive_message_on_socket(1, request_id, sock)
569+
response = self.__receive_message_on_socket(1, request_id,
570+
sock)
566571
return self.__check_response_to_last_error(response)
567572
return None
568573
except (ConnectionFailure, socket.error), e:

pymongo/cursor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"tailable_cursor": 2,
2626
"slave_okay": 4,
2727
"oplog_replay": 8,
28-
"no_timeout": 16
29-
}
28+
"no_timeout": 16}
3029

3130

3231
# TODO might be cool to be able to do find().include("foo") or
@@ -263,13 +262,15 @@ def __getitem__(self, index):
263262
skip = 0
264263
if index.start is not None:
265264
if index.start < 0:
266-
raise IndexError("Cursor instances do not support negative indices")
265+
raise IndexError("Cursor instances do not support"
266+
"negative indices")
267267
skip = index.start
268268

269269
if index.stop is not None:
270270
limit = index.stop - skip
271271
if limit <= 0:
272-
raise IndexError("stop index must be greater than start index for slice %r" % index)
272+
raise IndexError("stop index must be greater than start"
273+
"index for slice %r" % index)
273274
else:
274275
limit = 0
275276

@@ -279,14 +280,16 @@ def __getitem__(self, index):
279280

280281
if isinstance(index, (int, long)):
281282
if index < 0:
282-
raise IndexError("Cursor instances do not support negative indices")
283+
raise IndexError("Cursor instances do not support negative"
284+
"indices")
283285
clone = self.clone()
284286
clone.skip(index + self.__skip)
285-
clone.limit(-1) # use a hard limit
287+
clone.limit(-1) # use a hard limit
286288
for doc in clone:
287289
return doc
288290
raise IndexError("no such item for Cursor instance")
289-
raise TypeError("index %r cannot be applied to Cursor instances" % index)
291+
raise TypeError("index %r cannot be applied to Cursor "
292+
"instances" % index)
290293

291294
def max_scan(self, max_scan):
292295
"""Limit the number of documents to scan when performing the query.

pymongo/database.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def add_son_manipulator(self, manipulator):
8282
- `manipulator`: the manipulator to add
8383
"""
8484
def method_overwritten(instance, method):
85-
return getattr(instance, method) != getattr(super(instance.__class__, instance), method)
86-
85+
return getattr(instance, method) != \
86+
getattr(super(instance.__class__, instance), method)
8787

8888
if manipulator.will_copy():
8989
if method_overwritten(manipulator, "transform_incoming"):
@@ -440,9 +440,10 @@ def add_user(self, name, password):
440440
441441
.. versionadded:: 1.4
442442
"""
443+
pwd = helpers._password_digest(name, password)
443444
self.system.users.update({"user": name},
444445
{"user": name,
445-
"pwd": helpers._password_digest(name, password)},
446+
"pwd": pwd},
446447
upsert=True, safe=True)
447448

448449
def remove_user(self, name):
@@ -509,7 +510,8 @@ def authenticate(self, name, password):
509510
nonce = self.command("getnonce")["nonce"]
510511
key = helpers._auth_key(nonce, name, password)
511512
try:
512-
self.command("authenticate", user=unicode(name), nonce=nonce, key=key)
513+
self.command("authenticate", user=unicode(name),
514+
nonce=nonce, key=key)
513515
return True
514516
except OperationFailure:
515517
return False
@@ -525,9 +527,9 @@ def dereference(self, dbref):
525527
"""Dereference a DBRef, getting the SON object it points to.
526528
527529
Raises TypeError if `dbref` is not an instance of DBRef. Returns a SON
528-
object or None if the reference does not point to a valid object. Raises
529-
ValueError if `dbref` has a database specified that is different from
530-
the current database.
530+
object or None if the reference does not point to a valid object.
531+
Raises ValueError if `dbref` has a database specified that is different
532+
from the current database.
531533
532534
:Parameters:
533535
- `dbref`: the reference

pymongo/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"""Exceptions raised by PyMongo."""
1616

17+
1718
class PyMongoError(Exception):
1819
"""Base class for all PyMongo exceptions.
1920

pymongo/helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Little bits and pieces used by the driver that don't really fit elsewhere."""
15+
"""Bits and pieces used by the driver that don't really fit elsewhere."""
1616

1717
try:
1818
import hashlib
1919
_md5func = hashlib.md5
20-
except: # for Python < 2.5
20+
except: # for Python < 2.5
2121
import md5
2222
_md5func = md5.new
2323
import struct
@@ -28,6 +28,7 @@
2828
AutoReconnect)
2929
from pymongo.son import SON
3030

31+
3132
def _index_list(key_or_list, direction=None):
3233
"""Helper to generate a list of (key, direction) pairs.
3334

0 commit comments

Comments
 (0)