move constants to pymongo root. update docs. add documentation for the pymongo module itself.
This commit is contained in:
parent
ee3cefc8e8
commit
e0fa517744
@ -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"]
|
||||
|
||||
@ -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."""
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
"""
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user