L i.dZddlmZddlmZddlmZddlZddlZddlm Z ddlm Z ddlm Z ddlm Z dd lm Z dd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZesesddlmZnddl mZerddl!m"Z"ddl!m#Z#ddl!m$Z$ede Z%edee d fZ&Gd!d"eee e e&Z'eZ(e'Z)Gd#d$eZ*Gd%d&e*ejVd'ejXe Z-Gd(d)e*ej\d'e fZ/Gd*d+eejd'e fZ0y),z.Define row constructs including :class:`.Row`.) annotations)ABCN)Any)Callable)Dict)Generic)Iterator)List)Mapping)NoReturn)Optional)overload)Sequence)Tuple) TYPE_CHECKING)TypeVar)Union)util) deprecated)HAS_CYEXTENSION)BaseRow)_KeyType)_ProcessorsType) RMKeyView_T)bound_TP.ceZdZdZdZd dZd!dZd"dZeddd"dZ e d"d Z e edd d"d Z e d#d Z d$d Zesd%dZedZedZd&dZd'dZej,Zered(dZed)dZd*dZd+dZd+dZd+dZd+dZd+dZd+dZd,dZe d-dZ d.dZ!y)/RowaRepresent 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. .. 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. See :ref:`change_4710_core` for background on this change. ctd)Nzcan't set attributeAttributeError)selfnamevalues [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/engine/row.py __setattr__zRow.__setattr__Ps233ctd)Nzcan't delete attributer$)r&r's r) __delattr__zRow.__delattr__Ss566r+c|S)a5Return a 'tuple' form of this :class:`.Row`. At runtime, this method returns "self"; the :class:`.Row` object is already a named tuple. However, at the typing level, if this :class:`.Row` is typed, the "tuple" return type will be a :pep:`484` ``Tuple`` datatype that contains typing information about individual elements, supporting typed unpacking and attribute access. .. versionadded:: 2.0.19 - The :meth:`.Row._tuple` method supersedes the previous :meth:`.Row.tuple` method, which is now underscored to avoid name conflicts with column names in the same way as other named-tuple methods on :class:`.Row`. .. seealso:: :attr:`.Row._t` - shorthand attribute notation :meth:`.Result.tuples` r"r&s r)_tuplez Row._tupleVs , r+z2.0.19zThe :meth:`.Row.tuple` method is deprecated in favor of :meth:`.Row._tuple`; all :class:`.Row` methods and library-level attributes are intended to be underscored to avoid name conflicts. Please use :meth:`Row._tuple`.c"|jS)zUReturn a 'tuple' form of this :class:`.Row`. .. versionadded:: 2.0 )r0r/s r)tuplez Row.tuplens{{}r+c|S)awA synonym for :meth:`.Row._tuple`. .. versionadded:: 2.0.19 - The :attr:`.Row._t` attribute supersedes the previous :attr:`.Row.t` attribute, which is now underscored to avoid name conflicts with column names in the same way as other named-tuple methods on :class:`.Row`. .. seealso:: :attr:`.Result.t` r"r/s r)_tzRow._t}s  r+zThe :attr:`.Row.t` attribute is deprecated in favor of :attr:`.Row._t`; all :class:`.Row` methods and library-level attributes are intended to be underscored to avoid name conflicts. Please use :attr:`Row._t`.c|jS)zKA synonym for :meth:`.Row._tuple`. .. versionadded:: 2.0 )r4r/s r)tzRow.ts wwr+cZt|jd|j|jS)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. .. seealso:: :attr:`.Row._fields` .. versionadded:: 1.4 N) RowMapping_parent _key_to_index_datar/s r)_mappingz Row._mappings#$,,d.@.@$**MMr+cZt|j||j|jSN)r!r9r:r;)r& processors r)_filter_on_valueszRow._filter_on_valuess#4<<D,>,> KKr+c&tdfd }|S)z3Handle ambiguous names such as "count" and "index" cpjjrjSdfd }|S)NcLttjg|i|Sr>)getattrcollections_abcr)argkwr'r&s r)methz4Row._special_name_accessor..go..meths2Fw'?'?F  #& *, r+)rFrrGrreturnr)r9_has_key __getattr__)r&rHr's` r)goz&Row._special_name_accessor..gos2<<((.++D11  Kr+)r&r!rIr)property)r'rLs` r)_special_name_accessorzRow._special_name_accessors  Ir+countindexc||jvSr>)r;r&keys r) __contains__zRow.__contains__sdjj  r+ct|tr%||j|jS||j|Sr>) isinstancer!_to_tuple_instance)r&otherops r)_opzRow._opsK%% t&&(%*B*B*D E D++-u5 r+cyr>r"r&rPs r) __getitem__zRow.__getitem__s25r+cyr>r"r\s r)r]zRow.__getitem__s>Ar+cyr>r"r\s r)r]zRow.__getitem__r+cB|j|tjSr>)rZoperatorltr&rXs r)__lt__z Row.__lt__xxx{{++r+cB|j|tjSr>)rZrblerds r)__le__z Row.__le__rfr+cB|j|tjSr>)rZrbgerds r)__ge__z Row.__ge__rfr+cB|j|tjSr>)rZrbgtrds r)__gt__z Row.__gt__rfr+cB|j|tjSr>)rZrbeqrds r)__eq__z Row.__eq__rfr+cB|j|tjSr>)rZrbnerds r)__ne__z Row.__ne__rfr+c>ttj|Sr>)reprsql_util _repr_rowr/s r)__repr__z Row.__repr__sH&&t,--r+clt|jjDcgc]}|| c}Scc}w)aReturn 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` )r2r9keys)r&ks r)_fieldsz Row._fieldss+&!2!2DAamaDEEDs11c,t|jS)amReturn 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` )dictr<r/s r)_asdictz Row._asdict sDMM""r+N)r'strr(rrIr )r'rrIr )rIr)rIr8)r?zOptional[_ProcessorsType]rIzRow[Any])r'rrIr)rSrrIbool)rXrrYzCallable[[Any, Any], bool]rIr)rPintrIr)rPslicerI Sequence[Any])rPzUnion[int, slice]rIrrXrrIrrIr)rIzTuple[str, ...])rIzDict[str, Any])"__name__ __module__ __qualname____doc__ __slots__r*r-r0rr2rMr4r6r<r@rrNrOrPrTrZr__hash__rr]rerirlrorrrurzr~rr"r+r)r!r!2sA6I470 C   ?NN L2L L  $'w/&w/! H 5 5 A AC,,,,,,.FF(#r+r!cfeZdZUdZded<ded< ddZddZddZdd Zdd Z dd Z dd Z y ) ROMappingViewr"r_itemsMapping['_KeyType', Any]r<c ||_||_yr>)r<r)r&mappingitemss r)__init__zROMappingView.__init__%s   r+c,t|jSr>)lenrr/s r)__len__zROMappingView.__len__+s4;;r+c$dj|S)Nz&{0.__class__.__name__}({0._mapping!r}))formatr/s r)rzzROMappingView.__repr__.s7>>tDDr+c,t|jSr>)iterrr/s r)__iter__zROMappingView.__iter__1sDKK  r+c||jvSr>r)r&items r)rTzROMappingView.__contains__4st{{""r+c0t|t|k(Sr>listrds r)rrzROMappingView.__eq__7E{d4j((r+c0t|t|k7Sr>rrds r)ruzROMappingView.__ne__:rr+N)rrrrrIrr)rIz Iterator[Any])rrrIrr) rrrr__annotations__rrrzrrTrrrur"r+r)rrsGI &&/8E  E!#))r+rceZdZdZy)ROMappingKeysValuesViewrNrrrrr"r+r)rr>s Ir+rrceZdZdZy)ROMappingItemsViewrNrr"r+r)rrDsIr+rczeZdZdZdZerd dZn ejZddZ ddZ ddZ ddZ ddZ dd Zdd Zdd Zy )r8aA ``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. r"cyr>r"rRs r)r]zRowMapping.__getitem__fr`r+c,t|jSr>)rr;r/s r) _values_implzRowMapping._values_implksDJJr+c<d|jjDS)Nc3&K|] }|| ywr>r").0r}s r) z&RowMapping.__iter__..os>a >sr9r|r/s r)rzRowMapping.__iter__ns>4<<,,>>r+c,t|jSr>)rr;r/s r)rzRowMapping.__len__qs4::r+c8|jj|Sr>)r9rJrRs r)rTzRowMapping.__contains__ts||$$S))r+c*tt|Sr>)rwrr/s r)rzzRowMapping.__repr__wsDJr+c ft||jDcgc] }|||f c}Scc}w)zeReturn a view of key/value tuples for the elements in the underlying :class:`.Row`. )rr|rRs r)rzRowMapping.itemszs3 " tyy{;Cc#;  ;s. c.|jjS)znReturn a view of 'keys' for string column names represented by the underlying :class:`.Row`. rr/s r)r|zRowMapping.keyss ||   r+c6t||jS)zeReturn a view of values for the values represented in the underlying :class:`.Row`. )rrr/s r)valueszRowMapping.valuess 'tT->->-@AAr+N)rSrrIr)rIz List[Any])rIz Iterator[str]r)rSobjectrIrr)rIr)rIr)rIr)rrrrrrr]r_get_by_key_impl_mappingrrrrTrzrr|rr"r+r)r8r8HsJ2I866  ?*  !Br+r8)1r __future__rabcrcollections.abcrErbtypingrrrrr r r r r rrrrrrsqlrrxr util._has_cyr_py_rowr"sqlalchemy.cyextension.resultproxyresultrrrrrr! BaseRowProxyRowProxyrKeysView ValuesViewr ItemsViewrr8r"r+r)rs5")  "*+E '! T e5c?+f#'8C='#,f#R )C)>6??:.0A0A#0F (8(8S(IHB&..S9HBr+