§
    YŠtj¥J  ã                  ó˜  — d Z ddlmZ ddlZddlZddlmZmZ ddlm	Z	m
Z
 ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZ ddlmZ d&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  G d„ d e¦  «        Z! ed!¦  «        Z" ed"¦  «        Z#d&d'd#„Z$d&d(d%„Z%dS ))z 
SQL composition utility module
é    )ÚannotationsN)ÚABCÚabstractmethod)ÚAnyÚoverload)ÚIterableÚIteratorÚSequenceé   )ÚEscaping)ÚAdaptContext)ÚPyFormat)ÚLiteralStringÚTemplate)Úconn_encoding)ÚTransformerÚobjr   ÚcontextúAdaptContext | NoneÚreturnÚstrc                óF   — t          | ¦  «                             |¦  «        S )aÞ  
    Adapt a Python object to a quoted SQL string.

    Use this function only if you absolutely want to convert a Python string to
    an SQL quoted literal to use e.g. to generate batch SQL and you won't have
    a connection available when you will need to use it.

    This function is relatively inefficient, because it doesn't cache the
    adaptation rules. If you pass a `!context` you can adapt the adaptation
    rules used, otherwise only global rules are used.

    )ÚLiteralÚ	as_string)r   r   s     úI/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/psycopg/sql.pyÚquoter      s   € õ �3‰<Œ<×!Ò! 'Ñ*Ô*Ð*ó    c                  óf   — e Zd ZdZdd„Zdd„Zeddd„¦   «         Zddd„Zdd„Z	dd„Z
dd„Zdd„ZdS )Ú
ComposableaP  
    Abstract base class for objects that can be used to compose an SQL 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.

    `!SQL` and `!Composed` objects can be passed directly to
    `~psycopg.Cursor.execute()`, `~psycopg.Cursor.executemany()`,
    `~psycopg.Cursor.copy()` in place of the query string.
    r   r   c                ó   — || _         d S ©N©Ú_obj)Úselfr   s     r   Ú__init__zComposable.__init__6   s   € ØˆŒ	ˆ	ˆ	r   r   r   c                ó0   — | j         j        › d| j        ›d�S )Nú(ú))Ú	__class__Ú__name__r#   ©r$   s    r   Ú__repr__zComposable.__repr__9   s    € Ø”.Ô)Ð:Ð:¨D¬IÐ:Ð:Ð:Ð:r   Nr   r   Úbytesc                ó   — t           ‚)a~  
        Return the value of the object as bytes.

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

        The method is automatically invoked by `~psycopg.Cursor.execute()`,
        `~psycopg.Cursor.executemany()`, `~psycopg.Cursor.copy()` if a
        `!Composable` is passed instead of the query string.

        )ÚNotImplementedError©r$   r   s     r   Úas_byteszComposable.as_bytes<   s
   € õ "Ð!r   c                ó
  — t          |r|j        nd¦  «        }t          |                      |¦  «        x}t          ¦  «        r|                     |¦  «        S t          j        |¦  «                             |¦  «        d         S )z®
        Return the value of the object as string.

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

        Nr   )r   Ú
