diff options
Diffstat (limited to 'lib/sqlalchemy/ext/proxy.py')
| -rw-r--r-- | lib/sqlalchemy/ext/proxy.py | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/lib/sqlalchemy/ext/proxy.py b/lib/sqlalchemy/ext/proxy.py index c7e707f8d..b81702fc4 100644 --- a/lib/sqlalchemy/ext/proxy.py +++ b/lib/sqlalchemy/ext/proxy.py @@ -10,26 +10,41 @@ __all__ = ['BaseProxyEngine', 'AutoConnectEngine', 'ProxyEngine'] class BaseProxyEngine(sql.Executor): """Basis for all proxy engines.""" - + def get_engine(self): raise NotImplementedError def set_engine(self, engine): raise NotImplementedError - + engine = property(lambda s:s.get_engine(), lambda s,e:s.set_engine(e)) - + def execute_compiled(self, *args, **kwargs): - """this method is required to be present as it overrides the execute_compiled present in sql.Engine""" - return self.get_engine().execute_compiled(*args, **kwargs) - def compiler(self, *args, **kwargs): - """this method is required to be present as it overrides the compiler method present in sql.Engine""" - return self.get_engine().compiler(*args, **kwargs) + """Override superclass behaviour. + + This method is required to be present as it overrides the + `execute_compiled` present in ``sql.Engine``. + """ + + return self.get_engine().execute_compiled(*args, **kwargs) + + def compiler(self, *args, **kwargs): + """Override superclass behaviour. + + This method is required to be present as it overrides the + `compiler` method present in ``sql.Engine``. + """ + + return self.get_engine().compiler(*args, **kwargs) def __getattr__(self, attr): - """provides proxying for methods that are not otherwise present on this BaseProxyEngine. Note - that methods which are present on the base class sql.Engine will *not* be proxied through this, - and must be explicit on this class.""" + """Provide proxying for methods that are not otherwise present on this ``BaseProxyEngine``. + + Note that methods which are present on the base class + ``sql.Engine`` will **not** be proxied through this, and must + be explicit on this class. + """ + # call get_engine() to give subclasses a chance to change # connection establishment behavior e = self.get_engine() @@ -38,16 +53,15 @@ class BaseProxyEngine(sql.Executor): raise AttributeError("No connection established in ProxyEngine: " " no access to %s" % attr) - class AutoConnectEngine(BaseProxyEngine): """An SQLEngine proxy that automatically connects when necessary.""" - + def __init__(self, dburi, **kwargs): BaseProxyEngine.__init__(self) self.dburi = dburi self.kwargs = kwargs self._engine = None - + def get_engine(self): if self._engine is None: if callable(self.dburi): @@ -60,7 +74,7 @@ class AutoConnectEngine(BaseProxyEngine): class ProxyEngine(BaseProxyEngine): """Engine proxy for lazy and late initialization. - + This engine will delegate access to a real engine set with connect(). """ @@ -89,7 +103,7 @@ class ProxyEngine(BaseProxyEngine): except KeyError: map[key] = create_engine(*args, **kwargs) self.storage.engine = map[key] - + def get_engine(self): if not hasattr(self.storage, 'engine') or self.storage.engine is None: raise AttributeError("No connection established") |
