U kf/@sdZddlmZddlmZddlmZddlZddlZddlm Z ddlm Z ddlm Z ddlm Z dd lm Z dd lmZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZeses*ddlmZn ddl mZer`ddl!m"Z"ddl!m#Z#ddl!m$Z$ede dZ%edee d fdZ&Gd!d"d"eee e e&Z'eZ(e'Z)Gd#d$d$eZ*Gd%d&d&e*ej+d'ej,e Z-Gd(d)d)e*ej.d'e fZ/Gd*d+d+eejd'e fZ0dS),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.c@seZdZdZdZddddddZddd d d Zd d ddZeddd d ddZ e d d ddZ e eddd d ddZ e dd ddZ ddddd Zesddd d!d"Zed#Zed$Zdd%d&d'd(Zdd)d%d*d+d,ZejZer2ed-dd.d/d0Zed1d2d.d3d0Zd4dd.d5d0Zdd%d6d7d8Zdd%d6d9d:Zdd%d6d;d<Zdd%d6d=d>Zdd%d6d?d@Zdd%d6dAdBZdd dCdDZe dEd dFdGZ dHd dIdJZ!dKS)LRowaRepresent 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. strrr )namevaluereturncCs tddS)Nzcan't set attributeAttributeError)selfr"r#r r E/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/engine/row.py __setattr__PszRow.__setattr__)r"r$cCs tddS)Nzcan't delete attributer%)r'r"r r r( __delattr__SszRow.__delattr__rr$cCs|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'r r r(_tupleVsz Row._tuplez2.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`.cCs|S)zUReturn a 'tuple' form of this :class:`.Row`. .. versionadded:: 2.0 )r-r,r r r(tuplens z Row.tuplecCs|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,r r r(_t}s zRow._tzThe :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`.cCs|jS)zKA synonym for :meth:`.Row._tuple`. .. versionadded:: 2.0 )r/r,r r r(tszRow.t RowMappingcCst|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)r1_parent _key_to_index_datar,r r r(_mappingsz Row._mappingzOptional[_ProcessorsType]zRow[Any]) processorr$cCst|j||j|jSN)rr2r3r4)r'r6r r r(_filter_on_valuesszRow._filter_on_valuescstdddfdd }|S)z3Handle ambiguous names such as "count" and "index" rr)r'r$cs6jrSddddfdd }|SdS)Nr)argkwr$csttjf||Sr7)getattrcollections_abcr)r9r:)r"r'r r(meths z4Row._special_name_accessor..go..meth)r2_has_key __getattr__)r'r=r"r,r(gos  z&Row._special_name_accessor..go)property)r"rAr r@r(_special_name_accessors zRow._special_name_accessorcountindexboolkeyr$cCs ||jkSr7)r4r'rHr r r( __contains__szRow.__contains__zCallable[[Any, Any], bool])otheropr$cCs*t|tr|||S|||Sr7) isinstancerZ_to_tuple_instance)r'rKrLr r r(_ops zRow._opint)rEr$cCsdSr7r r'rEr r r( __getitem__szRow.__getitem__slice Sequence[Any]cCsdSr7r rPr r r(rQszUnion[int, slice]cCsdSr7r rPr r r(rQrKr$cCs||tjSr7)rNoperatorltr'rKr r r(__lt__sz Row.__lt__cCs||tjSr7)rNrVlerXr r r(__le__sz Row.__le__cCs||tjSr7)rNrVgerXr r r(__ge__sz Row.__ge__cCs||tjSr7)rNrVgtrXr r r(__gt__sz Row.__gt__cCs||tjSr7)rNrVeqrXr r r(__eq__sz Row.__eq__cCs||tjSr7)rNrVnerXr r r(__ne__sz Row.__ne__cCstt|Sr7)reprsql_utilZ _repr_rowr,r r r(__repr__sz Row.__repr__zTuple[str, ...]cCstdd|jjDS)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` cSsg|]}|dk r|qSr7r .0kr r r( szRow._fields..)r.r2keysr,r r r(_fieldssz Row._fieldszDict[str, Any]cCs 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` )dictr5r,r r r(_asdict sz Row._asdictN)"__name__ __module__ __qualname____doc__ __slots__r)r*r-rr.rBr/r0r5r8rrCrDrErJrNr__hash__r rQrYr[r]r_rarcrfrlrnr r r r(r2sXrc@seZdZUdZded<ded<dddddZd d d d Zd d ddZdd ddZdddddZ dddddZ dddddZ dS) ROMappingViewr rS_itemszMapping['_KeyType', Any]r5)mappingitemscCs||_||_dSr7)r5rv)r'rwrxr r r(__init__%szROMappingView.__init__rOr+cCs t|jSr7)lenrvr,r r r(__len__+szROMappingView.__len__r!cCs d|S)Nz&{0.__class__.__name__}({0._mapping!r}))formatr,r r r(rf.szROMappingView.__repr__z Iterator[Any]cCs t|jSr7)iterrvr,r r r(__iter__1szROMappingView.__iter__rrF)itemr$cCs ||jkSr7rv)r'rr r r(rJ4szROMappingView.__contains__rUcCst|t|kSr7listrXr r r(ra7szROMappingView.__eq__cCst|t|kSr7rrXr r r(rc:szROMappingView.__ne__N) rorprqrs__annotations__ryr{rfr~rJrarcr r r r(rus ruc@seZdZdZdS)ROMappingKeysValuesViewrNrorprqrsr r r r(r>srrc@seZdZdZdS)ROMappingItemsViewrNrr r r r(rDsrc@seZdZdZdZer&dddddZnejZdd d d Z d d d dZ dd ddZ dddddZ dd ddZ dd ddZdd ddZdd d d!Zd"S)#r1aA ``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 rrrGcCsdSr7r rIr r r(rQgrTzRowMapping.__getitem__z List[Any]r+cCs t|jSr7)rr4r,r r r( _values_impllszRowMapping._values_implz Iterator[str]cCsdd|jjDS)Ncss|]}|dk r|VqdSr7r rgr r r( psz&RowMapping.__iter__..r2rkr,r r r(r~oszRowMapping.__iter__rOcCs t|jSr7)rzr4r,r r r(r{rszRowMapping.__len__objectrFcCs |j|Sr7)r2r>rIr r r(rJuszRowMapping.__contains__r!cCs tt|Sr7)rdrmr,r r r(rfxszRowMapping.__repr__rcstfddDS)zeReturn a view of key/value tuples for the elements in the underlying :class:`.Row`. csg|]}||fqSr r )rhrHr,r r(rjsz$RowMapping.items..)rrkr,r r,r(rx{szRowMapping.itemsrcCs|jjS)znReturn a view of 'keys' for string column names represented by the underlying :class:`.Row`. rr,r r r(rkszRowMapping.keysrcCst||S)zeReturn a view of values for the values represented in the underlying :class:`.Row`. )rrr,r r r(valuesszRowMapping.valuesN)rorprqrrrsrrQrZ_get_by_key_impl_mappingrr~r{rJrfrxrkrr r r r(r1Hs r1)1rr __future__rabcrcollections.abcr<rVtypingrrrrrr r r r r rrrrrsqlrrerZ util._has_cyrZ_py_rowrZ"sqlalchemy.cyextension.resultproxyresultrrrrrrZ BaseRowProxyZRowProxyruKeysView ValuesViewr ItemsViewrr1r r r r(sX                           j