connectionÚ
isinstancer1   r-   ÚdecodeÚcodecsÚlookup)r$   r   ÚencÚbs       r   r   zComposable.as_stringK   sv   € õ °'ÐC˜GÔ.Ð.¸tÑDÔDˆÝ˜DŸMšM¨'Ñ2Ô2Ð2�qµUÑ;Ô;ð 	3Ø—8’8˜C‘=”=Ð õ ”= Ñ%Ô%×,Ò,¨QÑ/Ô/°Ô2Ð2r   ÚotherÚComposedc                óÌ   — t          |t          ¦  «        rt          | g¦  «        |z   S t          |t          ¦  «        r!t          | g¦  «        t          |g¦  «        z   S t          S r!   )r4   r;   r   ÚNotImplemented©r$   r:   s     r   Ú__add__zComposable.__add__Z   s`   € Ý�e�XÑ&Ô&ð 	,Ý˜T˜FÑ#Ô# eÑ+Ð+Ý�e�ZÑ(Ô(ð 	"Ý˜T˜FÑ#Ô#¥h°¨wÑ&7Ô&7Ñ7Ð7å!Ð!r   ÚnÚintc                ó(   — t          | g|z  ¦  «        S r!   )r;   )r$   r@   s     r   Ú__mul__zComposable.__mul__b   s   € Ý˜˜ ™
Ñ#Ô#Ð#r   Úboolc                ó^   — t          | ¦  «        t          |¦  «        u o| j        |j        k    S r!   )Útyper#   r>   s     r   Ú__eq__zComposable.__eq__e   s'   € Ý�D‰zŒz�T %™[œ[Ð(ÐD¨T¬Y¸%¼*Ò-DÐDr   c                ó.   — |                       |¦  «         S r!   )rG   r>   s     r   Ú__ne__zComposable.__ne__h   s   € Ø—;’;˜uÑ%Ô%Ð%Ð%r   )r   r   ©r   r   r!   ©r   r   r   r-   ©r   r   r   r   ©r:   r   r   r;   )r@   rA   r   r;   )r:   r   r   rD   )r*   Ú
__module__Ú__qualname__Ú__doc__r%   r,   r   r1   r   r?   rC   rG   rI   © r   r   r   r   '   sØ   € € € € € ðð ðð ð ð ð;ð ;ð ;ð ;ð ð"ð "ð "ð "ñ „^ð"ð3ð 3ð 3ð 3ð 3ð"ð "ð "ð "ð$ð $ð $ð $ðEð Eð Eð Eð&ð &ð &ð &ð &ð &r   r   c                  óR   ‡ — e Zd ZU dZded<   dˆ fd„Zddd„Zdd„Zdd„Zd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
    (such as the `SQL.format()` method). `!Composed` objects can be passed
    directly to `~psycopg.Cursor.execute()`, `~psycopg.Cursor.executemany()`,
    `~psycopg.Cursor.copy()` in place of the query string.

    It is also possible to create a `!Composed` directly specifying a sequence
    of objects as arguments: if they are not `!Composable` they will be wrapped
    in a `Literal`.

    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).
    zlist[Composable]r#   ÚseqúSequence[Any]c                ób   •— d„ |D ¦   «         }t          ¦   «                              |¦  «         d S )Nc                óZ   — g | ](}t          |t          ¦  «        r|nt          |¦  «        ‘Œ)S rQ   )r4   r   r   )Ú.0r   s     r   ú
<listcomp>z%Composed.__init__.<locals>.<listcomp>‡   s1   € ÐSÐSÐSÈ•j ¥jÑ1Ô1ÐCˆsˆsµw¸s±|´|ÐSÐSÐSr   )Úsuperr%   )r$   rS   r)   s     €r   r%   zComposed.__init__†   s4   ø€ ØSÐSÈsÐSÑSÔSˆÝ‰Œ×Ò˜ÑÔÐÐÐr   Nr   r   r   r-   c                óP   ‡— d                      ˆfd„| j        D ¦   «         ¦  «        S )Nr   c              3  óB   •K  — | ]}|                      ‰¦  «        V — Œd S r!   ©r1   )rW   r   r   s     €r   ú	<genexpr>z$Composed.as_bytes.<locals>.<genexpr>‹   s/   øè è € ÐCÐC°#˜Ÿš WÑ-Ô-ÐCÐCÐCÐCÐCÐCr   )Újoinr#   r0   s    `r   r1   zComposed.as_bytesŠ   s,   ø€ Ø�xŠxÐCÐCÐCÐC¸¼ÐCÑCÔCÑCÔCÐCr   úIterator[Composable]c                ó*   — t          | j        ¦  «        S r!   )Úiterr#   r+   s    r   Ú__iter__zComposed.__iter__�   s   € Ý�D”I‰ŒÐr   r:   r   c                óÌ   — t          |t          ¦  «        rt          | j        |j        z   ¦  «        S t          |t          ¦  «        rt          | j        |gz   ¦  «        S t          S r!   )r4   r;   r#   r   r=   r>   s     r   r?   zComposed.__add__�   sZ   € Ý�e�XÑ&Ô&ð 	4Ý˜DœI¨¬
Ñ2Ñ3Ô3Ð3Ý�e�ZÑ(Ô(ð 	"Ý˜DœI¨¨Ñ/Ñ0Ô0Ð0å!Ð!r   ÚjoinerúSQL | LiteralStringc                óÐ   — t          |t          ¦  «        rt          |¦  «        }n(t          |t          ¦  «        st          d|›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"

        z5Composed.join() argument must be strings or SQL, got ú instead)r4   r   ÚSQLÚ	TypeErrorr^   r#   )r$   rd   s     r   r^   zComposed.join˜   st   € õ �f�cÑ"Ô"ð 	Ý˜‘[”[ˆFˆFÝ˜F¥CÑ(Ô(ð 	Ýð+Øð+ð +ð +ñô ð ð
 �{Š{˜4œ9Ñ%Ô%Ð%r   )rS   rT   r!   rK   )r   r_   rM   )rd   re   r   r;   )r*   rN   rO   rP   Ú__annotations__r%   r1   rb   r?   r^   Ú__classcell__©r)   s   @r   r;   r;   l   s±   ø€ € € € € € ðð ð. ÐÐÑðð ð ð ð ð ðDð Dð Dð Dð Dðð ð ð ð"ð "ð "ð "ð&ð &ð &ð &ð &ð &ð &ð &r   r;   c                  ó¢   ‡ — e Zd ZU dZded<    ej        ¦   «         Zdˆ fd„Zddd„Z	ddd„Z
