|
14 | 14 |
|
15 | 15 | """Collection level utilities for Mongo.""" |
16 | 16 |
|
17 | | -import types |
18 | 17 | import warnings |
19 | 18 | import struct |
20 | 19 |
|
@@ -48,10 +47,10 @@ def __init__(self, database, name, options=None): |
48 | 47 | - `options`: dictionary of collection options. |
49 | 48 | see `pymongo.database.Database.create_collection` for details. |
50 | 49 | """ |
51 | | - if not isinstance(name, types.StringTypes): |
| 50 | + if not isinstance(name, basestring): |
52 | 51 | raise TypeError("name must be an instance of (str, unicode)") |
53 | 52 |
|
54 | | - if not isinstance(options, (types.DictType, types.NoneType)): |
| 53 | + if options is not None and not isinstance(options, dict): |
55 | 54 | raise TypeError("options must be an instance of dict") |
56 | 55 |
|
57 | 56 | if not name or ".." in name: |
@@ -168,7 +167,7 @@ def save(self, to_save, manipulate=True, safe=False): |
168 | 167 | - `manipulate` (optional): manipulate the SON object before saving it |
169 | 168 | - `safe` (optional): check that the save succeeded? |
170 | 169 | """ |
171 | | - if not isinstance(to_save, types.DictType): |
| 170 | + if not isinstance(to_save, dict): |
172 | 171 | raise TypeError("cannot save object of type %s" % type(to_save)) |
173 | 172 |
|
174 | 173 | if "_id" not in to_save: |
@@ -201,7 +200,7 @@ def insert(self, doc_or_docs, |
201 | 200 | Bulk insert works with any iterable |
202 | 201 | """ |
203 | 202 | docs = doc_or_docs |
204 | | - if isinstance(docs, types.DictType): |
| 203 | + if isinstance(docs, dict): |
205 | 204 | docs = [docs] |
206 | 205 |
|
207 | 206 | if manipulate: |
@@ -263,11 +262,11 @@ def update(self, spec, document, |
263 | 262 |
|
264 | 263 | .. _update modifiers: http://www.mongodb.org/display/DOCS/Updating |
265 | 264 | """ |
266 | | - if not isinstance(spec, types.DictType): |
| 265 | + if not isinstance(spec, dict): |
267 | 266 | raise TypeError("spec must be an instance of dict") |
268 | | - if not isinstance(document, types.DictType): |
| 267 | + if not isinstance(document, dict): |
269 | 268 | raise TypeError("document must be an instance of dict") |
270 | | - if not isinstance(upsert, types.BooleanType): |
| 269 | + if not isinstance(upsert, bool): |
271 | 270 | raise TypeError("upsert must be an instance of bool") |
272 | 271 |
|
273 | 272 | if upsert and manipulate: |
@@ -322,7 +321,7 @@ def remove(self, spec_or_object_id=None, safe=False): |
322 | 321 | if isinstance(spec, ObjectId): |
323 | 322 | spec = {"_id": spec} |
324 | 323 |
|
325 | | - if not isinstance(spec, types.DictType): |
| 324 | + if not isinstance(spec, dict): |
326 | 325 | raise TypeError("spec must be an instance of dict, not %s" % |
327 | 326 | type(spec)) |
328 | 327 |
|
@@ -366,7 +365,7 @@ def _fields_list_to_dict(self, fields): |
366 | 365 | """ |
367 | 366 | as_dict = {} |
368 | 367 | for field in fields: |
369 | | - if not isinstance(field, types.StringTypes): |
| 368 | + if not isinstance(field, basestring): |
370 | 369 | raise TypeError("fields must be a list of key names as " |
371 | 370 | "(string, unicode)") |
372 | 371 | as_dict[field] = 1 |
@@ -425,19 +424,19 @@ def find(self, spec=None, fields=None, skip=0, limit=0, |
425 | 424 |
|
426 | 425 | slave_okay = self.__database.connection.slave_okay |
427 | 426 |
|
428 | | - if not isinstance(spec, types.DictType): |
| 427 | + if not isinstance(spec, dict): |
429 | 428 | raise TypeError("spec must be an instance of dict") |
430 | | - if not isinstance(fields, (types.ListType, types.NoneType)): |
| 429 | + if fields is not None and not isinstance(fields, list): |
431 | 430 | raise TypeError("fields must be an instance of list") |
432 | | - if not isinstance(skip, types.IntType): |
| 431 | + if not isinstance(skip, int): |
433 | 432 | raise TypeError("skip must be an instance of int") |
434 | | - if not isinstance(limit, types.IntType): |
| 433 | + if not isinstance(limit, int): |
435 | 434 | raise TypeError("limit must be an instance of int") |
436 | | - if not isinstance(timeout, types.BooleanType): |
| 435 | + if not isinstance(timeout, bool): |
437 | 436 | raise TypeError("timeout must be an instance of bool") |
438 | | - if not isinstance(snapshot, types.BooleanType): |
| 437 | + if not isinstance(snapshot, bool): |
439 | 438 | raise TypeError("snapshot must be an instance of bool") |
440 | | - if not isinstance(tailable, types.BooleanType): |
| 439 | + if not isinstance(tailable, bool): |
441 | 440 | raise TypeError("tailable must be an instance of bool") |
442 | 441 |
|
443 | 442 | if fields is not None: |
@@ -565,10 +564,10 @@ def drop_index(self, index_or_name): |
565 | 564 | - `index_or_name`: index (or name of index) to drop |
566 | 565 | """ |
567 | 566 | name = index_or_name |
568 | | - if isinstance(index_or_name, types.ListType): |
| 567 | + if isinstance(index_or_name, list): |
569 | 568 | name = self._gen_index_name(index_or_name) |
570 | 569 |
|
571 | | - if not isinstance(name, types.StringTypes): |
| 570 | + if not isinstance(name, basestring): |
572 | 571 | raise TypeError("index_or_name must be an index name or list") |
573 | 572 |
|
574 | 573 | self.__database.connection._purge_index(self.__database.name, |
@@ -674,7 +673,7 @@ def rename(self, new_name): |
674 | 673 | :Parameters: |
675 | 674 | - `new_name`: new name for this collection |
676 | 675 | """ |
677 | | - if not isinstance(new_name, types.StringTypes): |
| 676 | + if not isinstance(new_name, basestring): |
678 | 677 | raise TypeError("new_name must be an instance of (str, unicode)") |
679 | 678 |
|
680 | 679 | if not new_name or ".." in new_name: |
|
0 commit comments