403Webshell
Server IP : 192.158.238.246  /  Your IP : 18.188.184.3
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib64/python3.7/site-packages/psycopg2/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib64/python3.7/site-packages/psycopg2/__pycache__/sql.cpython-37.pyc
B

*��]:�@s�dZddlZddlmZddlmZmZe��Z	Gdd�de
�ZGdd�de�ZGd	d
�d
e�Z
Gdd�de�ZGd
d�de�ZGdd�de�Ze
d�Ze
d�ZdS)zSQL composition utility module
�N)�
extensions)�PY3�string_typesc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
Composablea6
    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)�_wrapped)�self�wrapped�r	�?/opt/alt/python37/lib64/python3.7/site-packages/psycopg2/sql.py�__init__1szComposable.__init__cCsd|jj|jfS)Nz%s(%r))�	__class__�__name__r)rr	r	r
�__repr__4szComposable.__repr__cCst�dS)aj
        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)�NotImplementedError)r�contextr	r	r
�	as_string7szComposable.as_stringcCs>t|t�rt|g�|St|t�r6t|g�t|g�StSdS)N)�
isinstance�Composedr�NotImplemented)r�otherr	r	r
�__add__Ds


zComposable.__add__cCst|g|�S)N)r)r�nr	r	r
�__mul__LszComposable.__mul__cCst|�t|�ko|j|jkS)N)�typer)rrr	r	r
�__eq__OszComposable.__eq__cCs|�|�S)N)r)rrr	r	r
�__ne__RszComposable.__ne__N)r
�
__module__�__qualname__�__doc__rrrrrrrr	r	r	r
r#s

rcsLeZdZdZ�fdd�Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
�ZS)ra
    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).
    csFg}x,|D]$}t|t�s$td|��|�|�q
Wtt|��|�dS)Nz4Composed elements must be Composable, got %r instead)rr�	TypeError�append�superrr)r�seqr�i)rr	r
rhs


zComposed.__init__cCs
t|j�S)z+The list of the content of the `!Composed`.)�listr)rr	r	r
r"rszComposed.seqcCs.g}x|jD]}|�|�|��qWd�|�S)N�)rr r�join)rr�rvr#r	r	r
rwszComposed.as_stringcCs
t|j�S)N)�iterr)rr	r	r
�__iter__}szComposed.__iter__cCs<t|t�rt|j|j�St|t�r4t|j|g�StSdS)N)rrrrr)rrr	r	r
r�s


zComposed.__add__cCs0t|t�rt|�}nt|t�s&td��|�|�S)a|
        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"

        z3Composed.join() argument must be a string or an SQL)rr�SQLrr&)rZjoinerr	r	r
r&�s


z
Composed.join)r
rrrr�propertyr"rr)rr&�
__classcell__r	r	)rr
rVs
rcsDeZdZdZ�fdd�Zedd��Zdd�Zdd	�Zd
d�Z	�Z
S)r*aA
    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"
    cs&t|t�std��tt|��|�dS)NzSQL values must be strings)rrrr!r*r)r�string)rr	r
r�s
zSQL.__init__cCs|jS)z(The string wrapped by the `!SQL` object.)r)rr	r	r
r-�sz
SQL.stringcCs|jS)N)r)rrr	r	r
r�sz
SQL.as_stringc	Os�g}d}x�t�|j�D]�\}}}}|r.td��|r:td��|rL|�t|��|dkrVq|��r�|rjtd��|�|t|��d}q|s�|dkr�td��|�||�|d7}q|�||�qWt|�S)a^
        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

        rz(no format specification supported by SQLz%no format conversion supported by SQLNz6cannot switch from automatic field numbering to manualz6cannot switch from manual field numbering to automatic�)	�
_formatter�parser�
ValueErrorr r*�isdigit�intr)	r�args�kwargsr'Zautonum�pre�name�spec�convr	r	r
�format�s2 
z
SQL.formatcCs^g}t|�}y|�t|��Wntk
r2Yn$Xx |D]}|�|�|�|�q:Wt|�S)a
        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(r �next�
StopIterationr)rr"r'�itr#r	r	r
r&s

zSQL.join)r
rrrrr+r-rr:r&r,r	r	)rr
r*�s@r*csHeZdZdZ�fdd�Zedd��Zedd��Zdd	�Zd
d�Z	�Z
S)�
Identifiera*
    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"

    cs@|std��x|D]}t|t�std��qWtt|��|�dS)NzIdentifier cannot be emptyz$SQL identifier parts must be strings)rrrr!r>r)r�strings�s)rr	r
rAs

zIdentifier.__init__cCs|jS)z5A tuple with the strings wrapped by the `Identifier`.)r)rr	r	r
r?KszIdentifier.stringscCs$t|j�dkr|jdStd��dS)z0The string wrapped by the `Identifier`.
        r.rz2the Identifier wraps more than one than one stringN)�lenr�AttributeError)rr	r	r
r-Ps
zIdentifier.stringcCsd|jjd�tt|j��fS)Nz%s(%s)z, )rr
r&�map�reprr)rr	r	r
rZszIdentifier.__repr__csd��fdd�|jD��S)N�.c3s|]}t�|��VqdS)N)�extZquote_ident)�.0r@)rr	r
�	<genexpr>`sz'Identifier.as_string.<locals>.<genexpr>)r&r)rrr	)rr
r_szIdentifier.as_string)r
rrrrr+r?r-rrr,r	r	)rr
r>"s

r>c@s$eZdZdZedd��Zdd�ZdS)�Literala�
    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)z%The object wrapped by the `!Literal`.)r)rr	r	r
rwszLiteral.wrappedcCszt|tj�r|}nt|tj�r&|j}ntd��t�|j�}t|d�rN|�|�|�	�}t
rvt|t�rv|�tj
|j�}|S)Nz(context must be a connection or a cursor�prepare)rrFZ
connectionZcursorrZadaptr�hasattrrJZ	getquotedr�bytes�decode�	encodings�encoding)rrZconn�ar'r	r	r
r|s

zLiteral.as_stringN)r
rrrr+rrr	r	r	r
rIcsrIcs>eZdZdZd�fdd�	Zedd��Zdd�Zd	d
�Z�Z	S)�Placeholdera�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)

    NcsHt|t�r d|kr4td|��n|dk	r4td|��tt|��|�dS)N�)zinvalid name: %rz'expected string or None as name, got %r)rrr1rr!rQr)rr7)rr	r
r�s
zPlaceholder.__init__cCs|jS)zThe name of the `!Placeholder`.)r)rr	r	r
r7�szPlaceholder.namecCsd|jdk	r|jndfS)NzPlaceholder(%r)r%)r)rr	r	r
r�szPlaceholder.__repr__cCs|jdk	rd|jSdSdS)Nz%%(%s)sz%s)r)rrr	r	r
r�s

zPlaceholder.as_string)N)
r
rrrrr+r7rrr,r	r	)rr
rQ�s

rQ�NULL�DEFAULT)rr-�psycopg2rrFZpsycopg2.compatrr�	Formatterr/�objectrrr*r>rIrQrSrTr	r	r	r
�<module>s3IA-6

Youez - 2016 - github.com/yon3zu
LinuXploit