
    -h~7                     p   S SK r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  \R                  4S	 jr\R                  4S
 jr " S S\R                  \R                  5      r\R                   " SSSS9r\R                   " SSSS9r\R                   " SSSS9r " S S\R(                  5      rS rg)    N   )types)util)	coercions)
expression)	operators)rolesc                 $    UR                  X5      $ )zbA synonym for the ARRAY-level :meth:`.ARRAY.Comparator.any` method.
See that method for details.

)anyotherarrexproperators      yC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/dialects/postgresql/array.pyAnyr           ;;u''    c                 $    UR                  X5      $ )zbA synonym for the ARRAY-level :meth:`.ARRAY.Comparator.all` method.
See that method for details.

)allr   s      r   Allr      r   r   c                   \   ^  \ rS rSrSrS rSrSrU 4S jr\	S 5       r
S
S jrSS jrS	rU =r$ )array$   a[  A PostgreSQL ARRAY literal.

This is used to produce ARRAY literals in SQL expressions, e.g.::

    from sqlalchemy.dialects.postgresql import array
    from sqlalchemy.dialects import postgresql
    from sqlalchemy import select, func

    stmt = select(array([1,2]) + array([3,4,5]))

    print(stmt.compile(dialect=postgresql.dialect()))

Produces the SQL::

    SELECT ARRAY[%(param_1)s, %(param_2)s] ||
        ARRAY[%(param_3)s, %(param_4)s, %(param_5)s]) AS anon_1

An instance of :class:`.array` will always have the datatype
:class:`_types.ARRAY`.  The "inner" type of the array is inferred from
the values present, unless the ``type_`` keyword argument is passed::

    array(['foo', 'bar'], type_=CHAR)

Multidimensional arrays are produced by nesting :class:`.array` constructs.
The dimensionality of the final :class:`_types.ARRAY`
type is calculated by
recursively adding the dimensions of the inner :class:`_types.ARRAY`
type::

    stmt = select(
        array([
            array([1, 2]), array([3, 4]), array([column('q'), column('x')])
        ])
    )
    print(stmt.compile(dialect=postgresql.dialect()))

Produces::

    SELECT ARRAY[ARRAY[%(param_1)s, %(param_2)s],
    ARRAY[%(param_3)s, %(param_4)s], ARRAY[q, x]] AS anon_1

.. versionadded:: 1.3.6 added support for multidimensional array literals

.. seealso::

    :class:`_postgresql.ARRAY`


postgresqlTc                 $  > U Vs/ s H(  n[         R                  " [        R                  U5      PM*     nn[        [
        U ]  " U0 UD6  U Vs/ s H  oDR                  PM     snU l        UR                  SU R                  (       a  U R                  S   O[        R                  5      n[        U[        5      (       a6  [        UR                  UR                  b  UR                  S-   OSS9U l        g [        U5      U l        g s  snf s  snf )Ntype_r         )
dimensions)r   expectr	   ExpressionElementRolesuperr   __init__type_type_tuplepopsqltypesNULLTYPE
isinstanceARRAY	item_typer   )selfclauseskwcarg	main_type	__class__s         r   r#   array.__init__\   s    FM
FMIU88!<g 	 
 	eT#W33078HH8FF#'#3#3DQ9J9J
	
 i''##''3 %//!3	DI i(DI)
 9s   /DDc                     U 4$ N r,   s    r   _select_iterablearray._select_iterables   s	    wr   c                     U(       d  U[         R                  L a#  [        R                  " S UUUU R                  SS9$ [        U Vs/ s H  nU R                  XSUS9PM     sn5      $ s  snf )NT)_compared_to_operatorr   _compared_to_typeunique)_assume_scalarr   )r   getitemr   BindParameterr$   r   _bind_param)r,   r   objr>   r   os         r   rA   array._bind_paramw   s    X):)::++&."&))  
 !	 ! $$ D %  !	 s   A)c                     U[         R                  [         R                  [         R                  4;   a  [        R
                  " U 5      $ U $ r5   )r   any_opall_opr?   r   Grouping)r,   againsts     r   
self_grouparray.self_group   s9    y'')9)99;L;LMM&&t,,Kr   )r%   r$   )FNr5   )__name__
__module____qualname____firstlineno____doc____visit_name__stringify_dialectinherit_cacher#   propertyr8   rA   rJ   __static_attributes____classcell__)r2   s   @r   r   r   $   sC    /b N$M).  * r   r   z@>   T)
precedenceis_comparisonz<@z&&c                       \ rS rSrSr " S S\R                  R                  5      r\r SS jr	\
S 5       r\
S 5       rS	 rS
 r\R                   S 5       rS rS rS rSrg)r*      a
  PostgreSQL ARRAY type.

.. versionchanged:: 1.1 The :class:`_postgresql.ARRAY` type is now
   a subclass of the core :class:`_types.ARRAY` type.