dd„Zed d„¦   «         Zed!d„¦   «         Zd"d„Zˆ xZS )#rh   añ  
    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 `!obj` 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.

    `!SQL` objects can be passed directly to `~psycopg.Cursor.execute()`,
    `~psycopg.Cursor.executemany()`, `~psycopg.Cursor.copy()` in place of the
    query string.

    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"
    r   r#   r   c                óš   •— t          ¦   «                              |¦  «         t          |t          ¦  «        st	          d|›d�¦  «        ‚d S )Nz SQL values must be strings, got rg   )rY   r%   r4   r   ri   )r$   r   r)   s     €r   r%   zSQL.__init__Ï   sT   ø€ Ý‰Œ×Ò˜ÑÔÐÝ˜#�sÑ#Ô#ð 	PÝÐN¸sÐNÐNÐNÑOÔOÐOð	Pð 	Pr   Nr   r   r   r   c                ó   — | j         S r!   r"   r0   s     r   r   zSQL.as_stringÔ   s
   € ØŒyÐr   r-   c                ój   — |r|j         nd }t          |¦  «        }| j                             |¦  «        S r!   )r3   r   r#   Úencode©r$   r   Úconnr8   s       r   r1   zSQL.as_bytes×   s7   € Ø%,Ð6ˆwÔ!Ð!°$ˆÝ˜DÑ!Ô!ˆØŒy×Ò Ñ$Ô$Ð$r   Úargsr   Úkwargsr;   c                óF  — g }d}| j                              | j        ¦  «        D ]ï\  }}}}|rt          d¦  «        ‚|rt          d¦  «        ‚|r"|                     t          |¦  «        ¦  «         |€ŒP|                     ¦   «         r<|rt          d¦  «        ‚|                     |t          |¦  «                 ¦  «         d}Œ |s2|€t          d¦  «        ‚|                     ||         ¦  «         |dz  }ŒÔ|                     ||         ¦  «         Œðt          |¦  «        S )aý  
        Merge `Composable` objects into a template.

        :param args: parameters to replace to numbered (``{0}``, ``{1}``) or
            auto-numbered (``{}``) placeholders
        :param 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.

        If a `!Composable` objects is passed to the template it will be merged
        according to its `as_string()` method. If any other Python object is
        passed, it will be wrapped in a `Literal` object and so escaped
        according to SQL rules.

        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 name = {name}")
            ...     .format(tbl=sql.Identifier('people'), name="O'Rourke"))
            ...     .as_string(conn))
            SELECT * FROM "people" WHERE name = 'O''Rourke'

        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 automaticr   )	Ú
