Ë
    é#0h»9  ã                   óà   — d Z ddlZddlmZ  ej
                  «       Z G d„ d«      Z G d„ de«      Z G d„ d	e«      Z	 G d
„ de«      Z
 G d„ de«      Z G d„ de«      Z e	d«      Z e	d«      Zy)zSQL composition utility module
é    N)Ú
extensionsc                   ó:   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
y	)
Ú
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.
    c                 ó   — || _         y ©N©Ú_wrapped)ÚselfÚwrappeds     úJ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/psycopg2/sql.pyÚ__init__zComposable.__init__1   s	   € Øˆ�ó    c                 óN   — | j                   j                  › d| j                  ›d�S )Nú(ú))Ú	__class__Ú__name__r	   ©r
   s    r   Ú__repr__zComposable.__repr__4   s%   € Ø—.‘.×)Ñ)Ð*¨!¨D¯M©MÐ+<¸AÐ>Ð>r   c                 ó   — t         ‚)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.
        )ÚNotImplementedError©r
   Úcontexts     r   Ú	as_stringzComposable.as_string7   s
   € ô "Ð!r   c                 óž   — t        |t        «      rt        | g«      |z   S t        |t        «      rt        | g«      t        |g«      z   S t        S r   )Ú
isinstanceÚComposedr   ÚNotImplemented©r
   Úothers     r   Ú__add__zComposable.__add__D   sG   € Ü�eœXÔ&Ü˜T˜FÓ# eÑ+Ð+Ü�eœZÔ(Ü˜T˜FÓ#¤h°¨wÓ&7Ñ7Ð7ä!Ð!r   c                 ó    — t        | g|z  «      S r   )r   )r
   Úns     r   Ú__mul__zComposable.__mul__L   s   € Ü˜˜ ™
Ó#Ð#r   c                 ód   — t        | «      t        |«      u xr | j                  |j                  k(  S r   )Útyper	   r   s     r   Ú__eq__zComposable.__eq__O   s'   € Ü�D‹zœT %›[Ð(ÒL¨T¯]©]¸e¿n¹nÑ-LÐLr   c                 ó&   — | j                  |«       S r   )r'   r   s     r   Ú__ne__zComposable.__ne__R   s   € Ø—;‘;˜uÓ%Ð%Ð%r   N)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r!   r$   r'   r)   © r   r   r   r   #   s+   „ ñò ò?ò"ò"ò$òMó&r   r   c                   óJ   ‡ — e Zd ZdZˆ fd„Zed„ «       Zd„ Zd„ Zd„ Z	d„ Z
ˆ xZS )r   a  
    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).
    c                 ó–   •— g }|D ]2  }t        |t        «      st        d|›d�«      ‚|j                  |«       Œ4 t        ‰| �  |«       y )Nz*Composed elements must be Composable, got z instead)r   r   Ú	TypeErrorÚappendÚsuperr   )r
   Úseqr   Úir   s       €r   r   zComposed.__init__h   sW   ø€ ØˆØò 	ˆAÜ˜a¤Ô,ÜØ@ÀÀÀXÐNóPð Pà�N‰N˜1Õð		ô 	‰Ñ˜Õ!r   c                 ó,   — t        | j                  «      S )z+The list of the content of the `!Composed`.)Úlistr	   r   s    r   r3   zComposed.seqr   s   € ô �D—M‘MÓ"Ð"r   c                 óŠ   — g }| j                   D ]"  }|j                  |j                  |«      «       Œ$ dj                  |«      S )NÚ )r	   r1   r   Újoin)r
   r   Úrvr4   s       r   r   zComposed.as_stringw   s=   € ØˆØ—‘ò 	,ˆAØ�I‰I�a—k‘k 'Ó*Õ+ð	,à�w‰w�r‹{Ðr   c                 ó,   — t        | j                  «      S r   )Úiterr	   r   s    r   Ú__iter__zComposed.__iter__}   s   € Ü�D—M‘MÓ"Ð"r   c                 óÄ   — t        |t        «      r"t        | j                  |j                  z   «      S t        |t        «      rt        | j                  |gz   «      S t        S r   )r   r   r	   r   r   r   s     r   r!   zComposed.__add__€   sJ   € Ü�eœXÔ&Ü˜DŸM™M¨E¯N©NÑ:Ó;Ð;Ü�eœZÔ(Ü˜DŸM™M¨U¨GÑ3Ó4Ð4ä!Ð!r   c                 ó’   — t        |t        «      rt        |«      }nt        |t        «      st        d«      ‚|j	                  | «      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)r   ÚstrÚSQLr0   r9   )r
   Újoiners     r   r9   zComposed.joinˆ   sD   € ô �fœcÔ"Ü˜“[‰FÜ˜F¤CÔ(ÜØEóGð Gð �{‰{˜4Ó Ð r   )r   r*   r+   r,   r   Úpropertyr3   r   r=   r!   r9   Ú__classcell__©r   s   @r   r   r   V   s5   ø„ ñô""ð ñ#ó ð#òò#ò"ö!r   r   c                   óD   ‡ — e Zd ZdZˆ fd„Zed„ «       Zd„ Zd„ Zd„ Z	ˆ xZ
