Files
Home-AssistantConfig/deps/sqlalchemy/sql/__pycache__/functions.cpython-34.pyc

278 lines
20 KiB
Plaintext
Raw Normal View History

2016-10-11 16:42:06 +00:00
<EFBFBD>
|<7C><>W<EFBFBD>H<00>@s|dZddlmZmZddlmZmZddlmZm Z m
Z
m Z m Z m Z mZmZmZmZmZddlmZmZmZddlmZddlmZdd lmZdd
lmZeje<00>Zd d d <00>ZGdd<00>deee<00>Z Gdd<00>de!<00>Z"e"<00>Z#e"dd<00>Z$Gdd<00>de <00>Z%Gdd<00>de<00>Z&Gdd<00>dej'e&e%<00><00>Z(ede <00>ede
<00>Gdd<00>de(<00>Z)Gdd<00>de(<00>Z*Gd d!<00>d!e(<00>Z+Gd"d#<00>d#e+<00>Z,Gd$d%<00>d%e+<00>Z-Gd&d'<00>d'e+<00>Z.Gd(d)<00>d)e+<00>Z/Gd*d+<00>d+e(<00>Z0Gd,d-<00>d-e(<00>Z1Gd.d/<00>d/e(<00>Z2Gd0d1<00>d1e(<00>Z3Gd2d3<00>d3e(<00>Z4Gd4d5<00>d5e*<00>Z5Gd6d7<00>d7e*<00>Z6Gd8d9<00>d9e*<00>Z7Gd:d;<00>d;e*<00>Z8Gd<d=<00>d=e*<00>Z9Gd>d?<00>d?e*<00>Z:Gd@dA<00>dAe*<00>Z;GdBdC<00>dCe*<00>Z<GdDdE<00>dEe*<00>Z=dFS)Gz6SQL function API, factories, and built-in functions.
<EFBFBD>)<02>sqltypes<65>schema)<02>
Executable<EFBFBD>ColumnCollection) <0B>
ClauseList<EFBFBD>Cast<73>Extract<63>_literal_as_binds<64>literal_column<6D>_type_from_args<67> ColumnElement<6E>_clone<6E>Over<65> BindParameter<65>FunctionFilter)<03>
FromClause<EFBFBD>Select<63>Alias)<01> operators)<01> VisitableType<70>)<01>util)<01>
annotation<EFBFBD>_defaultcCst|}|||<dS)z<>Associate a callable with a particular func. name.
This is normally called by _GenericMeta, but is also
available by itself so that a non-Function construct
can be associated with the :data:`.func` accessor (i.e.
CAST, EXTRACT).
N)<01> _registry)<04>
identifier<EFBFBD>fn<66>package<67>reg<65>r<00>>/tmp/pip-build-zkr322cu/sqlalchemy/sqlalchemy/sql/functions.py<70>register_functions
r!c@s<>eZdZdZfZdd<00>Zdd<00>Zedd<00><00>Ze j
dd <00><00>Z d
d
d d <00>Z d d<00>Z edd<00><00>Zdd<00>Zedd<00>Zd
ddd<00>Zdd<00>Zdd<00>Zdd<00>Zdd<00>Zd
S) <20>FunctionElementa<Base for SQL function-oriented constructs.
.. seealso::
:class:`.Function` - named SQL function.
:data:`.func` - namespace which produces registered or ad-hoc
:class:`.Function` instances.
:class:`.GenericFunction` - allows creation of registered function
types.
csA<00>fdd<00>|D<>}tdtjdd|<00>j<00><00>_dS)z/Construct a :class:`.FunctionElement`.
cs"g|]}t|<00>j<00><00>qSr)r <00>name)<02>.0<EFBFBD>c)<01>selfrr <00>
<listcomp>;s z,FunctionElement.__init__.<locals>.<listcomp><3E>operator<6F>group_contentsTN)rr<00>comma_op<6F>
self_group<EFBFBD> clause_expr)r&<00>clauses<65>kwargs<67>argsr)r&r <00>__init__8szFunctionElement.__init__cCs|j|||<00>S)N)Z_execute_function)r&<00>
connectionZ multiparams<6D>paramsrrr <00>_execute_on_connectionAsz&FunctionElement._execute_on_connectioncCst|jd<00><00>S)a2The set of columns exported by this :class:`.FunctionElement`.
Function objects currently have no result column names built in;
this method returns a single-element column collection with
an anonymously named column.
An interim approach to providing named columns for a function
as a FROM clause is to build a :func:`.select` with the
desired columns::
from sqlalchemy.sql import column
stmt = select([column('x'), column('y')]). select_from(func.myfunction())
N)r<00>label)r&rrr <00>columnsDszFunctionElement.columnscCs
|jjS)z}Return the underlying :class:`.ClauseList` which contains
the arguments for this :class:`.FunctionElement`.
)r,<00>element)r&rrr r-YszFunctionElement.clausesNcCst|d|d|<00>S)a<>Produce an OVER clause against this function.
Used against aggregate or so-called "window" functions,
for database backends that support window functions.
The expression::
func.row_number().over(order_by='x')
is shorthand for::
from sqlalchemy import over
over(func.row_number(), order_by='x')
See :func:`~.expression.over` for a full description.
.. versionadded:: 0.7
<20> partition_by<62>order_by)r)r&r7r8rrr <00>overaszFunctionElement.overcGs|s
|St||<00>S)a<>Produce a FILTER clause against this function.
Used against aggregate and window functions,
for database backends that support the "FILTER" clause.
The expression::
func.count(1).filter(True)
is shorthand for::
from sqlalchemy import funcfilter
funcfilter(func.count(1), True)
.. versionadded:: 1.0.0
.. seealso::
:class:`.FunctionFilter`
:func:`.funcfilter`
)r)r&Z criterionrrr <00>filterwszFunctionElement.filtercCs
|jjS)N)r-<00> _from_objects)r&rrr r;<00>szFunctionElement._from_objectscKs
|jfS)N)r,)r&r.rrr <00> get_children<65>szFunctionElement.get_childrencKs3||j|<00>|_|j<00>tjj|<00>dS)N)r,Z_reset_exportedr"r-Z_reset)r&<00>clone<6E>kwrrr <00>_copy_internals<6C>s
zFunctionElement._copy_internalsFcCs t||<00>S)a_Produce a :class:`.Alias` construct against this
:class:`.FunctionElement`.
This construct wraps the function in a named alias which
is suitable for the FROM clause, in the style accepted for example
by Postgresql.
e.g.::
from sqlalchemy.sql import column
stmt = select([column('data_view')]).\
select_from(SomeTable).\
select_from(func.unnest(SomeTable.data).alias('data_view')
)
Would produce:
.. sourcecode:: sql
SELECT data_view
FROM sometable, unnest(sometable.data) AS data_view
.. versionadded:: 0.9.8 The :meth:`.FunctionElement.alias` method
is now supported. Previously, this method's behavior was
undefined and did not behave consistently across versions.
)r)r&r#Zflatrrr <00>alias<61>szFunctionElement.aliascCs1t|g<00>}|jr-|j|j<00>}n|S)z<>Produce a :func:`~.expression.select` construct
against this :class:`.FunctionElement`.
This is shorthand for::
s = select([function_element])
)rZ_execution_optionsZexecution_options)r&<00>srrr <00>select<63>s  zFunctionElement.selectcCs|j<00>j<00>j<00>S)arExecute this :class:`.FunctionElement` against an embedded
'bind' and return a scalar value.
This first calls :meth:`~.FunctionElement.select` to
produce a SELECT construct.
Note that :class:`.FunctionElement` can be passed to
the :meth:`.Connectable.scalar` method of :class:`.Connection`
or :class:`.Engine`.
)rB<00>execute<74>scalar)r&rrr rD<00>s zFunctionElement.scalarcCs|j<00>j<00>S)aYExecute this :class:`.FunctionElement` against an embedded
'bind'.
This first calls :meth:`~.FunctionElement.select` to
produce a SELECT construct.
Note that :class:`.FunctionElement` can be passed to
the :meth:`.Connectable.execute` method of :class:`.Connection`
or :class:`.Engine`.
)rBrC)r&rrr rC<00>s zFunctionElement.executec Cs"td|d|d|jdd<00>S)N<>_compared_to_operator<6F>_compared_to_type<70>uniqueT)r<00>type)r&r(<00>objrrr <00> _bind_param<61>szFunctionElement._bind_param)<17>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__<5F> packagenamesr0r3<00>propertyr5rZmemoized_propertyr-r9r:r;r<r r?r@rBrDrCrJrrrr r"'s       r"c@s:eZdZdZdd<00>Zdd<00>Zdd<00>ZdS) <09>_FunctionGeneratorz;Generate :class:`.Function` objects based on getattr calls.cKsg|_||_dS)N)<02>_FunctionGenerator__names<65>opts)r&rSrrr r0<00>s z_FunctionGenerator.__init__c Cs<>|jd<00>rBy|j|SWqdtk
r>t|<00><00>YqdXn"|jd<00>rd|dd<00>}nt|j<00>}t|j<00>|g|_|S)N<>__<5F>_<>r<00><><EFBFBD><EFBFBD><EFBFBD>) <09>
startswith<EFBFBD>__dict__<5F>KeyError<6F>AttributeError<6F>endswithrQrS<00>listrR)r&r#<00>frrr <00> __getattr__<5F>s z_FunctionGenerator.__getattr__cOs<>|jj<00>}|j|<00>t|j<00>}|dkrI|j\}}n)|dkrld|jd}}nd}|dk r<>t|j|<00>}|dk r<>|||<00>Snt|jdd|jdd<00>||<00>S)NrrrrVrOrWrW)rS<00>copy<70>update<74>lenrRr<00>get<65>Function)r&r%r.<00>o<>tokensr<00>fname<6D>funcrrr <00>__call__s     z_FunctionGenerator.__call__N)rKrLrMrNr0r_rirrrr rQ<00>s   rQ<00>groupFc@s4eZdZdZdZdd<00>Zdd<00>ZdS)rdaYDescribe a named SQL function.
See the superclass :class:`.FunctionElement` for a description
of public methods.
.. seealso::
:data:`.func` - namespace which produces registered or ad-hoc
:class:`.Function` instances.
:class:`.GenericFunction` - allows creation of registered function
types.
<20>functioncOsn|jdd<00>pg|_||_|jdd<00>|_tj|jdd<00><00>|_tj |||<00>dS)z<>Construct a :class:`.Function`.
The :data:`.func` construct is normally used to construct
new :class:`.Function` instances.
rON<>bind<6E>type_)
<EFBFBD>poprOr#rc<00>_bindr<00> to_instancerHr"r0)r&r#r-r>rrr r0ys
 zFunction.__init__c Cs%t|j|d|d|jdd<00>S)NrErFrGT)rr#rH)r&r(rIrrr rJ<00>s zFunction._bind_paramN)rKrLrMrNZ__visit_name__r0rJrrrr rdgs  rdcs"eZdZ<00>fdd<00>Z<00>S)<03> _GenericMetacs<>tj|jkr<>|jd|<00>|_}|jd|<00>|_}|jdd<00>}d|krr|d|_nt|||<00>nt t