_formatterÚparser#   Ú
ValueErrorÚappendrh   ÚisdigitrA   r;   )	r$   rt   ru   ÚrvÚautonumÚpreÚnameÚspecÚconvs	            r   Úformatz
SQL.formatÜ   sQ  € ðF  "ˆØˆð &*¤_×%:Ò%:¸4¼9Ñ%EÔ%Eð 	(ð 	(Ñ!ˆC��t˜TØð MÝ Ð!KÑLÔLÐLØð JÝ Ð!HÑIÔIÐIØð $Ø—	’	�#˜c™(œ(Ñ#Ô#Ð#àˆ|Øà�|Š|‰~Œ~ð (Øð Ý$ØPñô ð ð —	’	˜$�s 4™yœyœ/Ñ*Ô*Ð*Ø��àð 	(Ø�?Ý$ØPñô ð ð —	’	˜$˜wœ-Ñ(Ô(Ð(Ø˜1‘��ð —	’	˜& œ,Ñ'Ô'Ð'Ð'å˜‰|Œ|Ðr   rS   úIterable[Template]r   c                ó   — d S r!   rQ   ©r$   rS   s     r   r^   zSQL.join$  s   € Ø9<¸r   úIterable[Any]c                ó   — d S r!   rQ   r…   s     r   r^   zSQL.join'  s   € Ø47°Cr   úComposed | Templatec                ó¨  — t          |¦  «        }	 t          |¦  «        }n# t          $ r t          g ¦  «        cY S w xY wt	          |t
          ¦  «        r…t          |¦  «        }|D ]j}t	          |t
          ¦  «        s$t          dt          |¦  «        j	        › �¦  «        ‚| 
                    | j        ¦  «         |                     |¦  «         Œkt          |Ž S |g}|D ]e}t	          |t
          ¦  «        r$t          dt          |¦  «        j	        › �¦  «        ‚| 
                    | ¦  «         | 
                    |¦  «         Œft          |¦  «        S )aæ  
        Join a sequence of `Composable`.

        :param seq: the elements to join.

        Use the `!SQL` object's string to separate the elements in `!seq`.
        Elements that are not `Composable` will be considered `Literal`.

        If the arguments are `Template` instance, return a `Template` joining
        all the items. Note that arguments must either be all templates or
        none should be.

        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"
        zcan't mix Template and )ra   ÚnextÚStopIterationr;   r4   r   Úlistri   rF   r*   rz   r#   Úextend)r$   rS   ÚitÚfirstÚitemsÚtÚcsÚis           r   r^   zSQL.join*  sT  € õ0 �#‰YŒYˆð	 Ý˜‘H”HˆEˆEøÝð 	 ð 	 ð 	 Ý˜B‘<”<ÐÐÐð	 øøøõ �e�XÑ&Ô&ð 	$Ý˜‘K”KˆEØð  ð  �Ý! !¥XÑ.Ô.ð RÝ#Ð$P½dÀ1¹g¼gÔ>NÐ$PÐ$PÑQÔQÐQØ—’˜TœYÑ'Ô'Ð'Ø—’˜Q‘”��Ý˜UÐ#Ð#àˆWˆØð 	ð 	ˆAÝ˜!�XÑ&Ô&ð NÝÐ L½$¸q¹'¼'Ô:JÐ LÐ LÑMÔMÐMØ�IŠI�d‰OŒOˆOØ�IŠI�a‰LŒLˆLˆLå˜‰|Œ|Ðs   ‘! ¡=¼=)r   r   r!   rL   rK   )rt   r   ru   r   r   r;   )rS   rƒ   r   r   )rS   r†   r   r;   )rS   r†   r   rˆ   )r*   rN   rO   rP   rj   ÚstringÚ	Formatterrw   r%   r   r1   r‚   r   r^   rk   rl   s   @r   rh   rh   ±   sú   ø€ € € € € € ðð ð4 ÐÐÑØ!�Ô!Ñ#Ô#€JðPð Pð Pð Pð Pð Pð
