ó
    //¡j»9  ã                   óà   • S r SSKrSSKJr  \R
                  " 5       r " S S5      r " S S\5      r " S S	\5      r	 " S
 S\5      r
 " S S\5      r " S S\5      r\	" S5      r\	" S5      rg)zSQL composition utility module
é    N)Ú
extensionsc                   óB   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)Ú
Composableé#   a  
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                 ó   • Xl         g ©N©Ú_wrapped)ÚselfÚwrappeds     Úe/var/www/html/health-monitoring.indevconsultancy.in/venv/lib/python3.13/site-packages/psycopg2/sql.pyÚ__init__ÚComposable.__init__1   s   € Ø�ó    c                 óP   • U R                   R                   SU R                  < S3$ )NÚ(Ú))Ú	__class__Ú__name__r
   ©r   s    r   Ú__repr__ÚComposable.__repr__4   s%   € Ø—.‘.×)Ñ)Ð*¨!¨D¯M©MÑ+<¸AÐ>Ð>r   c                 ó   • [         e)a2  
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_stringÚComposable.as_string7   s
   € ô "Ð!r   c                 ó²   • [        U[        5      (       a  [        U /5      U-   $ [        U[        5      (       a  [        U /5      [        U/5      -   $ [        $ r   )Ú
isinstanceÚComposedr   ÚNotImplemented©r   Úothers     r   Ú__add__ÚComposable.__add__D   sM   € Ü�eœX×&Ñ&Ü˜T˜FÓ# eÑ+Ð+Ü�eœZ×(Ñ(Ü˜T˜FÓ#¤h°¨wÓ&7Ñ7Ð7ä!Ð!r   c                 ó    • [        U /U-  5      $ r   )r!   )r   Úns     r   Ú__mul__ÚComposable.__mul__L   s   € Ü˜˜ ™
Ó#Ð#r   c                 ón   • [        U 5      [        U5      L =(       a    U R                  UR                  :H  $ r   )Útyper
   r#   s     r   Ú__eq__ÚComposable.__eq__O   s'   € Ü�D‹zœT %›[Ð(×L¨T¯]©]¸e¿n¹nÑ-LÐLr   c                 ó.   • U R                  U5      (       + $ r   )r-   r#   s     r   Ú__ne__ÚComposable.__ne__R   s   € Ø—;‘;˜uÓ%Ô%Ð%r   r	   N)r   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r%   r)   r-   r0   Ú__static_attributes__© r   r   r   r   #   s+   † ñò ò?ò"ò"ò$òMõ&r   r   c                   óT   ^ • \ rS rSrSrU 4S jr\S 5       rS rS r	S r
