diff options
author | Jason Pellerin <jpellerin@gmail.com> | 2006-02-05 14:43:10 +0000 |
---|---|---|
committer | Jason Pellerin <jpellerin@gmail.com> | 2006-02-05 14:43:10 +0000 |
commit | 6f11c56230784d523c8eb04632080c037ed0e5c1 (patch) | |
tree | dd05fcea9fe2bd51c12095fc1dcf9421744bf0b1 /lib/sqlalchemy/ext/proxy.py | |
parent | 1d20ecbb6d0f0f8cfbb0a54e2a3aaf6cead23ecb (diff) | |
download | sqlalchemy-6f11c56230784d523c8eb04632080c037ed0e5c1.tar.gz |
Provisional fix for #51, very slightly adapted from the patch posted in the ticket. Tests added to verify fix.
Diffstat (limited to 'lib/sqlalchemy/ext/proxy.py')
-rw-r--r-- | lib/sqlalchemy/ext/proxy.py | 70 |
1 files changed, 31 insertions, 39 deletions
diff --git a/lib/sqlalchemy/ext/proxy.py b/lib/sqlalchemy/ext/proxy.py index ae5f40cfa..6139164bf 100644 --- a/lib/sqlalchemy/ext/proxy.py +++ b/lib/sqlalchemy/ext/proxy.py @@ -57,7 +57,9 @@ class ProxyEngine(object): # something for oid column name, and the call happens too early # to proxy, so effecticely no oids are allowed when using # proxy engine - return None + if self.storage.engine is None: + return None + return self.get_engine().oid_column_name() def columnimpl(self, column): """Proxy point: return a ProxyColumnImpl @@ -100,47 +102,37 @@ class ProxyTableImpl(sql.TableImpl): engine = property(lambda self: self._engine.engine) -class ProxyTypeEngine(object): - """Proxy type engine; defers engine access to ProxyEngine +class ProxyType(object): + """ProxyType base class; used by ProxyTypeEngine to construct proxying + types """ def __init__(self, engine, typeobj): self._engine = engine self.typeobj = typeobj - - engine = property(lambda self: self._engine.engine) - - def __getattr__(self, attr): - # NOTE: - # profiling so far indicates that caching the type_descriptor - # results is more trouble than it's worth - return getattr(self.engine.type_descriptor(self.typeobj), attr) - - - - - - - - - - - - - - - - - - - - - - - - - - - - + def __getattribute__(self, attr): + if attr.startswith('__') and attr.endswith('__'): + return object.__getattribute__(self, attr) + + engine = object.__getattribute__(self, '_engine').engine + typeobj = object.__getattribute__(self, 'typeobj') + return getattr(engine.type_descriptor(typeobj), attr) + def __repr__(self): + return '<Proxy %s>' % (object.__getattribute__(self, 'typeobj')) + +class ProxyTypeEngine(object): + """Proxy type engine; creates dynamic proxy type subclass that is instance + of actual type, but proxies engine-dependant operations through the proxy + engine. + """ + def __new__(cls, engine, typeobj): + """Create a new subclass of ProxyType and typeobj + so that internal isinstance() calls will get the expected result. + """ + if isinstance(typeobj, type): + typeclass = typeobj + else: + typeclass = typeobj.__class__ + typed = type('ProxyTypeHelper', (ProxyType, typeclass), {}) + return typed(engine, typeobj) |