diff --git a/README.rst b/README.rst index 81ddef40b..f144fb782 100644 --- a/README.rst +++ b/README.rst @@ -47,7 +47,7 @@ ObjectId('\x03\x1c\x06\x8d|\x9d}O\x8b\xaf!\xa0'))]) 10 8 11 ->>> from pymongo.database import ASCENDING +>>> from pymongo import ASCENDING >>> db.my_collection.create_index("x", ASCENDING) >>> for item in db.my_collection.find().sort("x", ASCENDING): ... print item["x"] diff --git a/pymongo/__init__.py b/pymongo/__init__.py index e69de29bb..dd46d2b16 100644 --- a/pymongo/__init__.py +++ b/pymongo/__init__.py @@ -0,0 +1,28 @@ +# Copyright 2009 10gen, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""A Mongo driver for Python.""" + +ASCENDING = 1 +"""Ascending sort order.""" +DESCENDING = -1 +"""Descending sort order.""" + +OFF = 0 +"""Turn off database profiling.""" +SLOW_ONLY = 1 +"""Only profile slow operations.""" +ALL = 2 +"""Profile all operations.""" + diff --git a/pymongo/collection.py b/pymongo/collection.py index 3b27fdd39..e81ce0149 100644 --- a/pymongo/collection.py +++ b/pymongo/collection.py @@ -270,8 +270,8 @@ class Collection(object): Takes either a single key and a direction, or a list of (key, direction) pairs. The key(s) must be an instance of (str, unicode), and the - direction(s) must be one of (Mongo.ASCENDING, Mongo.DESCENDING). Returns - the name of the created index. + direction(s) must be one of (`pymongo.ASCENDING`, `pymongo.DESCENDING`). + Returns the name of the created index. :Parameters: - `key_or_list`: a single key or a list of (key, direction) pairs @@ -298,7 +298,7 @@ class Collection(object): if not isinstance(key, types.StringTypes): raise TypeError("first item in each key pair must be a string") if not isinstance(value, types.IntType): - raise TypeError("second item in each key pair must be Mongo.ASCENDING or Mongo.DESCENDING") + raise TypeError("second item in each key pair must be ASCENDING or DESCENDING") key_object[key] = value to_save["key"] = key_object diff --git a/pymongo/cursor.py b/pymongo/cursor.py index fc8acb9df..a94fef6d6 100644 --- a/pymongo/cursor.py +++ b/pymongo/cursor.py @@ -129,9 +129,9 @@ class Cursor(object): Takes either a single key and a direction, or a list of (key, direction) pairs. The key(s) must be an instance of (str, unicode), and the - direction(s) must be one of (Mongo.ASCENDING, Mongo.DESCENDING). Raises - InvalidOperation if this cursor has already been used. Only the last - `sort` applied to this cursor has any effect. + direction(s) must be one of (`pymongo.ASCENDING`, `pymongo.DESCENDING`). + Raises InvalidOperation if this cursor has already been used. Only the + last `sort` applied to this cursor has any effect. :Parameters: - `key_or_list`: a single key or a list of (key, direction) pairs diff --git a/pymongo/database.py b/pymongo/database.py index 4a537ce06..908cdfc0f 100644 --- a/pymongo/database.py +++ b/pymongo/database.py @@ -24,15 +24,6 @@ from collection import Collection from errors import InvalidName, CollectionInvalid, OperationFailure from code import Code -# sort directions -ASCENDING = 1 -DESCENDING = -1 - -# profiling levels -OFF = 0 -SLOW_ONLY = 1 -ALL = 2 - class Database(object): """A Mongo database. """ @@ -220,7 +211,7 @@ class Database(object): def profiling_level(self): """Get the database's current profiling level. - Returns one of (OFF, SLOW_ONLY, ALL). + Returns one of (`pymongo.OFF`, `pymongo.SLOW_ONLY`, `pymongo.ALL`). """ result = self._command({"profile": -1}) @@ -230,7 +221,8 @@ class Database(object): def set_profiling_level(self, level): """Set the database's profiling level. - Raises ValueError if level is not one of (OFF, SLOW_ONLY, ALL). + Raises ValueError if level is not one of (`pymongo.OFF`, + pymongo.SLOW_ONLY`, `pymongo.ALL`). :Parameters: - `level`: the profiling level to use diff --git a/pymongo/mongo.py b/pymongo/mongo.py index 229721d2d..218fe4911 100644 --- a/pymongo/mongo.py +++ b/pymongo/mongo.py @@ -29,9 +29,6 @@ from objectid import ObjectId from dbref import DBRef from cursor_manager import BatchCursorManager -ASCENDING = database.ASCENDING -DESCENDING = database.DESCENDING - class Mongo(database.Database): """A connection to a Mongo database. """ diff --git a/test/test_collection.py b/test/test_collection.py index 7d8a4abd9..6265317d5 100644 --- a/test/test_collection.py +++ b/test/test_collection.py @@ -23,7 +23,7 @@ from test_connection import get_connection from pymongo.objectid import ObjectId from pymongo.collection import Collection from pymongo.errors import InvalidName -from pymongo.database import ASCENDING, DESCENDING +from pymongo import ASCENDING, DESCENDING from pymongo.son import SON class TestCollection(unittest.TestCase): diff --git a/test/test_cursor.py b/test/test_cursor.py index 836bfc219..2306cee4c 100644 --- a/test/test_cursor.py +++ b/test/test_cursor.py @@ -21,7 +21,8 @@ sys.path[0:0] = [""] from pymongo.errors import InvalidOperation from pymongo.cursor import Cursor -from pymongo.database import Database, ASCENDING, DESCENDING +from pymongo.database import Database +from pymongo import ASCENDING, DESCENDING from test_connection import get_connection class TestCursor(unittest.TestCase): diff --git a/test/test_database.py b/test/test_database.py index 6cb909937..02aa2e34b 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -24,7 +24,8 @@ sys.path[0:0] = [""] from pymongo.errors import InvalidName, InvalidOperation, CollectionInvalid, OperationFailure from pymongo.son import SON from pymongo.objectid import ObjectId -from pymongo.database import Database, ASCENDING, DESCENDING, OFF, SLOW_ONLY, ALL +from pymongo.database import Database +from pymongo import ASCENDING, DESCENDING, OFF, SLOW_ONLY, ALL from pymongo.connection import Connection from pymongo.collection import Collection from pymongo.dbref import DBRef diff --git a/test/test_mongo.py b/test/test_mongo.py index 63149cc0e..6d2f85396 100644 --- a/test/test_mongo.py +++ b/test/test_mongo.py @@ -25,7 +25,8 @@ from pymongo.objectid import ObjectId from pymongo.dbref import DBRef from pymongo.son import SON from pymongo.errors import InvalidOperation, ConnectionFailure -from pymongo.mongo import Mongo, ASCENDING, DESCENDING +from pymongo.mongo import Mongo +from pymongo import ASCENDING, DESCENDING class TestMongo(unittest.TestCase): def setUp(self):