
    +hyI                        d Z ddlZddlmZ ddlmZ ddlmZ dZ	 ddl	m
Z
 d ZdZ	 d	Z	 dZ	 d
Z	 	 ddl	mZ dZ G d deej(                        Z G d de      ZeZeZ G d dej2                  ej4                  ej6                        Z G d deej:                        Zy# e$ r d ZY w xY w# e$ r dZ G d de      ZY w xY w)z.Define row constructs including :class:`.Row`.    N   )util)collections_abcsafe_rowproxy_reconstructorc                     t        | |      S Nr   )clsstates     H/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/engine/row.pyrowproxy_reconstructorr      s    *366    c                 J    | j                  |       }|j                  |       |S r	   )__new____setstate__)r
   r   objs      r   r   r   $   s#    kk#
r         )BaseRowTFc                   V    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZeZd Zd Zy)r   )_parent_data_keymap
_key_stylec                 n   t         j                  | d|       |rHt         j                  | dt        t        ||      D cg c]  \  }}|r ||      n| c}}             n t         j                  | dt        |             t         j                  | d|       t         j                  | d|       yc c}}w )z4Row objects are constructed by CursorResult objects.r   r   r   r   N)object__setattr__tuplezip)selfparent
processorskeymap	key_styledataprocvalues           r   __init__zBaseRow.__init__B   s     tY7"" 03:t/D +e ,0DKU:	 ""4%+>tY7t\9=s   B1c                 F    t         | j                  | j                         ffS r	   )r   	__class____getstate__r    s    r   
__reduce__zBaseRow.__reduce__Y   s$    &!2!2!45 r   c                 p    t        | j                  || j                  | j                  | j                        S r	   )Rowr   r   r   r   )r    filterss     r   _filter_on_valueszBaseRow._filter_on_values_   s.    

 r   c                     t        |       S r	   listr,   s    r   _values_implzBaseRow._values_implh   s    :r   c                 ,    t        | j                        S r	   )iterr   r,   s    r   __iter__zBaseRow.__iter__k       

##r   c                 ,    t        | j                        S r	   lenr   r,   s    r   __len__zBaseRow.__len__n   s    tzz?"r   c                 ,    t        | j                        S r	   )hashr   r,   s    r   __hash__zBaseRow.__hash__q   r9   r   c                      | j                   |   S r	   r   r    keys     r   _get_by_int_implzBaseRow._get_by_int_implt   s    ::c?"r   c                    t         |j                  j                  v r| j                  |   S | j                  t
        k(  r| j                  j                  |       	 | j                  |   }|t           }|| j                  j!                  |       n3| j                  t"        k(  r ||k7  r| j                  j%                  |       | j                  |   S # t        $ rS}t        |t              rt        | j                  |         cY d }~S | j                  j                  ||      }Y d }~d }~wt        $ r, t        |t              rt        | j                  |         cY S  w xY wr	   )intr*   __mro__r   r   KEY_INTEGER_ONLYr   _raise_for_nonintr   KeyError
isinstanceslicer   _key_fallback	TypeErrorMD_INDEX _raise_for_ambiguous_column_nameKEY_OBJECTS_BUT_WARN_warn_for_nonintr    rD   reckemdindexs        r   _get_by_key_implzBaseRow._get_by_key_implw   s   cmm+++zz#&"22..s3ll3' (mG==cB$88W^--c2::g&&%  >c5) C11,,44S"=C c5) C11	s*   C 	E"'D*E"	D**4E" E"c                 f   	 | j                   |   }|t           }|| j                  j                  |       n:| j                  t        k(  r't        |j                  j                  v rt        |      | j                  |   S # t        $ r&}| j                  j                  ||      }Y d }~d }~ww xY wr	   )r   rK   r   rN   rP   rQ   r   KEY_OBJECTS_ONLYrG   r*   rH   r   rT   s        r   _get_by_key_impl_mappingz BaseRow._get_by_key_impl_mapping   s    :ll3' (mG==cB#333==000sm#::g&&  :ll00b9:s   B 	B0
B++B0c                     	 | j                  |      S # t        $ r7}t        j                  t	        |j
                  d         |       Y d }~y d }~ww xY w)Nr   )replace_context)r[   rK   r   raise_AttributeErrorargs)r    namees      r   __getattr__zBaseRow.__getattr__   sI    J44T:: JN166!95qIIJs    	A-AAN)__name__