S )rA   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"
    c                 óZ   •— t        |t        «      st        d«      ‚t        ‰| �  |«       y )NzSQL values must be strings)r   r@   r0   r2   r   )r
   Ústringr   s     €r   r   zSQL.__init__µ   s&   ø€ Ü˜&¤#Ô&ÜÐ8Ó9Ð9Ü‰Ñ˜Õ r   c                 ó   — | j                   S )z(The string wrapped by the `!SQL` object.r   r   s    r   rH   z
SQL.stringº   ó   € ð �}‰}Ðr   c                 ó   — | j                   S r   r   r   s     r   r   zSQL.as_string¿   s   € Ø�}‰}Ðr   c                 óØ  — g }d}t         j                  | j                  «      D ]º  \  }}}}|rt        d«      ‚|rt        d«      ‚|r|j	                  t        |«      «       |€ŒA|j                  «       r-|rt        d«      ‚|j	                  |t        |«         «       d}Œ~|s'|€t        d«      ‚|j	                  ||   «       |dz  }Œ§|j	                  ||   «       Œ¼ t        |«      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

        r   z(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	   Ú
ValueErrorr1   rA   ÚisdigitÚintr   )	r
   ÚargsÚkwargsr:   ÚautonumÚpreÚnameÚspecÚconvs	            r   Úformatz
SQL.formatÂ   s÷   € ð@ ˆØˆÜ%/×%5Ñ%5°d·m±mÓ%Dò 	(Ñ!ˆC��t˜TÙÜ Ð!KÓLÐLÙÜ Ð!HÓIÐIÙØ—	‘	œ#˜c›(Ô#àˆ|Øà�|‰|Œ~ÙÜ$ØPóRð Rà—	‘	˜$œs 4›y™/Ô*Ø‘áØ�?Ü$ØPóRð Rà—	‘	˜$˜w™-Ô(Ø˜1‘‘ð —	‘	˜& ™,Õ'ð5	(ô8 ˜‹|Ðr   c                 óì   — g }t        |«      }	 |j                  t        |«      «       |D ]$  }|j                  | «       |j                  |«       Œ& t	        |«      S # t        $ r Y t	        |«      S w xY w)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<   r1   ÚnextÚStopIterationr   )r
   r3   r:   Úitr4   s        r   r9   zSQL.join  sz   € ð$ ˆÜ�#‹Yˆð	Ø�I‰I”d˜2“hÔð ò �Ø—	‘	˜$”Ø—	‘	˜!•ðô ˜‹|Ðøô ò 	Øô ˜‹|Ðð	ús   �A Á	A3Á2A3)r   r*   r+   r,   r   rC   rH   r   rZ   r9   rD   rE   s   @r   rA   rA   Ÿ   s1   ø„ ñô*!ð
 ñó ðòò>ö@r   rA   c                   óN   ‡ — e Zd ZdZˆ fd„Zed„ «       Zed„ «       Zd„ Zd„ Z	ˆ x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"

    c                 ó‚   •— |st        d«      ‚|D ]  }t        |t        «      rŒt        d«      ‚ t        ‰| �  |«       y )NzIdentifier cannot be emptyz$SQL identifier parts must be strings)r0   r   r@   r2   r   )r
   ÚstringsÚsr   s      €r   r   zIdentifier.__init__A  sH   ø€ ÙÜÐ8Ó9Ð9àò 	HˆAÜ˜a¤Õ%ÜÐ FÓGÐGð	Hô 	‰Ñ˜Õ!r   c                 ó   — | j                   S )z5A tuple with the strings wrapped by the `Identifier`.r   r   s    r   rb   zIdentifier.stringsK  rJ   r   c                 óf   — t        | j                  «      dk(  r| j                  d   S t        d«      ‚)z0The string wrapped by the `Identifier`.
        rM   r   z2the Identifier wraps more than one than one string)Úlenr	   ÚAttributeErrorr   s    r   rH   zIdentifier.stringP  s6   € ô ˆt�}‰}Ó Ò"Ø—=‘= Ñ#Ð#ä ØDóFð Fr   c                 óˆ   — | j                   j                  › ddj                  t        t        | j
                  «      «      › d�S )Nr   z, r   )r   r   r9   ÚmapÚreprr	   r   s    r   r   zIdentifier.__repr__Z  s6   € Ø—.‘.×)Ñ)Ð*¨!¨D¯I©I´c¼$ÀÇÁÓ6NÓ,OÐ+PÐPQÐRÐRr   c                 óL   ‡— dj                  ˆfd„| j                  D «       «      S )Nú.c              3   óJ   •K  — | ]  }t        j                  |‰«      –— Œ y ­wr   )ÚextÚquote_ident)Ú.0rc   r   s     €r   ú	<genexpr>z'Identifier.as_string.<locals>.<genexpr>^  s   øè ø€ ÒK¸œŸ™¨¨7×3ÑKùs   ƒ #)r9   r	   r   s    `r   r   zIdentifier.as_string]  s   ø€ Ø�x‰xÓK¸T¿]¹]ÔKÓKÐKr   )r   r*   r+   r,   r   rC   rb   rH   r   r   rD   rE   s   @r   r`   r`   "  sC   ø„ ñô<"ð ñó ðð ñFó ðFòSöLr   r`   c                   ó&   — e Zd ZdZed„ «       Zd„ Zy)Ú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

    c                 ó   — | j                   S )z%The object wrapped by the `!Literal`.r   r   s    r   r   zLiteral.wrappedu  rJ   r   c                 ó´  — t        |t        j                  «      r|}n2t        |t        j                  «      r|j                  }nt	        d«      ‚t        j
                  | j                  «      }t        |d«      r|j                  |«       |j                  «       }t        |t        «      r,|j                  t        j                  |j                     «      }|S )Nz(context must be a connection or a cursorÚprepare)r   rn   Ú
