summaryrefslogtreecommitdiff
path: root/sqlplain/connection.py
diff options
context:
space:
mode:
authormichele.simionato <devnull@localhost>2008-12-18 13:35:47 +0000
committermichele.simionato <devnull@localhost>2008-12-18 13:35:47 +0000
commit705cf00911474cd3ca798490d605ee8b0e0e4b19 (patch)
tree11b7cd6659888f4cd7b7a8a8fef10bf93a273915 /sqlplain/connection.py
parent2d48e27a1be6ed61732f6428431b2e5d87fa38bf (diff)
downloadmicheles-705cf00911474cd3ca798490d605ee8b0e0e4b19.tar.gz
Refactored sqlplain.table by introducing connmethod
Diffstat (limited to 'sqlplain/connection.py')
-rw-r--r--sqlplain/connection.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/sqlplain/connection.py b/sqlplain/connection.py
index 85687b3..e5b7904 100644
--- a/sqlplain/connection.py
+++ b/sqlplain/connection.py
@@ -279,3 +279,20 @@ class FakeConnection(object):
return self
def __exit_(self, exctype, exc, tb):
pass
+
+class connmethod(object):
+ """
+ A descriptor for methods which first argument is a (lazy) connection.
+ Used to decorate methods of classes with a .conn attribute.
+ """
+ def __init__(self, func):
+ self._func = func
+ self.__name__ = func.__name__
+ #self.__doc__ = func.__doc__
+ #self.__dict__ = func.__dict__
+ #self.__module__ = func.__module__
+ def __get__(self, obj, objcls):
+ if obj is None: # called from the class
+ return self._func
+ else: # called from the instance
+ return self._func.__get__(obj.conn, objcls)