__module____qualname__	__slots__r(   r-   r1   r5   r8   r=   r@   rE   rX   __getitem__r[   rc    r   r   r   r   ?   sG    A		>.				$	#	$	#	'J '	'"	Jr   r   c                      e Zd ZdZdZeZd Zd Ze	d        Z
d Z ed      Z ed      Zd	 Zd
 Zd Zd Zej&                  Zd Zd Zd Zd Zd Zd Zd Z ej8                  dd      d        Ze	d        Zd Zd Z e	d        Z!y)r/   a  Represent a single result row.

    The :class:`.Row` object represents a row of a database result.  It is
    typically associated in the 1.x series of SQLAlchemy with the
    :class:`_engine.CursorResult` object, however is also used by the ORM for
    tuple-like results as of SQLAlchemy 1.4.

    The :class:`.Row` object seeks to act as much like a Python named
    tuple as possible.   For mapping (i.e. dictionary) behavior on a row,
    such as testing for containment of keys, refer to the :attr:`.Row._mapping`
    attribute.

    .. seealso::

        :ref:`tutorial_selecting_data` - includes examples of selecting
        rows from SELECT statements.

        :class:`.LegacyRow` - Compatibility interface introduced in SQLAlchemy
        1.4.

    .. versionchanged:: 1.4

        Renamed ``RowProxy`` to :class:`.Row`.  :class:`.Row` is no longer a
        "proxy" object in that it contains the final form of data within it,
        and now acts mostly like a named tuple.  Mapping-like functionality is
        moved to the :attr:`.Row._mapping` attribute, but will remain available
        in SQLAlchemy 1.x series via the :class:`.LegacyRow` class that is used
        by :class:`_engine.LegacyCursorResult`.
        See :ref:`change_4710_core` for background
        on this change.

    ri   c                     t        d      )Nzcan't set attributer_   )r    ra   r'   s      r   r   zRow.__setattr__   s    233r   c                     t        d      )Nzcan't delete attributerl   )r    ra   s     r   __delattr__zRow.__delattr__   s    566r   c                 x    t        | j                  d| j                  t         j                  | j                        S )a   Return a :class:`.RowMapping` for this :class:`.Row`.

        This object provides a consistent Python mapping (i.e. dictionary)
        interface for the data contained within the row.   The :class:`.Row`
        by itself behaves like a named tuple, however in the 1.4 series of
        SQLAlchemy, the :class:`.LegacyRow` class is still used by Core which
        continues to have mapping-like behaviors against the row object
        itself.

        .. seealso::

            :attr:`.Row._fields`

        .. versionadded:: 1.4

        N)
RowMappingr   r   _default_key_styler   r,   s    r   _mappingzRow._mapping   s2    $ LLLL))JJ
 	