connectionÚcursorr0   Úadaptr	   Úhasattrrv   Ú	getquotedÚbytesÚdecodeÚ	encodingsÚencoding)r
   r   ÚconnÚar:   s        r   r   zLiteral.as_stringz  s–   € ä�gœsŸ~™~Ô.Ø‰DÜ˜¤§¡Ô,Ø×%Ñ%‰DäÐFÓGÐGä�I‰I�d—m‘mÓ$ˆÜ�1�iÔ Ø�I‰I�dŒOà�[‰[‹]ˆÜ�bœ%Ô Ø—‘œ3Ÿ=™=¨¯©Ñ7Ó8ˆBàˆ	r   N)r   r*   r+   r,   rC   r   r   r-   r   r   rs   rs   a  s    „ ñð& ñó ðór   rs   c                   ó@   ‡ — e Zd ZdZdˆ fd„	Zed„ «       Zd„ Zd„ Zˆ x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)

    c                 óˆ   •— t        |t        «      rd|v rt        d|›�«      ‚|�t        d|›�«      ‚t        ‰| �  |«       y )Nr   zinvalid name: z%expected string or None as name, got )r   r@   rP   r0   r2   r   )r
   rW   r   s     €r   r   zPlaceholder.__init__©  sL   ø€ Ü�dœCÔ Ø�d‰{Ü  >°$°Ð!:Ó;Ð;àÐÜÐCÀDÀ8ÐLÓMÐMä‰Ñ˜Õr   c                 ó   — | j                   S )zThe name of the `!Placeholder`.r   r   s    r   rW   zPlaceholder.name³  rJ   r   c                 ó˜   — | j                   €| j                  j                  › d�S | j                  j                  › d| j                   ›d�S )Nz()r   r   )r	   r   r   r   s    r   r   zPlaceholder.__repr__¸  sG   € Ø�=‰=Ð Ø—n‘n×-Ñ-Ð.¨bÐ1Ð1à—n‘n×-Ñ-Ð.¨a°·±Ð/@ÀÐBÐBr   c                 ó<   — | j                   �d| j                   › d�S y)Nz%(z)sz%sr   r   s     r   r   zPlaceholder.as_string¾  s"   € Ø�=‰=Ð$Ø˜Ÿ™� bÐ)Ð)àr   r   )
r   r*   r+   r,   r   rC   rW   r   r   rD   rE   s   @r   rƒ   rƒ   Ž  s,   ø„ ñõ4ð ñó ðòCör   rƒ   ÚNULLÚDEFAULT)r,   rH   Úpsycopg2r   rn   Ú	FormatterrN   r   r   rA   r`   rs   rƒ   rˆ   r‰   r-   r   r   ú<module>rŒ      sŠ   ðñó4 å &ð ˆV×ÑÓ€
÷0&ñ 0&ôfF!ˆzô F!ôR@ˆ*ô @ôF<L�ô <Lô~*ˆjô *ôZ4�*ô 4ñp ˆ6ƒ{€Ù
ˆi‹.�r   