The :class:`_postgresql.ARRAY` type is constructed in the same way
as the core :class:`_types.ARRAY` type; a member type is required, and a
number of dimensions is recommended if the type is to be used for more
than one dimension::

    from sqlalchemy.dialects import postgresql

    mytable = Table("mytable", metadata,
            Column("data", postgresql.ARRAY(Integer, dimensions=2))
        )

The :class:`_postgresql.ARRAY` type provides all operations defined on the
core :class:`_types.ARRAY` type, including support for "dimensions",
indexed access, and simple matching such as
:meth:`.types.ARRAY.Comparator.any` and
:meth:`.types.ARRAY.Comparator.all`.  :class:`_postgresql.ARRAY`
class also
provides PostgreSQL-specific methods for containment operations, including
:meth:`.postgresql.ARRAY.Comparator.contains`
:meth:`.postgresql.ARRAY.Comparator.contained_by`, and
:meth:`.postgresql.ARRAY.Comparator.overlap`, e.g.::

    mytable.c.data.contains([1, 2])

The :class:`_postgresql.ARRAY` type may not be supported on all
PostgreSQL DBAPIs; it is currently known to work on psycopg2 only.

Additionally, the :class:`_postgresql.ARRAY`
type does not work directly in
conjunction with the :class:`.ENUM` type.  For a workaround, see the
special type at :ref:`postgresql_array_of_enum`.

.. container:: topic

    **Detecting Changes in ARRAY columns when using the ORM**

    The :class:`_postgresql.ARRAY` type, when used with the SQLAlchemy ORM,
    does not detect in-place mutations to the array. In order to detect
    these, the :mod:`sqlalchemy.ext.mutable` extension must be used, using
    the :class:`.MutableList` class::

        from sqlalchemy.dialects.postgresql import ARRAY
        from sqlalchemy.ext.mutable import MutableList

        class SomeOrmClass(Base):
            # ...

            data = Column(MutableList.as_mutable(ARRAY(Integer)))

    This extension will allow "in-place" changes such to the array
    such as ``.append()`` to produce events which will be detected by the
    unit of work.  Note that changes to elements **inside** the array,
    including subarrays that are mutated in place, are **not** detected.

    Alternatively, assigning a new array value to an ORM element that
    replaces the old one will always trigger a change event.

.. seealso::

    :class:`_types.ARRAY` - base array type

    :class:`_postgresql.array` - produces a literal array value.

c                   *    \ rS rSrSrS rS rS rSrg)ARRAY.Comparator   a  Define comparison operations for :class:`_types.ARRAY`.

Note that these operations are in addition to those provided
by the base :class:`.types.ARRAY.Comparator` class, including
:meth:`.types.ARRAY.Comparator.any` and
:meth:`.types.ARRAY.Comparator.all`.

