From d0d5f792404126f2f3f62cb850e6b887c246178e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 12 Feb 2010 19:54:49 +0000 Subject: - Made sqlalchemy.sql.expressions.Executable part of public API, used for any expression construct that can be sent to execute(). FunctionElement now inherits Executable so that it gains execution_options(), which are also propagated to the select() that's generated within execute(). Executable in turn subclasses _Generative which marks any ClauseElement that supports the @_generative decorator - these may also become "public" for the benefit of the compiler extension at some point. --- lib/sqlalchemy/sql/expression.py | 54 ++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 1ae706999..0f55ac097 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2208,7 +2208,20 @@ class _TypeClause(ClauseElement): def __init__(self, type): self.type = type -class _Executable(object): + +class _Generative(object): + """Allow a ClauseElement to generate itself via the + @_generative decorator. + + """ + + def _generate(self): + s = self.__class__.__new__(self.__class__) + s.__dict__ = self.__dict__.copy() + return s + + +class Executable(_Generative): """Mark a ClauseElement as supporting execution.""" supports_execution = True @@ -2240,8 +2253,10 @@ class _Executable(object): """ self._execution_options = self._execution_options.union(kw) +# legacy, some outside users may be calling this +_Executable = Executable -class _TextClause(_Executable, ClauseElement): +class _TextClause(Executable, ClauseElement): """Represent a literal SQL text fragment. Public constructor is the :func:`text()` function. @@ -2251,7 +2266,7 @@ class _TextClause(_Executable, ClauseElement): __visit_name__ = 'textclause' _bind_params_regex = re.compile(r'(?