ð ð ð ð ð%ð %ð %ð %ð %ð
Fð Fð Fð FðP Ø<Ð<Ð<ñ „XØ<àØ7Ð7Ð7ñ „XØ7ð.ð .ð .ð .ð .ð .ð .ð .r   rh   c                  óJ   ‡ — e Zd ZU dZded<   dˆ fd„Zdd„Zddd„Zd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/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"

    zSequence[str]r#   Ústringsr   c                óÆ   •— t          ¦   «                              |¦  «         |st          d¦  «        ‚|D ]*}t          |t          ¦  «        st          d|›d�¦  «        ‚Œ+d S )NzIdentifier cannot be emptyz*SQL identifier parts must be strings, got rg   )rY   r%   ri   r4   r   )r$   r˜   Úsr)   s      €r   r%   zIdentifier.__init__}  s‚   ø€ å‰Œ×Ò˜Ñ!Ô!Ð!àð 	:ÝÐ8Ñ9Ô9Ð9àð 	ð 	ˆAÝ˜a¥Ñ%Ô%ð ÝØNÀÐNÐNÐNñô ð ðð	ð 	r   r   c                ó|   — | j         j        › dd                     t          t          | j        ¦  «        ¦  «        › d�S )Nr'   ú, r(   )r)   r*   r^   ÚmapÚreprr#   r+   s    r   r,   zIdentifier.__repr__Š  s6   € Ø”.Ô)ÐNÐN¨D¯IªIµc½$ÀÄ	Ñ6JÔ6JÑ,KÔ,KÐNÐNÐNÐNr   Nr   r   r-   c                óâ   ‡ ‡‡— |r|j         nd x}r8t          |j        ¦  «        Št          |¦  «        Šˆˆfd„‰ j        D ¦   «         }nˆ fd„‰ j        D ¦   «         }d                     |¦  «        S )Nc                ó`   •— g | ]*}‰                      |                     ‰¦  «        ¦  «        ‘Œ+S rQ   )Úescape_identifierrq   )rW   rš   r8   Úescs     €€r   rX   z'Identifier.as_bytes.<locals>.<listcomp>‘  s1   ø€ ÐLÐLÐL¸Q�C×)Ò)¨!¯(ª(°3©-¬-Ñ8Ô8ÐLÐLÐLr   c                ó^   •— g | ])}‰                      |                     ¦   «         ¦  «        ‘Œ*S rQ   )Ú_escape_identifierrq   )rW   rš   r$   s     €r   rX   z'Identifier.as_bytes.<locals>.<listcomp>“  s/   ø€ ÐKÐKÐK¸A�D×+Ò+¨A¯HªH©J¬JÑ7Ô7ÐKÐKÐKr   ó   .)r3   r   Úpgconnr   r#   r^   )r$   r   rs   Úescsr8   r¢   s   `   @@r   r1   zIdentifier.as_bytes�  s‡   øøø€ Ø*1Ð;�GÔ&Ð&°tÐ<ˆ4ð 	LÝ˜4œ;Ñ'Ô'ˆCÝ Ñ%Ô%ˆCØLÐLÐLÐLÐLÀ$Ä)ÐLÑLÔLˆDˆDàKÐKÐKÐKÀÄÐKÑKÔKˆDØ�yŠy˜‰ŒÐr   rš   c                ó:   — d|                      dd¦  «        z   dz   S )zK
        Approximation of PQescapeIdentifier taking no connection.
        ó   "s   "")Úreplace)r$   rš   s     r   r¤   zIdentifier._escape_identifier–  s"   € ð �a—i’i  eÑ,Ô,Ñ,¨tÑ3Ð3r   )r˜   r   rJ   r!   rK   )rš   r-   r   r-   )
