%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/
Upload File :
Create Path :
Current File : //opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyc

�
�ac@s�dZddlZddlmZddlmZmZej�Z	de
fd��YZdefd��YZd	efd
��YZ
defd��YZd
efd��YZdefd��YZe
d�Ze
d�ZdS(sSQL composition utility module
i����N(t
extensions(tPY3tstring_typest
ComposablecBsMeZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	RS(s6
    Abstract base class for objects that can be used to compose an SQL string.

    `!Composable` objects can be passed directly to `~cursor.execute()`,
    `~cursor.executemany()`, `~cursor.copy_expert()` in place of the query
    string.

    `!Composable` objects can be joined using the ``+`` operator: the result
    will be a `Composed` instance containing the objects joined. The operator
    ``*`` is also supported with an integer argument: the result is a
    `!Composed` instance containing the left argument repeated as many times as
    requested.
    cCs
||_dS(N(t_wrapped(tselftwrapped((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyt__init__1scCsd|jj|jfS(Ns%s(%r)(t	__class__t__name__R(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyt__repr__4scCs
t�dS(sj
        Return the string value of the object.

        :param context: the context to evaluate the string into.
        :type context: `connection` or `cursor`

        The method is automatically invoked by `~cursor.execute()`,
        `~cursor.executemany()`, `~cursor.copy_expert()` if a `!Composable` is
        passed instead of the query string.
        N(tNotImplementedError(Rtcontext((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyt	as_string7scCsQt|t�r t|g�|St|t�rIt|g�t|g�StSdS(N(t
isinstancetComposedRtNotImplemented(Rtother((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyt__add__Ds
cCst|g|�S(N(R(Rtn((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyt__mul__LscCs(t|�t|�ko'|j|jkS(N(ttypeR(RR((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyt__eq__OscCs|j|�S(N(R(RR((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyt__ne__Rs(
R	t
__module__t__doc__RR
R
RRRR(((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR#s
			
			RcBsJeZdZd�Zed��Zd�Zd�Zd�Zd�Z	RS(s
    A `Composable` object made of a sequence of `!Composable`.

    The object is usually created using `!Composable` operators and methods.
    However it is possible to create a `!Composed` directly specifying a
    sequence of `!Composable` as arguments.

    Example::

        >>> comp = sql.Composed(
        ...     [sql.SQL("insert into "), sql.Identifier("table")])
        >>> print(comp.as_string(conn))
        insert into "table"

    `!Composed` objects are iterable (so they can be used in `SQL.join` for
    instance).
    cCs`g}x=|D]5}t|t�s5td|��n|j|�q
Wtt|�j|�dS(Ns4Composed elements must be Composable, got %r instead(RRt	TypeErrortappendtsuperRR(RtseqRti((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyRhs
cCs
t|j�S(s+The list of the content of the `!Composed`.(tlistR(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyRrscCs=g}x'|jD]}|j|j|��qWdj|�S(Nt(RRR
tjoin(RRtrvR((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR
wscCs
t|j�S(N(titerR(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyt__iter__}scCsNt|t�r#t|j|j�St|t�rFt|j|g�StSdS(N(RRRRR(RR((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR�s
cCsIt|t�rt|�}nt|t�s<td��n|j|�S(s|
        Return a new `!Composed` interposing the *joiner* with the `!Composed` items.

        The *joiner* must be a `SQL` or a string which will be interpreted as
        an `SQL`.

        Example::

            >>> fields = sql.Identifier('foo') + sql.Identifier('bar')  # a Composed
            >>> print(fields.join(', ').as_string(conn))
            "foo", "bar"

        s3Composed.join() argument must be a string or an SQL(RRtSQLRR!(Rtjoiner((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR!�s(
R	RRRtpropertyRR
R$RR!(((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyRVs	
			R%cBsAeZdZd�Zed��Zd�Zd�Zd�ZRS(sA
    A `Composable` representing a snippet of SQL statement.

    `!SQL` exposes `join()` and `format()` methods useful to create a template
    where to merge variable parts of a query (for instance field or table
    names).

    The *string* doesn't undergo any form of escaping, so it is not suitable to
    represent variable identifiers or values: you should only use it to pass
    constant strings representing templates or snippets of SQL statements; use
    other objects such as `Identifier` or `Literal` to represent variable
    parts.

    Example::

        >>> query = sql.SQL("select {0} from {1}").format(
        ...    sql.SQL(', ').join([sql.Identifier('foo'), sql.Identifier('bar')]),
        ...    sql.Identifier('table'))
        >>> print(query.as_string(conn))
        select "foo", "bar" from "table"
    cCs8t|t�std��ntt|�j|�dS(NsSQL values must be strings(RRRRR%R(Rtstring((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR�scCs|jS(s(The string wrapped by the `!SQL` object.(R(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR(�scCs|jS(N(R(RR((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR
�sc	Os(g}d}xtj|j�D]�\}}}}|rFtd��n|r[td��n|rw|jt|��n|dkr�qn|j�r�|r�td��n|j|t|��d}q|s	|dkr�td��n|j||�|d7}q|j||�qWt	|�S(s^
        Merge `Composable` objects into a template.

        :param `Composable` args: parameters to replace to numbered
            (``{0}``, ``{1}``) or auto-numbered (``{}``) placeholders
        :param `Composable` kwargs: parameters to replace to named (``{name}``)
            placeholders
        :return: the union of the `!SQL` string with placeholders replaced
        :rtype: `Composed`

        The method is similar to the Python `str.format()` method: the string
        template supports auto-numbered (``{}``), numbered (``{0}``,
        ``{1}``...), and named placeholders (``{name}``), with positional
        arguments replacing the numbered placeholders and keywords replacing
        the named ones. However placeholder modifiers (``{0!r}``, ``{0:<10}``)
        are not supported. Only `!Composable` objects can be passed to the
        template.

        Example::

            >>> print(sql.SQL("select * from {} where {} = %s")
            ...     .format(sql.Identifier('people'), sql.Identifier('id'))
            ...     .as_string(conn))
            select * from "people" where "id" = %s

            >>> print(sql.SQL("select * from {tbl} where {pkey} = %s")
            ...     .format(tbl=sql.Identifier('people'), pkey=sql.Identifier('id'))
            ...     .as_string(conn))
            select * from "people" where "id" = %s

        is(no format specification supported by SQLs%no format conversion supported by SQLs6cannot switch from automatic field numbering to manuals6cannot switch from manual field numbering to automaticiN(
t
_formattertparseRt
ValueErrorRR%tNonetisdigittintR(	RtargstkwargsR"tautonumtpretnametspectconv((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pytformat�s2 %	
cCsrg}t|�}y|jt|��Wntk
r<n,Xx(|D] }|j|�|j|�qDWt|�S(s
        Join a sequence of `Composable`.

        :param seq: the elements to join.
        :type seq: iterable of `!Composable`

        Use the `!SQL` object's *string* to separate the elements in *seq*.
        Note that `Composed` objects are iterable too, so they can be used as
        argument for this method.

        Example::

            >>> snip = sql.SQL(', ').join(
            ...     sql.Identifier(n) for n in ['foo', 'bar', 'baz'])
            >>> print(snip.as_string(conn))
            "foo", "bar", "baz"
        (R#Rtnextt
StopIterationR(RRR"titR((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR!s


(	R	RRRR'R(R
R6R!(((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR%�s			@t
IdentifiercBsGeZdZd�Zed��Zed��Zd�Zd�ZRS(s*
    A `Composable` representing an SQL identifier or a dot-separated sequence.

    Identifiers usually represent names of database objects, such as tables or
    fields. PostgreSQL identifiers follow `different rules`__ than SQL string
    literals for escaping (e.g. they use double quotes instead of single).

    .. __: https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#         SQL-SYNTAX-IDENTIFIERS

    Example::

        >>> t1 = sql.Identifier("foo")
        >>> t2 = sql.Identifier("ba'r")
        >>> t3 = sql.Identifier('ba"z')
        >>> print(sql.SQL(', ').join([t1, t2, t3]).as_string(conn))
        "foo", "ba'r", "ba""z"

    Multiple strings can be passed to the object to represent a qualified name,
    i.e. a dot-separated sequence of identifiers.

    Example::

        >>> query = sql.SQL("select {} from {}").format(
        ...     sql.Identifier("table", "field"),
        ...     sql.Identifier("schema", "table"))
        >>> print(query.as_string(conn))
        select "table"."field" from "schema"."table"

    cGs^|std��nx,|D]$}t|t�std��qqWtt|�j|�dS(NsIdentifier cannot be emptys$SQL identifier parts must be strings(RRRRR:R(Rtstringsts((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyRAs
cCs|jS(s5A tuple with the strings wrapped by the `Identifier`.(R(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR;KscCs0t|j�dkr |jdStd��dS(s0The string wrapped by the `Identifier`.
        iis2the Identifier wraps more than one than one stringN(tlenRtAttributeError(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR(PscCs)d|jjdjtt|j��fS(Ns%s(%s)s, (RR	R!tmaptreprR(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR
Zs	cs dj�fd�|jD��S(Nt.c3s!|]}tj|��VqdS(N(texttquote_ident(t.0R<(R(sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pys	<genexpr>`s(R!R(RR((RsC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR
_s(	R	RRRR'R;R(R
R
(((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR:"s	

	tLiteralcBs&eZdZed��Zd�ZRS(s�
    A `Composable` representing an SQL value to include in a query.

    Usually you will want to include placeholders in the query and pass values
    as `~cursor.execute()` arguments. If however you really really need to
    include a literal value in the query you can use this object.

    The string returned by `!as_string()` follows the normal :ref:`adaptation
    rules <python-types-adaptation>` for Python objects.

    Example::

        >>> s1 = sql.Literal("foo")
        >>> s2 = sql.Literal("ba'r")
        >>> s3 = sql.Literal(42)
        >>> print(sql.SQL(', ').join([s1, s2, s3]).as_string(conn))
        'foo', 'ba''r', 42

    cCs|jS(s%The object wrapped by the `!Literal`.(R(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyRwscCs�t|tj�r|}n*t|tj�r9|j}ntd��tj|j�}t|d�rv|j|�n|j	�}t
r�t|t�r�|jtj
|j�}n|S(Ns(context must be a connection or a cursortprepare(RRBt
connectiontcursorRtadaptRthasattrRFt	getquotedRtbytestdecodet	encodingstencoding(RRtconntaR"((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR
|s	(R	RRR'RR
(((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyREcstPlaceholdercBs;eZdZdd�Zed��Zd�Zd�ZRS(s�A `Composable` representing a placeholder for query parameters.

    If the name is specified, generate a named placeholder (e.g. ``%(name)s``),
    otherwise generate a positional placeholder (e.g. ``%s``).

    The object is useful to generate SQL queries with a variable number of
    arguments.

    Examples::

        >>> names = ['foo', 'bar', 'baz']

        >>> q1 = sql.SQL("insert into table ({}) values ({})").format(
        ...     sql.SQL(', ').join(map(sql.Identifier, names)),
        ...     sql.SQL(', ').join(sql.Placeholder() * len(names)))
        >>> print(q1.as_string(conn))
        insert into table ("foo", "bar", "baz") values (%s, %s, %s)

        >>> q2 = sql.SQL("insert into table ({}) values ({})").format(
        ...     sql.SQL(', ').join(map(sql.Identifier, names)),
        ...     sql.SQL(', ').join(map(sql.Placeholder, names)))
        >>> print(q2.as_string(conn))
        insert into table ("foo", "bar", "baz") values (%(foo)s, %(bar)s, %(baz)s)

    cCsjt|t�r1d|krPtd|��qPn|dk	rPtd|��ntt|�j|�dS(Nt)sinvalid name: %rs'expected string or None as name, got %r(RRR+R,RRRRR(RR3((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR�scCs|jS(sThe name of the `!Placeholder`.(R(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR3�scCs#d|jdk	r|jndfS(NsPlaceholder(%r)R (RR,(R((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR
�scCs"|jdk	rd|jSdSdS(Ns%%(%s)ss%s(RR,(RR((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyR
�sN(	R	RRR,RR'R3R
R
(((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyRR�s

	tNULLtDEFAULT(RR(tpsycopg2RRBtpsycopg2.compatRRt	FormatterR)tobjectRRR%R:RERRRTRU(((sC/opt/plesk/python/2.7/lib64/python2.7/site-packages/psycopg2/sql.pyt<module>s3I�A-6

Zerion Mini Shell 1.0