r   c                 $     t          fd       }|S )z3Handle ambiguous names such as "count" and "index" c                 n      j                   j                        r j                        S  fd}|S )Nc                  L     t        t        j                        g| i |S r	   )getattrr   Sequence)argkwra   r    s     r   methz4Row._special_name_accessor.<locals>.go.<locals>.meth  s2    B7?#;#;TB"&( r   )r   _has_keyrc   )r    rz   ra   s   ` r   goz&Row._special_name_accessor.<locals>.go   s2    ||$$T*''--
 r   )property)ra   r|   s   ` r   _special_name_accessorzRow._special_name_accessor   s     

	 

	 	r   countindexc                     || j                   v S r	   rB   rC   s     r   __contains__zRow.__contains__  s    djj  r   c                 J    | j                   | j                  | j                  dS )Nr   r   r   r   r,   s    r   r+   zRow.__getstate__  s!    ||ZZ//
 	
r   c                     |d   }t         j                  | d|       t         j                  | d|d          t         j                  | d|j                         t         j                  | d|d          y )Nr   r   r   r   )r   r   r   )r    r   r!   s      r   r   zRow.__setstate__  sa    y!4F34%.94FNN;4u\/BCr   c                 |    t        |t              r |t        |       t        |            S  |t        |       |      S r	   )rL   r/   r   )r    otherops      r   _opzRow._op#  s<     %% uT{E%L)	
 E$K'	
r   c                 B    | j                  |t        j                        S r	   )r   operatorltr    r   s     r   __lt__z
Row.__lt__,      xxx{{++r   c                 B    | j                  |t        j                        S r	   )r   r   ler   s     r   __le__z
Row.__le__/  r   r   c                 B    | j                  |t        j                        S r	   )r   r   ger   s     r   __ge__z
Row.__ge__2  r   r   c                 B    | j                  |t        j                        S r	   )r   r   gtr   s     r   __gt__z
Row.__gt__5  r   r   c                 B    | j                  |t        j                        S r	   )r   r   eqr   s     r   __eq__z
Row.__eq__8  r   r   c                 B    | j                  |t        j                        S r	   )r   r   ner   s     r   __ne__z
Row.__ne__;  r   r   c                 >    t        t        j                  |             S r	   )reprsql_util	_repr_rowr,   s    r   __repr__zRow.__repr__>  s    H&&t,--r   z:meth:`.Row.keys`zqUse the namedtuple standard accessor :attr:`.Row._fields`, or for full mapping behavior use  row._mapping.keys() )alternativec                 .    | j                   j                  S )a  Return the list of keys as strings represented by this
        :class:`.Row`.

        The keys can represent the labels of the columns returned by a core
        statement or the names of the orm classes returned by an orm
        execution.

        This method is analogous to the Python dictionary ``.keys()`` method,
        except that it returns a list, not an iterator.

        .. seealso::

            :attr:`.Row._fields`

            :attr:`.Row._mapping`

        r   keysr,   s    r   r   zRow.keysA  s    0 ||   r   c                 l    t        | j                  j                  D cg c]  }||	 c}      S c c}w )a  Return a tuple of string keys as represented by this
        :class:`.Row`.

        The keys can represent the labels of the columns returned by a core
        statement or the names of the orm classes returned by an orm
        execution.

        This attribute is analogous to the Python named tuple ``._fields``
        attribute.

        .. versionadded:: 1.4

        .. seealso::

            :attr:`.Row._mapping`

        )r   r   r   )r    ks     r   _fieldszRow._fields[  s+    & !2!2DAamaDEEDs   11c                 ,    t        | j                        S )am  Return a new dict which maps field names to their corresponding
        values.

        This method is analogous to the Python named tuple ``._asdict()``
        method, and works by applying the ``dict()`` constructor to the
        :attr:`.Row._mapping` attribute.

        .. versionadded:: 1.4

        .. seealso::

            :attr:`.Row._mapping`

        )dictrr   r,   s    r   _asdictzRow._asdictp  s     DMM""r   c                     t               r	   NotImplementedErrorr,   s    r   _replacezRow._replace  s    !##r   c                     t               r	   r   r,   s    r   _field_defaultszRow._field_defaults  s    !##r   N)"rd   re   rf   __doc__rg   rR   rq   r   rn   r}   rr   r~   r   r   r   r+   r   r   r   r@   r   r   r   r   r   r   r   r   deprecated_20r   r   r   r   r   ri   r   r   r/   r/      s    B I .47 
 
2$ #7+E"7+E!
D
 H,,,,,,. T!!( F F(#"$ $ $r   r/   c                   6   e Zd ZdZdZej                  reZne	Zd Z
 ej                  dd      d        Z ej                  dd      d        Z ej                  dd	      d
        Z ej                  dd      d        Z ej                  dd      d        Zy)	LegacyRowa  A subclass of :class:`.Row` that delivers 1.x SQLAlchemy behaviors
    for Core.

    The :class:`.LegacyRow` class is where most of the Python mapping
    (i.e. dictionary-like)
    behaviors are implemented for the row object.  The mapping behavior
    of :class:`.Row` going forward is accessible via the :class:`.Row._mapping`
    attribute.

    .. versionadded:: 1.4 - added :class:`.LegacyRow` which encapsulates most
       of the deprecated behaviors of :class:`.Row`.

    ri   c                 :    | j                   j                  ||       S r	   )r   	_containsrC   s     r   r   zLegacyRow.__contains__  s    ||%%c400r   z1.4zThe :meth:`.LegacyRow.has_key` method is deprecated and will be removed in a future release.  To test for key membership, use the :attr:`Row._mapping` attribute, i.e. 'key in row._mapping`.c                 8    | j                   j                  |      S )a  Return True if this :class:`.LegacyRow` contains the given key.

        Through the SQLAlchemy 1.x series, the ``__contains__()`` method of
        :class:`.Row` (or :class:`.LegacyRow` as of SQLAlchemy 1.4)  also links
        to :meth:`.Row.has_key`, in that an expression such as ::

            "some_col" in row

        Will return True if the row contains a column named ``"some_col"``,
        in the way that a Python mapping works.

        However, it is planned that the 2.0 series of SQLAlchemy will reverse
        this behavior so that ``__contains__()`` will refer to a value being
        present in the row, in the way that a Python tuple works.

        .. seealso::

            :ref:`change_4710_core`

        r   r{   rC   s     r   has_keyzLegacyRow.has_key  s    8 ||$$S))r   zThe :meth:`.LegacyRow.items` method is deprecated and will be removed in a future release.  Use the :attr:`Row._mapping` attribute, i.e., 'row._mapping.items()'.c                 R    | j                         D cg c]	  }|| |   f c}S c c}w )zReturn a list of tuples, each tuple containing a key/value pair.

        This method is analogous to the Python dictionary ``.items()`` method,
        except that it returns a list, not an iterator.

        )r   rC   s     r   itemszLegacyRow.items  s'     -1IIK8Sd3i 888s   $zThe :meth:`.LegacyRow.iterkeys` method is deprecated and will be removed in a future release.  Use the :attr:`Row._mapping` attribute, i.e., 'row._mapping.keys()'.c                 @    t        | j                  j                        S )zReturn a an iterator against the :meth:`.Row.keys` method.

        This method is analogous to the Python-2-only dictionary
        ``.iterkeys()`` method.

        )r7   r   r   r,   s    r   iterkeyszLegacyRow.iterkeys  s     DLL%%&&r   zThe :meth:`.LegacyRow.itervalues` method is deprecated and will be removed in a future release.  Use the :attr:`Row._mapping` attribute, i.e., 'row._mapping.values()'.c                     t        |       S )zReturn a an iterator against the :meth:`.Row.values` method.

        This method is analogous to the Python-2-only dictionary
        ``.itervalues()`` method.

        )r7   r,   s    r   