S rS	rU =r$ )
r!   éV   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                 ó¦   >• / nU H9  n[        U[        5      (       d  [        SU< S35      eUR                  U5        M;     [        TU ]  U5        g )Nz*Composed elements must be Composable, got z instead)r    r   Ú	TypeErrorÚappendÚsuperr   )r   Úseqr   Úir   s       €r   r   ÚComposed.__init__h   sU   ø€ ØˆÛˆAÜ˜a¤×,Ñ,ÜØ@ÀÁÀXÐNóPð Pà�N‰N˜1Öñ	 ô 	‰Ñ˜Õ!r   c                 ó,   • [        U R                  5      $ )z+The list of the content of the `!Composed`.)Úlistr
   r   s    r   r>   ÚComposed.seqr   s   € ô �D—M‘MÓ"Ð"r   c                 óŽ   • / nU R                    H#  nUR                  UR                  U5      5        M%     SR                  U5      $ )NÚ )r
   r<   r   Újoin)r   r   Úrvr?   s       r   r   ÚComposed.as_stringw   s8   € ØˆØ—”ˆAØ�I‰I�a—k‘k 'Ó*Ö+ñ à�w‰w�r‹{Ðr   c                 ó,   • [        U R                  5      $ r   )Úiterr
   r   s    r   Ú__iter__ÚComposed.__iter__}   s   € Ü�D—M‘MÓ"Ð"r   c                 óØ   • [        U[        5      (       a"  [        U R                  UR                  -   5      $ [        U[        5      (       a  [        U R                  U/-   5      $ [        $ r   )r    r!   r
   r   r"   r#   s     r   r%   ÚComposed.__add__€   sP   € Ü�eœX×&Ñ&Ü˜DŸM™M¨E¯N©NÑ:Ó;Ð;Ü�eœZ×(Ñ(Ü˜DŸM™M¨U¨GÑ3Ó4Ð4ä!Ð!r   c                 ó¦   • [        U[        5      (       a  [        U5      nO [        U[        5      (       d  [        S5      eUR	                  U 5      $ )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ÚSQLr;   rF   )r   Újoiners     r   rF   ÚComposed.joinˆ   sJ   € ô �fœc×"Ñ"Ü˜“[‰FÜ˜F¤C×(Ñ(ÜØEóGð Gð �{‰{˜4Ó Ð r   r7   )r   r2   r3   r4   r5   r   Úpropertyr>   r   rK   r%   rF   r6   Ú__classcell__©r   s   @r   r!   r!   V   s:   ø† ñõ""ð ñ#ó ð#òò#ò"÷!ð !r   r!   c                   óN   ^ • \ rS rSrSrU 4S jr\S 5       rS rS r	S r
SrU =r$ )	rQ   éŸ   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 *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                 ód   >• [        U[        5      (       d  [        S5      e[        TU ]  U5        g )NzSQL values must be strings)r    rP   r;   r=   r   )r   Ústringr   s     €r   r   ÚSQL.__init__µ   s)   ø€ Ü˜&¤#×&Ñ&ÜÐ8Ó9Ð9Ü‰Ñ˜Õ r   c                 ó   • U R                   $ )z(The string wrapped by the `!SQL` object.r	   r   s    r   rZ   Ú
SQL.stringº   ó   € ð �}‰}Ðr   c                 ó   • U R                   $ r   r	   r   s     r   r   ÚSQL.as_string¿   s   € Ø�}‰}Ðr   c                 ó  • / nSn[         R                  U R                  5       HÚ  u  pVpxU(       a  [        S5      eU(       a  [        S5      eU(       a  UR	                  [        U5      5        Uc  MP  UR                  5       (       a3  U(       a  [        S5      eUR	                  U[        U5         5        SnM˜  U(       d(  Uc  [        S5      eUR	                  X   5        US-  nMÇ  UR	                  X&   5        MÜ     [        U5      $ )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
   Ú
ValueErrorr<   rQ   ÚisdigitÚintr!   )	r   ÚargsÚkwargsrG   ÚautonumÚpreÚnameÚspecÚconvs	            r   ÚformatÚ
SQL.formatÂ   sí   € ð@ ˆØˆÜ%/×%5Ñ%5°d·m±mÖ%DÑ!ˆC�tÞÜ Ð!KÓLÐLÞÜ Ð!HÓIÐIÞØ—	‘	œ#˜c›(Ô#à‰|Ùà�|‰|�~‰~ÞÜ$ØPóRð Rà—	‘	˜$œs 4›y™/Ô*Ø’æØ‘?Ü$ØPóRð Rà—	‘	˜$™-Ô(Ø˜1‘’ð —	‘	˜&™,Ö'ñ5 &Eô8 ˜‹|Ðr   c                 óÞ   • / n[        U5      n UR                  [        U5      5        U H%  nUR                  U 5        UR                  U5        M'     [	        U5      $ ! [         a     Nf = f)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"
)rJ   r<   ÚnextÚStopIterationr!   )r   r>   rG   Úitr?   s        r   rF   ÚSQL.join  si   € ð$ ˆÜ�#‹Yˆð	Ø�I‰I”d˜2“hÔó �Ø—	‘	˜$”Ø—	‘	˜!–ñ ô ˜‹|Ðøô ó 	Ùð	ús   �A Á
A,Á+A,r7   )r   r2   r3   r4   r5   r   rT   rZ   r   ro   rF   r6   rU   rV   s   @r   rQ   rQ   Ÿ   s6   ø† ñõ*!ð
 ñó ðòò>÷@ð r   rQ   c                   óX   ^ • \ rS rSrSrU 4S jr\S 5       r\S 5       rS r	S r
SrU =r$ )	Ú
Identifieri"  aÚ  
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                 óš   >• U(       d  [        S5      eU H#  n[        U[        5      (       a  M  [        S5      e   [        TU ]  U5        g )NzIdentifier cannot be emptyz$SQL identifier parts must be strings)r;   r    rP   r=   r   )r   ÚstringsÚsr   s      €r   r   ÚIdentifier.__init__A  sD   ø€ ÞÜÐ8Ó9Ð9ãˆAÜ˜a¤×%Ó%ÜÐ FÓGÐGñ ô 	‰Ñ˜Õ!r   c                 ó   • U R                   $ )z5A tuple with the strings wrapped by the `Identifier`.r	   r   s    r   ry   ÚIdentifier.stringsK  r^   r   c                 óh   • [        U R                  5      S:X  a  U R                  S   $ [        S5      e)z0The string wrapped by the `Identifier`.
        rb   r   z2the Identifier wraps more than one than one string)Úlenr
   ÚAttributeErrorr   s    r   rZ   ÚIdentifier.stringP  s6   € ô ˆt�}‰}Ó Ó"Ø—=‘= Ñ#Ð#ä ØDóFð Fr   c                 óˆ   • U R                   R                   SSR                  [        [        U R
                  5      5       S3$ )Nr   z, r   )r   r   rF   ÚmapÚreprr
   r   s    r   r   ÚIdentifier.__repr__Z  s6   € Ø—.‘.×)Ñ)Ð*¨!¨D¯I©I´c¼$ÀÇÁÓ6NÓ,OÐ+PÐPQÐRÐRr   c                 óN   ^• SR                  U4S jU R                   5       5      $ )NÚ.c              3   óR   >#   • U  H  n[         R                  " UT5      v •  M     g 7fr   )ÚextÚquote_ident)Ú.0rz   r   s     €r   Ú	<genexpr>Ú'Identifier.as_string.<locals>.<genexpr>^  s   øé € ÐKº]¸œŸš¨¨7×3Ð3º]ùs   ƒ$')rF   r
   r   s    `r   r   ÚIdentifier.as_string]  s   ø€ Ø�x‰xÔK¸T¿]º]ÓKÓKÐKr   r7   )r   r2   r3   r4   r5   r   rT   ry   rZ   r   r   r6   rU   rV   s   @r   rw   rw   "  sI   ø† ñõ<"ð ñó ðð ñFó ðFòS÷Lð Lr   rw   c                   ó.   • \ rS rSrSr\S 5       rS rSrg)ÚLiteralia  aT  
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                 ó   • U R                   $ )z%The object wrapped by the `!Literal`.r	   r   s    r   r   ÚLiteral.wrappedu  r^   r   c                 óÞ  • [        U[        R                  5      (       a  UnO7[        U[        R                  5      (       a  UR                  nO[	        S5      e[        R
                  " U R                  5      n[        US5      (       a  UR                  U5        UR                  5       n[        U[        5      (       a,  UR                  [        R                  UR                     5      nU$ )Nz(context must be a connection or a cursorÚprepare)r    r‰   Ú
connectionÚcursorr;   Úadaptr
   Úhasattrr”   Ú	getquotedÚbytesÚdecodeÚ	encodingsÚencoding)r   r   ÚconnÚarG   s        r   r   Ú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   r7   N)	r   r2   r3   r4   r5   rT   r   r   r6   r7   r   r   r�   r�   a  s    † ñð& ñó ðõr   r�   c                   óL   ^ • \ rS rSrSrSU 4S jjr\S 5       rS rS r	Sr
U =r$ )	ÚPlaceholderiŽ  aŸ  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                 óž   >• [        U[        5      (       a  SU;   a  [        SU< 35      eOUb  [        SU< 35      e[        TU ]  U5        g )Nr   zinvalid name: z%expected string or None as name, got )r    rP   re   r;   r=   r   )r   rl   r   s     €r   r   ÚPlaceholder.__init__©  sV   ø€ Ü�dœC× Ñ Ø�d‹{Ü  >°$±Ð!:Ó;Ð;ð ð ÑÜÐCÀDÁ8ÐLÓMÐMä‰Ñ˜Õr   c                 ó   • U R                   $ )zThe name of the `!Placeholder`.r	   r   s    r   rl   ÚPlaceholder.name³  r^   r   c                 óœ   • U R                   c  U R                  R                   S3$ U R                  R                   SU R                   < S3$ )Nz()r   r   )r
   r   r   r   s    r   r   ÚPlaceholder.__repr__¸  sG   € Ø�=‰=Ñ Ø—n‘n×-Ñ-Ð.¨bÐ1Ð1à—n‘n×-Ñ-Ð.¨a°·±Ñ/@ÀÐBÐBr   c                 ó>   • U R                   b  SU R                    S3$ g)Nz%(z)sz%sr	   r   s     r   r   ÚPlaceholder.as_string¾  s"   € Ø�=‰=Ñ$Ø˜Ÿ™� bÐ)Ð)àr   r7   r   )r   r2   r3   r4   r5   r   rT   rl   r   r   r6   rU   rV   s   @r   r¢   r¢   Ž  s1   ø† ñ÷4ð ñó ðòC÷ð r   r¢   ÚNULLÚDEFAULT)r5   rZ   Úpsycopg2r   r‰   Ú	Formatterrc   r   r!   rQ   rw   r�   r¢   r«   r¬   r7   r   r   Ú<module>r¯      sˆ   ðñó4 å &ð ×ÒÓ€
÷0&ñ 0&ôfF!ˆzô F!ôR@ˆ*ô @ôF<L�ô <Lô~*ˆjô *ôZ4�*ô 4ñp ˆ6ƒ{€Ù
ˆi‹.�r   