diff options
author | michele.simionato <devnull@localhost> | 2008-12-12 10:14:49 +0000 |
---|---|---|
committer | michele.simionato <devnull@localhost> | 2008-12-12 10:14:49 +0000 |
commit | 3da5c4db6d8def6bf51c16d7df42614311faebc0 (patch) | |
tree | a4c8fc0a30035e6b9c8e3abb84ee07fab0c1ca2f /sqlplain | |
parent | 80bf8764d75e332f51fba758beb8ec494bcabd8e (diff) | |
download | micheles-3da5c4db6d8def6bf51c16d7df42614311faebc0.tar.gz |
Changed the documentation of the decorator module and improved the source code management
Diffstat (limited to 'sqlplain')
-rw-r--r-- | sqlplain/connection.py | 18 | ||||
-rw-r--r-- | sqlplain/doc/doc.py | 18 | ||||
-rw-r--r-- | sqlplain/sql_support.py | 6 |
3 files changed, 30 insertions, 12 deletions
diff --git a/sqlplain/connection.py b/sqlplain/connection.py index 2bb4bc0..5e6fae5 100644 --- a/sqlplain/connection.py +++ b/sqlplain/connection.py @@ -249,10 +249,22 @@ class NullObject(object): def __call__(self, *a, **k): return None -class FakeConn(object): +class FakeConnection(object): def __init__(self, iodict): self.iodict = iodict - self.conn = NullObject() - self.curs = NullObject() + self._conn = NullObject() + self._curs = NullObject() def execute(self, templ, args=()): return self.iodict[(templ,) + args] + def executescript(self, templ, *dicts, **kw): + pass + def commit(self): + pass + def rollback(self): + pass + def close(self): + pass + def __enter__(self): + return self + def __exit_(self, exctype, exc, tb): + pass diff --git a/sqlplain/doc/doc.py b/sqlplain/doc/doc.py index fb79e2b..e04b44d 100644 --- a/sqlplain/doc/doc.py +++ b/sqlplain/doc/doc.py @@ -235,11 +235,13 @@ uri is parsed and the correct database driver is loaded, otherwise a ``NameError`` is raised. If the configuration file is missing, an ``ImportError`` is raised. -Lazy connections can be used as global variables -(do not believe people saying that globals are evil: Python is full of -globals, modules are global variables, classes are global variables, and -there is nothing wrong in having lazy connection as globals). If -you instantiate your lazy connections at the beginning +Lazy connections can be used as global variables. + +.. (do not believe people saying that globals are evil: Python is full of + globals, modules are global variables, classes are global variables, and + there is nothing wrong in having lazy connection as globals) + +If you instantiate your lazy connections at the beginning of your module, then the underlying low level database driver is imported when your module is imported. If you follow this pattern, then, the configuration file is part of your application and @@ -266,12 +268,14 @@ A typical way to pass the URI is to read it from the command line: This works if ``sys.argv[1]`` is a valid URI or a valid alias. However, if you are writing functional tests and you invoke them -with (say) nose, you cannot use this pattern since ``sys.argv[1]`` -is the test file. When writing nose tests it makes sense to +with (say) nose_, you cannot use this pattern since ``sys.argv[1]`` +is the name of the file to be tested. When writing nose tests it makes sense to use a global lazy connection, instantiated at the top of your testing script, something like ``testdb = lazyconnect('testdb')`` where ``testdb`` is an alias to the database used for your automatic tests. +.. _nose: http://somethingaboutorange.com/mrl/projects/nose/ + Transactions -------------------------------------------------------------- diff --git a/sqlplain/sql_support.py b/sqlplain/sql_support.py index bdf5196..c4e884a 100644 --- a/sqlplain/sql_support.py +++ b/sqlplain/sql_support.py @@ -1,4 +1,4 @@ -import re +import re, inspect from decorator import FunctionMaker STRING_OR_COMMENT = re.compile(r"('[^']*'|--.*\n)") @@ -53,5 +53,7 @@ def do(templ, name='sqlquery', args=None, defaults=None, doc=None, return conn.execute(templ, %(args)s scalar=scalar)''' % locals() fun = FunctionMaker(name=name, signature=args, defaults=defaults, doc=doc or templ) - return fun.make(src, templ=templ, scalar=scalar) + comment = '\n# scalar = %s\n# templ=\n%s\n' % (scalar, '\n'.join( + '## ' + line for line in templ.splitlines())) + return fun.make(src, dict(templ=templ, scalar=scalar), addsource=comment) |