+
    i;                         R t ^ RIt^ RIHt ]P
                  ! 4       t ! R R4      t ! R R]4      t ! R R]4      t	 ! R	 R
]4      t
 ! R R]4      t ! R R]4      t]	! R4      t]	! R4      tR# )zSQL composition utility module
N)
extensionsc                   N   a  ] tR t^#t o RtR tR tR tR tR t	R t
R tR	tV tR
# )
Composablea  
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                    Wn         R # N_wrapped)selfwrappeds   &&fC:\Users\petid\OneDrive\Desktop\Maestro\MAESTRO\maestro-backend\venv\Lib\site-packages\psycopg2/sql.py__init__Composable.__init__1   s        c                P    V P                   P                   R V P                  : R2# )())	__class____name__r   r	   s   &r   __repr__Composable.__repr__4   s%    ..))*!DMM+<A>>r   c                    \         h)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                    \        V\        4      '       d   \        V .4      V,           # \        V\        4      '       d   \        V .4      \        V.4      ,           # \        # r   )
isinstanceComposedr   NotImplementedr	   others   &&r   __add__Composable.__add__D   sM    eX&&TF#e++eZ((TF#hw&777!!r   c                (    \        V .V,          4      # r   )r   )r	   ns   &&r   __mul__Composable.__mul__L   s    
##r   c                p    \        V 4      \        V4      J ;'       d    V P                  VP                  8H  # r   )typer   r!   s   &&r   __eq__Composable.__eq__O   s*    DzT%[(LLT]]enn-LLr   c                .    V P                  V4      '       * # 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+   r.   __static_attributes____classdictcell____classdict__s   @r   r   r   #   s3      ?""$M& &r   r   c                   ^   a a ] tR t^Vt oRtV 3R lt]R 4       tR tR t	R t
R tRtVtV ;t# )	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                   < . pV F:  p\        V\        4      '       g   \        R V: R24      hVP                  V4       K<  	  \        SV `  V4       R# )z*Composed elements must be Composable, got z insteadN)r   r   	TypeErrorappendsuperr   )r	   seqr
   ir   s   &&  r   r   Composed.__init__h   sU    Aa,,@XNP PNN1	  	!r   c                ,    \        V P                  4      # )z+The list of the content of the `!Composed`.)listr   r   s   &r   r=   Composed.seqr   s     DMM""r   c                    . pV P                    F#  pVP                  VP                  V4      4       K%  	  R P                  V4      # ) )r   r;   r   join)r	   r   rvr>   s   &&  r   r   Composed.as_stringw   s8    AIIakk'*+ wwr{r   c                ,    \        V P                  4      # r   )iterr   r   s   &r   __iter__Composed.__iter__}   s    DMM""r   c                    \        V\        4      '       d'   \        V P                  VP                  ,           4      # \        V\        4      '       d   \        V P                  V.,           4      # \        # r   )r   r   r   r   r    r!   s   &&r   r#   Composed.__add__   sP    eX&&DMMENN:;;eZ((DMMUG344!!r   c                    \        V\        4      '       d   \        V4      pM!\        V\        4      '       g   \        R4      hVP	                  V 4      # )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:   rE   )r	   joiners   &&r   rE   Composed.join   sJ     fc""[FFC((EG G {{4  r    )r   r0   r1   r2   r3   r   propertyr=   r   rJ   r#   rE   r4   r5   __classcell__r   r7   s   @@r   r   r   V   s<     "" # ##"! !r   r   c                   X   a a ] tR t^t oRtV 3R lt]R 4       tR tR t	R t
RtVtV ;t# )rP   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                h   < \        V\        4      '       g   \        R 4      h\        SV `  V4       R# )zSQL values must be stringsN)r   rO   r:   r<   r   )r	   stringr   s   &&r   r   SQL.__init__   s)    &#&&899 r   c                    V P                   # )z(The string wrapped by the `!SQL` object.r   r   s   &r   rY   
SQL.string        }}r   c                    V P                   # r   r   r   s   &&r   r   SQL.as_string   s    }}r   c                J   . p^ p\         P                  V P                  4       F  w  rVrxV'       d   \        R4      hV'       d   \        R4      hV'       d   VP	                  \        V4      4       Vf   KT  VP                  4       '       d9   V'       d   \        R4      hVP	                  V\        V4      ,          4       RpK  V'       g2   Vf   \        R4      hVP	                  W,          4       V^,          pK  VP	                  W&,          4       K  	  \        V4      # )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

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;   rP   isdigitintr   )	r	   argskwargsrF   autonumprenamespecconvs	   &*,      r   format
SQL.format   s    @ %/%5%5dmm%D!Ct !KLL !HII		#c(#|||~~$PR R		$s4y/*?$PR R		$-(1 		&,'5 &E8 |r   c                    . p\        V4      p VP                  \        V4      4       V F%  pVP                  V 4       VP                  V4       K'  	  \	        V4      #   \         d     Li ; i)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"
)rI   r;   nextStopIterationr   )r	   r=   rF   itr>   s   &&   r   rE   SQL.join  si    $ #Y	IId2h 		$		!  |  		s   A A-,A-rS   )r   r0   r1   r2   r3   r   rT   rY   r   rm   rE   r4   r5   rU   rV   s   @@r   rP   rP      s8     *!
  >@ r   rP   c                   b   a a ] tR tRt oRtV 3R lt]R 4       t]R 4       tR t	R t