c                 H    U R                  [        U[        R                  S9$ )zBoolean expression.  Test if elements are a superset of the
elements of the argument array expression.

kwargs may be ignored by this operator but are required for API
conformance.
result_type)operateCONTAINSr'   Boolean)r,   r   kwargss      r   containsARRAY.Comparator.contains   s     <<%X=M=M<NNr   c                 H    U R                  [        U[        R                  S9$ )zlBoolean expression.  Test if elements are a proper subset of the
elements of the argument array expression.
r`   )rb   CONTAINED_BYr'   rd   r,   r   s     r   contained_byARRAY.Comparator.contained_by   s'     <<e1A1A    r   c                 H    U R                  [        U[        R                  S9$ )z]Boolean expression.  Test if array has elements in common with
an argument array expression.
r`   )rb   OVERLAPr'   rd   rj   s     r   overlapARRAY.Comparator.overlap   s     <<H<L<L<MMr   r6   N)	rL   rM   rN   rO   rP   rf   rk   ro   rU   r6   r   r   
Comparatorr]      s    		O		Nr   rq   Nc                     [        U[        5      (       a  [        S5      e[        U[        5      (       a  U" 5       nXl        X l        X0l        X@l        g)a  Construct an ARRAY.

E.g.::

  Column('myarray', ARRAY(Integer))

Arguments are:

:param item_type: The data type of items of this array. Note that
  dimensionality is irrelevant here, so multi-dimensional arrays like
  ``INTEGER[][]``, are constructed as ``ARRAY(Integer)``, not as
  ``ARRAY(ARRAY(Integer))`` or such.

:param as_tuple=False: Specify whether return results
  should be converted to tuples from lists. DBAPIs such
  as psycopg2 return lists by default. When tuples are
  returned, the results are hashable.

:param dimensions: if non-None, the ARRAY will assume a fixed
 number of dimensions.  This will cause the DDL emitted for this
 ARRAY to include the exact number of bracket clauses ``[]``,
 and will also optimize the performance of the type overall.
 Note that PG arrays are always implicitly "non-dimensioned",
 meaning they can store any number of dimensions no matter how
 they were declared.

:param zero_indexes=False: when True, index values will be converted
 between Python zero-based and PostgreSQL one-based indexes, e.g.
 a value of one will be added to all index values before passing
 to the database.

 .. versionadded:: 0.9.5


zUDo not nest ARRAY types; ARRAY(basetype) handles multi-dimensional arrays of basetypeN)r)   r*   
ValueErrorr$   r+   as_tupler   zero_indexes)r,   r+   rt   r   ru   s        r   r#   ARRAY.__init__  sO    L i''?  i&&!I" $(r   c                     U R                   $ r5   )rt   r7   s    r   hashableARRAY.hashable8  s    }}r   c                     [         $ r5   )listr7   s    r   python_typeARRAY.python_type<  s    r   c                 
    X:H  $ r5   r6   )r,   xys      r   compare_valuesARRAY.compare_values@  s	    vr   c                    ^ ^^^ Tc  [        U5      nTS:X  d(  TcF  U(       a  [        US   [         [        45      (       d!  T(       a  T" U4S jU 5       5      $ T" U5      $ T" UUUU 4S jU 5       5      $ )Nr   r   c              3   4   >#    U  H  nT" U5      v   M     g 7fr5   r6   ).0r   itemprocs     r   	<genexpr>$ARRAY._proc_array.<locals>.<genexpr>R  s     !;s!(1++ss   c              3   \   >#    U  H!  nTR                  UTTb  TS-
  OS T5      v   M#     g 7fNr   )_proc_array)r   r   
collectiondimr   r,   s     r   r   r   V  sB       A   "C!GD	  s   ),)r{   r)   tuple)r,   arrr   r   r   s   ` ```r   r   ARRAY._proc_arrayC  ss    ;s)C1H{
 !#a&4-88 !!;s!;;;!#&    r   c                     [        U R                  [        R                  5      =(       a    U R                  R                  $ r5   )r)   r+   r'   Enumnative_enumr7   s    r   _against_native_enumARRAY._against_native_enum`  s-     t~~x}}5 +**	
r   c                     U$ r5   r6   )r,   	bindvalues     r   bind_expressionARRAY.bind_expressiong  s    r   c                 l   ^ ^ T R                   R                  U5      R                  U5      mUU 4S jnU$ )Nc                 R   > U c  U $ TR                  U TTR                  [        5      $ r5   )r   r   r{   value	item_procr,   s    r   process%ARRAY.bind_processor.<locals>.processo  s-    }''9doot r   )r+   dialect_implbind_processor)r,   dialectr   r   s   `  @r   r   ARRAY.bind_processorj  s1    NN//8GG
		 r   c                    ^ ^^^^ T R                   R                  U5      R                  X5      mUU 4S jnT R                  (       a%  Um[        R
                  " S5      mU4S jmUU4S jnU$ )Nc                    > U c  U $ TR                  U TTR                  TR                  (       a
  [        5      $ [        5      $ r5   )r   r   rt   r   r{   r   s    r   r   'ARRAY.result_processor.<locals>.process~  sE    }''OO!]]E	  15	 r   z^{(.*)}$c                 Z   > TR                  U 5      R                  S5      n[        U5      $ r   )matchgroup_split_enum_values)r   innerpatterns     r   handle_raw_string1ARRAY.result_processor.<locals>.handle_raw_string  s'    e,2215)%00r   c                 t   > U c  U $ T" [        U [        R                  5      (       a  T" U 5      5      $ U 5      $ r5   )r)   r   string_types)r   r   super_rps    r   r   r     sH    = L  !%):):;; &e,   r   )r+   r   result_processorr   recompile)r,   r   coltyper   r   r   r   r   s   `   @@@@r   r   ARRAY.result_processory  sY    NN//8II
			 $$Hjj-G1
 r   )rt   r   r+   ru   )FNF)rL   rM   rN   rO   rP   r'   r*   rq   comparator_factoryr#   rT   rx   r|   r   r   r   memoized_propertyr   r   r   r   rU   r6   r   r   r*   r*      s    DL NX^^..  ND $ HM0)d    : 

 
$r   r*   c                    SU ;  a  U (       a  U R                  S5      $ / $ U R                  SS5      nUR                  SS5      n/ n[        R                   " SU5      nSnU Hb  nUS:X  a	  U(       + nM  U(       a#  UR                  UR                  SS5      5        M<  UR	                  [        R
                  " S	U5      5        Md     U$ )
N",z\"z_$ESC_QUOTE$_z\\\z(")Fz([^\s,]+),?)splitreplacer   appendextendfindall)array_stringtextresult	on_quotes	in_quotestoks         r   r   r     s    
,*6|!!#&>B> 7D<<t$DF&II#:%IMM#++os;<MM"**^S9:  Mr   )r    r   r'   r   sqlr   r   r   r	   eqr   r   
ClauseListColumnElementr   	custom_oprc   ri   rn   r*   r   r6   r   r   <module>r      s    
 !      "+ ( "+ (lJ!!:#;#; l^ tF""4ATJ


dq
ECHNN CLr   