From: Mike Bayer Date: Sat, 3 Sep 2005 00:41:41 +0000 (+0000) Subject: (no commit message) X-Git-Tag: rel_0_1_0~820 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca82e0f5d98532ab9ec4624f79edec492cc23597;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git --- diff --git a/lib/sqlalchemy/engine.py b/lib/sqlalchemy/engine.py index db1191a9bc..758f805bcf 100644 --- a/lib/sqlalchemy/engine.py +++ b/lib/sqlalchemy/engine.py @@ -126,7 +126,6 @@ class SQLEngine(schema.SchemaEngine): self.rollback() raise self.commit() - def begin(self): if getattr(self.context, 'transaction', None) is None: diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py index 2eda7a1cbf..ea6befba8f 100644 --- a/lib/sqlalchemy/util.py +++ b/lib/sqlalchemy/util.py @@ -16,7 +16,7 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. __ALL__ = ['OrderedProperties', 'OrderedDict'] -import thread +import thread, weakref class OrderedProperties(object): @@ -119,4 +119,41 @@ class Set(object): del self.map[key] def __getitem__(self, key): - return self.map[key] \ No newline at end of file + return self.map[key] + + +class ScopedRegistry(object): + def __init__(self, createfunc): + self.createfunc = createfunc + self.application = createfunc() + self.threadlocal = {} + self.scopes = { + 'application' : {'call' : self._call_application, 'clear' : self._clear_application}, + 'thread' : {'call' : self._call_thread, 'clear':self._clear_thread} + } + + def __call__(self, scope): + return self.scopes[scope]['call']() + + def clear(self, scope): + return self.scopes[scope]['clear']() + + def _call_thread(self): + try: + return self.threadlocal[thread.get_ident()] + except KeyError: + return self.threadlocal.setdefault(thread.get_ident(), self.createfunc()) + + def _clear_thread(self): + try: + del self.threadlocal[thread.get_ident()] + except KeyError: + pass + + def _call_application(self): + return self.application + + def _clear_application(self): + self.application = createfunc() + + \ No newline at end of file