|<00>j |||<00>dS)Nr#rrrZ__return_type__) rZ Annotated<65>__mro__rcr#rrnrHr!<00>superrqr0)<07>clsZclsname<6D>basesZclsdictr#rr)<01> __class__rr r0<00>s z_GenericMeta.__init__)rKrLrMr0rr)rvr rq<00>s rqc@s(eZdZdZdZdd<00>ZdS)<06>GenericFunctionaI
Define a 'generic' function.
A generic function is a pre-established :class:`.Function`
class that is instantiated automatically when called
by name from the :data:`.func` attribute. Note that
calling any name from :data:`.func` has the effect that
a new :class:`.Function` instance is created automatically,
given that name. The primary use case for defining
a :class:`.GenericFunction` class is so that a function
of a particular name may be given a fixed return type.
It can also include custom argument parsing schemes as well
as additional methods.
Subclasses of :class:`.GenericFunction` are automatically
registered under the name of the class. For
example, a user-defined function ``as_utc()`` would
be available immediately::
from sqlalchemy.sql.functions import GenericFunction
from sqlalchemy.types import DateTime
class as_utc(GenericFunction):
type = DateTime
print select([func.as_utc()])
User-defined generic functions can be organized into
packages by specifying the "package" attribute when defining
:class:`.GenericFunction`. Third party libraries
containing many functions may want to use this in order
to avoid name conflicts with other systems. For example,
if our ``as_utc()`` function were part of a package
"time"::
class as_utc(GenericFunction):
type = DateTime
package = "time"
The above function would be available from :data:`.func`
using the package name ``time``::
print select([func.time.as_utc()])
A final option is to allow the function to be accessed
from one name in :data:`.func` but to render as a different name.
The ``identifier`` attribute will override the name used to
access the function as loaded from :data:`.func`, but will retain
the usage of ``name`` as the rendered name::
class GeoBuffer(GenericFunction):
type = Geometry
package = "geo"
name = "ST_Buffer"
identifier = "buffer"
The above function will render as follows::
>>> print func.geo.buffer()
ST_Buffer()
.. versionadded:: 0.8 :class:`.GenericFunction` now supports
automatic registration of new functions as well as package
and custom naming support.
.. versionchanged:: 0.8 The attribute name ``type`` is used
to specify the function's return type at the class level.
Previously, the name ``__return_type__`` was used. This
name is still recognized for backwards-compatibility.
TcOs<>|jdd<00>}|dkr4dd<00>|D<>}ng|_|jdd<00>|_tdtjdd|<00>j<00>|_t j
|jdd<00>p<>t |d d<00><00>|_ dS)
N<EFBFBD> _parsed_argscSsg|]}t|<00><00>qSr)r )r$r%rrr r'<00>s z,GenericFunction.__init__.<locals>.<listcomp>rlr(r)TrmrH) rnrOrcrorrr*r+r,rrp<00>getattrrH)r&r/r.Z parsed_argsrrr r0<00>s  $zGenericFunction.__init__N)rKrLrMrNZcoerce_argumentsr0rrrr rw<00>s Frw<00>cast<73>extractc@sFeZdZdZej<00>ZdZdd<00>Ze dd<00><00>Z
dS)<07>
next_valueaRepresent the 'next value', given a :class:`.Sequence`
as its single argument.
Compiles into the appropriate function on each backend,
or will raise NotImplementedError if used on a backend
that does not provide support for sequences.
cKs@t|tj<00>std<00><00>|jdd<00>|_||_dS)Nz0next_value() accepts a Sequence object as input.rl)<07>
isinstancer<00>Sequence<63>AssertionErrorrcro<00>sequence)r&<00>seqr>rrr r0s znext_value.__init__cCsgS)Nr)r&rrr r;sznext_value._from_objectsN) rKrLrMrNr<00>IntegerrHr#r0rPr;rrrr r|<00>s
  r|c@seZdZdd<00>ZdS)<04> AnsiFunctioncKstj||<00>dS)N)rwr0)r&r.rrr r0 szAnsiFunction.__init__N)rKrLrMr0rrrr r<> s r<>c@s"eZdZdZdd<00>ZdS)<05>ReturnTypeFromArgszADefine a function whose return type is the same as its arguments.cOsJdd<00>|D<>}|jdt|<00><00>||d<tj|||<00>dS)NcSsg|]}t|<00><00>qSr)r )r$r%rrr r's z/ReturnTypeFromArgs.__init__.<locals>.<listcomp>rmrx)<04>