r*   rN   rO   rP   rj   r%   r,   r1   r¤   rk   rl   s   @r   r—   r—   [  sœ   ø€ € € € € € ðð ð> ÐÐÑðð ð ð ð ð ðOð Oð Oð Oðð ð ð ð ð4ð 4ð 4ð 4ð 4ð 4ð 4ð 4r   r—   c                  ó   — e Zd ZdZdd	d„ZdS )
r   a™  
    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 <types-adaptation>` for Python objects.

    Example::

        >>> s1 = sql.Literal("fo'o")
        >>> s2 = sql.Literal(42)
        >>> s3 = sql.Literal(date(2000, 1, 1))
        >>> print(sql.SQL(', ').join([s1, s2, s3]).as_string(conn))
        'fo''o', 42, '2000-01-01'::date

    Nr   r   r   r-   c                ó^   — t          j        |¦  «        }|                     | j        ¦  «        S r!   )r   Úfrom_contextÚ
as_literalr#   )r$   r   Útxs      r   r1   zLiteral.as_bytes²  s&   € ÝÔ% gÑ.Ô.ˆØ�}Š}˜TœYÑ'Ô'Ð'r   r!   rK   )r*   rN   rO   rP   r1   rQ   r   r   r   r   �  s7   € € € € € ðð ð((ð (ð (ð (ð (ð (ð (r   r   c                  óP   ‡ — e Zd ZdZdej        fdˆ fd„Zdd	„Zddd„Zdd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``,
    ``%(name)b``), otherwise generate a positional placeholder (e.g. ``%s``,
    ``%b``).

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

    Examples::

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

        >>> q1 = sql.SQL("INSERT INTO my_table ({}) VALUES ({})").format(
        ...     sql.SQL(', ').join(map(sql.Identifier, names)),
        ...     sql.SQL(', ').join(sql.Placeholder() * len(names)))
        >>> print(q1.as_string(conn))
        INSERT INTO my_table ("foo", "bar", "baz") VALUES (%s, %s, %s)

        >>> q2 = sql.SQL("INSERT INTO my_table ({}) VALUES ({})").format(
        ...     sql.SQL(', ').join(map(sql.Identifier, names)),
        ...     sql.SQL(', ').join(map(sql.Placeholder, names)))
        >>> print(q2.as_string(conn))
        INSERT INTO my_table ("foo", "bar", "baz") VALUES (%(foo)s, %(bar)s, %(baz)s)

    Ú r   r   r‚   ústr | PyFormatc                óŽ  •— t          ¦   «                              |¦  «         t          |t          ¦  «        st	          d|›�¦  «        ‚d|v rt          d|›�¦  «        ‚t          |¦  «        t          u rt          |¦  «        }t          |t          ¦  «        s$t	          dt          |¦  «        j        ›�¦  «        ‚|| _	        d S )Nzexpected string as name, got r(   zinvalid name: z!expected PyFormat as format, got )
rY   r%   r4   r   ri   ry   rF   r   r*   Ú_format)r$   r   r‚   r)   s      €r   r%   zPlaceholder.__init__Ó  sÈ   ø€ Ý‰Œ×Ò˜ÑÔÐÝ˜$¥Ñ$Ô$ð 	FÝÐD¸DÐDÐDÑEÔEÐEà�$ˆ;ˆ;ÝÐ6¨dÐ6Ð6Ñ7Ô7Ð7å�‰<Œ<�3ÐÐÝ˜fÑ%Ô%ˆFÝ˜&¥(Ñ+Ô+ð 	ÝØMµD¸±L´LÔ4IÐMÐMñô ð ð "(ˆŒˆˆr   r   c                ó  — g }| j         r'|                     t          | j         ¦  «        ¦  «         | j        t          j        ur"|                     d| j        j        › �¦  «         | j        j        › dd 	                    |¦  «        › d�S )Nzformat=r'   rœ   r(   )
r#   rz   rž   rµ   r   ÚAUTOr   r)   r*   r^   )r$   Úpartss     r   r,   zPlaceholder.__repr__ä  s‚   € ØˆØŒ9ð 	*Ø�LŠL�˜dœi™œÑ)Ô)Ð)ØŒ<�xœ}Ð,Ð,Ø�LŠLÐ6 4¤<Ô#4Ð6Ð6Ñ7Ô7Ð7à”.Ô)Ð?Ð?¨D¯IªI°eÑ,<Ô,<Ð?Ð?Ð?Ð?r   Nr   r   c                óL   — | j         j        }| j        rd| j        › d|› �nd|› �S )Nz%(r(   ú%)rµ   Úvaluer#   )r$   r   Úcodes      r   r   zPlaceholder.as_stringí  s7   € ØŒ|Ô!ˆØ*.¬)ÐCÐ&�D”IÐ&Ð& Ð&Ð&Ð&¸¸T¸¸ÐCr   r-   c                ó†   — |r|j         nd }t          |¦  «        }|                      |¦  «                             |¦  «        S r!   )r3   r   r   rq   rr   s       r   r1   zPlaceholder.as_bytesñ  sA   € Ø%,Ð6ˆwÔ!Ð!°$ˆÝ˜DÑ!Ô!ˆØ�~Š~˜gÑ&Ô&×-Ò-¨cÑ2Ô2Ð2r   )r   r   r‚   r³   rJ   r!   rL   rK   )r*   rN   rO   rP   r   r·   r%   r,   r   r1   rk   rl   s   @r   r±   r±   ·  s¤   ø€ € € € € ðð ð6 $&ÀÄð (ð (ð (ð (ð (ð (ð (ð"@ð @ð @ð @ðDð Dð Dð Dð Dð3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð 3r   r±   ÚNULLÚDEFAULTc                óì   — t          | t          ¦  «        r|                      |¬¦  «        S t          | t          ¦  «        rddlm}  || |¦  «        S t          | ¦  «                             |¬¦  «        S )a  Convert an object to a string according to SQL rules.

    :param obj: the object to convert
    :param context: the context in which to convert the object
    :type context: `~psycopg.abc.AdaptContext` | `!None`

    Adaptation happens according to the type of `!obj`:

    - `Composable` objects are converted according to their
      `~Composable.as_string()` method;
    - `~string.templatelib.Template` strings are converted according to the
      rules documented in :ref:`template-strings`;
    - every other object is converted as it was :ref:`a parameter passed to a
      query <types-adaptation>`.

    If `!context` is specified then it is be used to customize the conversion.
    for example using the encoding of a connection or the dumpers registered.
    ©r   r   )r   )r4   r   r   r   Ú	_tstringsr   )r   r   r   s      r   r   r   ü  s}   € õ& �#•zÑ"Ô"ð 7Ø�}Š} Wˆ}Ñ-Ô-Ð-Ý	�C�Ñ	"Ô	"ð 7Ø(Ð(Ð(Ð(Ð(Ð(àˆy˜˜gÑ&Ô&Ð&å�s‰|Œ|×%Ò%¨gÐ%Ñ6Ô6Ð6r   r-   c                óì   — t          | t          ¦  «        r|                      |¬¦  «        S t          | t          ¦  «        rddlm}  || |¦  «        S t          | ¦  «                             |¬¦  «        S )a  Convert an object to a bytes string according to SQL rules.

    :param obj: the object to convert
    :param context: the context in which to convert the object
    :type context: `~psycopg.abc.AdaptContext` | `!None`

    See `as_string()` for details.
    rÁ   r   r\   )r4   r   r1   r   rÂ   r   )r   r   r1   s      r   r1   r1     s}   € õ �#•zÑ"Ô"ð 6Ø�|Š| Gˆ|Ñ,Ô,Ð,Ý	�C�Ñ	"Ô	"ð 6Ø'Ð'Ð'Ð'Ð'Ð'àˆx˜˜WÑ%Ô%Ð%å�s‰|Œ|×$Ò$¨WÐ$Ñ5Ô5Ð5r   r!   )r   r   r   r   r   r   )r   r   r   r   r   r-   )&rP   Ú
__future__r   r6   r”   Úabcr   r   Útypingr   r   Úcollections.abcr   r	   r
   Úpqr   r   Ú_enumsr   Ú_compatr   r   Ú
_encodingsr   Ú_transformerr   r   r   r;   rh   r—   r   r±   r¾   r¿   r   r1   rQ   r   r   ú<module>rÍ      s  ððð ð #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø %Ð %Ð %Ð %Ð %Ð %Ø %Ð %Ð %Ð %Ð %Ð %ð+ð +ð +ð +ð +ð B&ð B&ð B&ð B&ð B&�ñ B&ô B&ð B&ðJB&ð B&ð B&ð B&ð B&ˆzñ B&ô B&ð B&ðJgð gð gð gð gˆ*ñ gô gð gðT?4ð ?4ð ?4ð ?4ð ?4�ñ ?4ô ?4ð ?4ðD(ð (ð (ð (ð (ˆjñ (ô (ð (ð4=3ð =3ð =3ð =3ð =3�*ñ =3ô =3ð =3ðB €sˆ6�{„{€Ø
ˆ#ˆi‰.Œ.€ð7ð 7ð 7ð 7ð 7ð:6ð 6ð 6ð 6ð 6ð 6ð 6r   