RtVtV ;t# )	
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                   < V'       g   \        R 4      hV F$  p\        V\        4      '       d   K  \        R4      h	  \        SV `  V4       R# )zIdentifier cannot be emptyz$SQL identifier parts must be stringsN)r:   r   rO   r<   r   )r	   stringssr   s   &* r   r   Identifier.__init__A  sD    899Aa%% FGG  	!r   c                    V P                   # )z5A tuple with the strings wrapped by the `Identifier`.r   r   s   &r   rw   Identifier.stringsK  r]   r   c                r    \        V P                  4      ^8X  d   V P                  ^ ,          # \        R4      h)z0The string wrapped by the `Identifier`.
        z2the Identifier wraps more than one than one string)lenr   AttributeErrorr   s   &r   rY   Identifier.stringP  s6     t}}"==## DF Fr   c                    V P                   P                   R RP                  \        \        V P
                  4      4       R2# )r   z, r   )r   r   rE   mapreprr   r   s   &r   r   Identifier.__repr__Z  s6    ..))*!DIIc$6N,O+PPQRRr   c                N   a R P                  V3R lV P                   4       4      # ).c              3   R   <"   T F  p\         P                  ! VS4      x  K  	  R # 5ir   )extquote_ident).0rx   r   s   & r   	<genexpr>'Identifier.as_string.<locals>.<genexpr>^  s     K]733]s   $')rE   r   r   s   &fr   r   Identifier.as_string]  s    xxKT]]KKKr   rS   )r   r0   r1   r2   r3   r   rT   rw   rY   r   r   r4   r5   rU   rV   s   @@r   ru   ru   "  sK     <"   F FSL Lr   ru   c                   :   a  ] tR tRt o Rt]R 4       tR tRtV t	R# )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                    V P                   # )z%The object wrapped by the `!Literal`.r   r   s   &r   r
   Literal.wrappedu  r]   r   c                   \        V\        P                  4      '       d   TpM8\        V\        P                  4      '       d   VP                  pM\	        R 4      h\        P
                  ! V P                  4      p\        VR4      '       d   VP                  V4       VP                  4       p\        V\        4      '       d1   VP                  \        P                  VP                  ,          4      pV# )z(context must be a connection or a cursorprepare)r   r   
connectioncursorr:   adaptr   hasattrr   	getquotedbytesdecode	encodingsencoding)r	   r   connarF   s   &&   r   r   Literal.as_stringz  s    gs~~..D,,%%DFGGIIdmm$1i  IIdO[[]b%  3==78B	r   rS   N)
r   r0   r1   r2   r3   rT   r
   r   r4   r5   r6   s   @r   r   r   a  s(     &   r   r   c                   V   a a ] tR tRt oRtRV 3R llt]R 4       tR tR t	Rt
VtV ;t# )	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                   < \        V\        4      '       d   R V9   d   \        RV: 24      hMVe   \        RV: 24      h\        SV `  V4       R# )r   zinvalid name: Nz%expected string or None as name, got )r   rO   rc   r:   r<   r   )r	   rj   r   s   &&r   r   Placeholder.__init__  sV    dC  d{ >$!:;;  CD8LMMr   c                    V P                   # )zThe name of the `!Placeholder`.r   r   s   &r   rj   Placeholder.name  r]   r   c                    V P                   f   V P                  P                   R2# V P                  P                   RV P                   : R2# )Nz()r   r   )r   r   r   r   s   &r   r   Placeholder.__repr__  sG    == nn--.b11nn--.a/@BBr   c                B    V P                   e   RV P                    R2# R# )Nz%(z)sz%sr   r   s   &&r   r   Placeholder.as_string  s"    ==$b))r   rS   r   )r   r0   r1   r2   r3   r   rT   rj   r   r   r4   r5   rU   rV   s   @@r   r   r     s3     4  C r   r   NULLDEFAULT)r3   rY   psycopg2r   r   	Formatterra   r   r   rP   ru   r   r   r   r   rS   r   r   <module>r      s   4  & 
0& 0&fF!z F!R@* @F<L <L~*j *Z4* 4p 6{
i.r   