itervalueszLegacyRow.itervalues  s     Dzr   zThe :meth:`.LegacyRow.values` method is deprecated and will be removed in a future release.  Use the :attr:`Row._mapping` attribute, i.e., 'row._mapping.values()'.c                 "    | j                         S )zReturn the values represented by this :class:`.Row` as a list.

        This method is analogous to the Python dictionary ``.values()`` method,
        except that it returns a list, not an iterator.

        )r5   r,   s    r   valueszLegacyRow.values  s       ""r   N)rd   re   rf   r   rg   r   SQLALCHEMY_WARN_20rR   rq   KEY_OBJECTS_NO_WARNr   
deprecatedr   r   r   r   r   ri   r   r   r   r     s     I101 T__	J**0 T__	399 T__	2'' T__	4 T__	4##r   r   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
ROMappingViewrr   _itemsc                      || _         || _        y r	   r   )r    mappingr   s      r   r(   zROMappingView.__init__  s    r   c                 ,    t        | j                        S r	   )r<   r   r,   s    r   r=   zROMappingView.__len__  s    4;;r   c                 $    dj                  |       S )Nz&{0.__class__.__name__}({0._mapping!r}))formatr,   s    r   r   zROMappingView.__repr__  s    7>>tDDr   c                 ,    t        | j                        S r	   )r7   r   r,   s    r   r8   zROMappingView.__iter__  s    DKK  r   c                     || j                   v S r	   )r   )r    items     r   r   zROMappingView.__contains__   s    t{{""r   c                 0    t        |      t        |       k(  S r	   r3   r   s     r   r   zROMappingView.__eq__#      E{d4j((r   c                 0    t        |      t        |       k7  S r	   r3   r   s     r   r   zROMappingView.__ne__&  r   r   N)rd   re   rf   rg   r(   r=   r   r8   r   r   r   ri   r   r   r   r   	  s-    
I
 E!#))r   r   c                   d    e Zd ZdZdZeZesej                  Z
d Zd Zd Zd Zd Zd Zd	 Zd
 Zy)rp   a  A ``Mapping`` that maps column names and objects to :class:`.Row`
    values.

    The :class:`.RowMapping` is available from a :class:`.Row` via the
    :attr:`.Row._mapping` attribute, as well as from the iterable interface
    provided by the :class:`.MappingResult` object returned by the
    :meth:`_engine.Result.mappings` method.

    :class:`.RowMapping` supplies Python mapping (i.e. dictionary) access to
    the  contents of the row.   This includes support for testing of
    containment of specific keys (string column names or objects), as well
    as iteration of keys, values, and items::

        for row in result:
            if 'a' in row._mapping:
                print("Column 'a': %s" % row._mapping['a'])

            print("Column b: %s" % row._mapping[table.c.b])


    .. versionadded:: 1.4 The :class:`.RowMapping` object replaces the
       mapping-like access previously provided by a database result row,
       which now seeks to behave mostly like a named tuple.

    ri   c                 ,    t        | j                        S r	   )r4   r   r,   s    r   r5   zRowMapping._values_implM  r9   r   c                 <    d | j                   j                  D        S )Nc              3   &   K   | ]	  }||  y wr	   ri   ).0r   s     r   	<genexpr>z&RowMapping.__iter__.<locals>.<genexpr>Q  s     >a>s   r   r,   s    r   r8   zRowMapping.__iter__P  s    >4<<,,>>r   c                 ,    t        | j                        S r	   r;   r,   s    r   r=   zRowMapping.__len__S  s    4::r   c                 8    | j                   j                  |      S r	   r   rC   s     r   r   zRowMapping.__contains__V  s    ||$$S))r   c                 *    t        t        |             S r	   )r   r   r,   s    r   r   zRowMapping.__repr__Y  s    DJr   c           	      f    t        | | j                         D cg c]	  }|| |   f c}      S c c}w )zeReturn a view of key/value tuples for the elements in the
        underlying :class:`.Row`.

        )r   r   rC   s     r   r   zRowMapping.items\  s.    
 T		#LS$s)$4#LMM#Ls   .
c                 .    | j                   j                  S )znReturn a view of 'keys' for string column names represented
        by the underlying :class:`.Row`.

        r   r,   s    r   r   zRowMapping.keysc  s     ||   r   c                 6    t        | | j                               S )zeReturn a view of values for the values represented in the
        underlying :class:`.Row`.

        )r   r5   r,   s    r   r   zRowMapping.valuesk  s    
 T4#4#4#677r   N)rd   re   rf   r   rg   rZ   rq   _baserow_usecextr   r[   rh   r5   r8   r=   r   r   r   r   r   ri   r   r   rp   rp   *  sK    4 I)66	$?* N!8r   rp   )r   r    r   sqlr   util.compatr   rP   sqlalchemy.cresultproxyr   r   ImportErrorrI   rZ   rR   r   r   r   r   rw   r/   r   BaseRowProxyRowProxyKeysView
ValuesView	ItemsViewr   Mappingrp   ri   r   r   <module>r      s   5   " ) D
7   H  N 2  {J/vP$'?++ P$fy# y#x ))BF8/11 F8Q  4  wJtJ& tJwJs"   	B! B/ !B,+B,/CC