use property decorator now that we're no longer supporting 2.3

This commit is contained in:
Mike Dirolf 2010-01-27 15:14:47 -05:00
parent fdbded0ec8
commit 08eb76327e
10 changed files with 21 additions and 21 deletions

View File

@ -164,17 +164,17 @@ class GridFile(object):
self.__collection.chunks.remove({"files_id": self.__id})
@property
def closed(self):
"""Is this :class:`GridFile` closed?
"""
return self.__closed
closed = property(closed)
@property
def mode(self):
"""Mode this :class:`GridFile` was opened with.
"""
return self.__mode
mode = property(mode)
def __create_property(field_name, docstring, read_only=False):
def getter(self):

View File

@ -44,11 +44,11 @@ class Binary(str):
self.__subtype = subtype
return self
@property
def subtype(self):
"""Subtype of this binary data.
"""
return self.__subtype
subtype = property(subtype)
def __eq__(self, other):
if isinstance(other, Binary):

View File

@ -45,11 +45,11 @@ class Code(str):
self.__scope = scope
return self
@property
def scope(self):
"""Scope dictionary for this instance.
"""
return self.__scope
scope = property(scope)
def __repr__(self):
return "Code(%s, %r)" % (str.__repr__(self), self.__scope)

View File

@ -118,6 +118,7 @@ class Collection(object):
(other.__database, other.__name))
return NotImplemented
@property
def full_name(self):
"""The full name of this :class:`Collection`.
@ -128,8 +129,8 @@ class Collection(object):
``full_name()`` method is deprecated.
"""
return self.__full_name_w
full_name = property(full_name)
@property
def name(self):
"""The name of this :class:`Collection`.
@ -138,8 +139,8 @@ class Collection(object):
``name()`` method is deprecated.
"""
return self.__name_w
name = property(name)
@property
def database(self):
"""The :class:`~pymongo.database.Database` that this
:class:`Collection` is a part of.
@ -149,7 +150,6 @@ class Collection(object):
``database()`` method is deprecated.
"""
return self.__database_w
database = property(database)
def save(self, to_save, manipulate=True, safe=False):
"""Save a document in this collection.

View File

@ -295,6 +295,7 @@ class Connection(object): # TODO support auth for pooling
if index_name in self.__index_cache[database_name][collection_name]:
del self.__index_cache[database_name][collection_name][index_name]
@property
def host(self):
"""Current connected host.
@ -303,8 +304,8 @@ class Connection(object): # TODO support auth for pooling
method is deprecated.
"""
return helpers.callable_value(self.__host, "Connection.host")
host = property(host)
@property
def port(self):
"""Current connected port.
@ -313,13 +314,12 @@ class Connection(object): # TODO support auth for pooling
method is deprecated.
"""
return helpers.callable_value(self.__port, "Connection.port")
port = property(port)
@property
def slave_okay(self):
"""Is it okay for this connection to connect directly to a slave?
"""
return self.__slave_okay
slave_okay = property(slave_okay)
def __find_master(self):
"""Create a new socket and use it to figure out who the master is.

View File

@ -65,6 +65,7 @@ class Cursor(object):
self.__retrieved = 0
self.__killed = False
@property
def collection(self):
"""The :class:`~pymongo.collection.Collection` that this
:class:`Cursor` is iterating.
@ -72,7 +73,6 @@ class Cursor(object):
.. versionadded:: 1.1
"""
return self.__collection
collection = property(collection)
def __del__(self):
if self.__id and not self.__killed:

View File

@ -99,6 +99,7 @@ class Database(object):
if method_overwritten(manipulator, "transform_outgoing"):
self.__outgoing_manipulators.insert(0, manipulator)
@property
def connection(self):
"""The :class:`~pymongo.connection.Connection` instance for this
:class:`Database`.
@ -108,8 +109,8 @@ class Database(object):
``connection()`` method is deprecated.
"""
return self.__connection_w
connection = property(connection)
@property
def name(self):
"""The name of this :class:`Database`.
@ -118,7 +119,6 @@ class Database(object):
``name()`` method is deprecated.
"""
return self.__name_w
name = property(name)
def __cmp__(self, other):
if isinstance(other, Database):

View File

@ -45,18 +45,19 @@ class DBRef(object):
self.__id = id
self.__database = database
@property
def collection(self):
"""Get the name of this DBRef's collection as unicode.
"""
return self.__collection
collection = property(collection)
@property
def id(self):
"""Get this DBRef's _id.
"""
return self.__id
id = property(id)
@property
def database(self):
"""Get the name of this DBRef's database.
@ -65,7 +66,6 @@ class DBRef(object):
.. versionadded:: 1.1.1
"""
return self.__database
database = property(database)
def as_doc(self):
"""Get the SON document representation of this DBRef.

View File

@ -58,21 +58,21 @@ class MasterSlaveConnection(object):
self.__master = master
self.__slaves = slaves
@property
def master(self):
return self.__master
master = property(master)
@property
def slaves(self):
return self.__slaves
slaves = property(slaves)
@property
def slave_okay(self):
"""Is it okay for this connection to connect directly to a slave?
This is always True for MasterSlaveConnection instances.
"""
return True
slave_okay = property(slave_okay)
def set_cursor_manager(self, manager_class):
"""Set the cursor manager for this connection.

View File

@ -121,12 +121,13 @@ class ObjectId(object):
raise TypeError("id must be an instance of (str, ObjectId), "
"not %s" % type(oid))
@property
def binary(self):
"""12-byte binary representation of this ObjectId.
"""
return self.__id
binary = property(binary)
@property
def generation_time(self):
"""A :class:`datetime.datetime` instance representing the time of
generation for this :class:`ObjectId`.
@ -138,7 +139,6 @@ class ObjectId(object):
"""
t = struct.unpack(">i", self.__id[0:4])[0]
return datetime.datetime.utcfromtimestamp(t)
generation_time = property(generation_time)
def __str__(self):
return self.__id.encode("hex")