setdefaultr rwr0)r&r/r.rrr r0s
zReturnTypeFromArgs.__init__N)rKrLrMrNr0rrrr r<>s r<>c@seZdZdS)<02>coalesceN)rKrLrMrrrr r<>s r<>c@seZdZdS)<02>maxN)rKrLrMrrrr r<>s r<>c@seZdZdS)<02>minN)rKrLrMrrrr r<>#s r<>c@seZdZdS)<02>sumN)rKrLrMrrrr r<>'s r<>c@seZdZejZdS)<02>nowN)rKrLrMr<00>DateTimerHrrrr r<>+s r<>c@seZdZejZdS)<02>concatN)rKrLrMr<00>StringrHrrrr r<>/s r<>c@s%eZdZejZdd<00>ZdS)<04> char_lengthcKstj|||<00>dS)N)rwr0)r&<00>argr.rrr r06szchar_length.__init__N)rKrLrMrr<>rHr0rrrr r<>3s  r<>c@seZdZdS)<02>randomN)rKrLrMrrrr r<>:s r<>c@s.eZdZdZejZddd<00>ZdS)<05>countzPThe ANSI COUNT aggregate function. With no arguments,
emits COUNT \*.
NcKs2|dkrtd<00>}ntj|||<00>dS)N<>*)r
rwr0)r&Z
expressionr.rrr r0Es zcount.__init__)rKrLrMrNrr<>rHr0rrrr r<>>s  r<>c@seZdZejZdS)<02> current_dateN)rKrLrMrZDaterHrrrr r<>Ks r<>c@seZdZejZdS)<02> current_timeN)rKrLrMrZTimerHrrrr r<>Os r<>c@seZdZejZdS)<02>current_timestampN)rKrLrMrr<>rHrrrr r<>Ss r<>c@seZdZejZdS)<02> current_userN)rKrLrMrr<>rHrrrr r<>Ws r<>c@seZdZejZdS)<02> localtimeN)rKrLrMrr<>rHrrrr r<>[s r<>c@seZdZejZdS)<02>localtimestampN)rKrLrMrr<>rHrrrr r<>_s r<>c@seZdZejZdS)<02> session_userN)rKrLrMrr<>rHrrrr r<>cs r<>c@seZdZejZdS)<02>sysdateN)rKrLrMrr<>rHrrrr r<>gs r<>c@seZdZejZdS)<02>userN)rKrLrMrr<>rHrrrr r<>ks r<>N)>rN<00>rr<00>baserr<00>elementsrrrr r
r r r rrrZ
selectablerrrrZvisitorsrrr<00> defaultdict<63>dictrr!r"<00>objectrQrh<00>modifierrdrq<00>with_metaclassrwr|r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>r<>rrrr <00><module>
sPL <1C>+ J' "V