U apI@sdZddlZddlmZddlmZddlmZdZzddl m Z ddZ Wne k rhd dZ YnXdZ d ZdZd Zzdd l mZd ZWn(e k rdZGdddeZYnXGdddeejZGdddeZeZeZGdddejejejZGdddeejZdS)z.Define row constructs including :class:`.Row`.N)util)collections_abcsafe_rowproxy_reconstructorcCs t||SNr)clsstater VC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\engine\row.pyrowproxy_reconstructorsr cCs||}|||Sr)__new__ __setstate__)rr objr r r r $s  )BaseRowTFc@sleZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ e Z ddZddZdS)r_parent_data_keymap _key_stylecCs@||_|r&tddt||D|_n t||_||_||_dS)z4Row objects are constructed by CursorResult objects.cSs g|]\}}|r||n|qSr r ).0procvaluer r r Isz$BaseRow.__init__..N)rtupleziprrr)selfparentZ processorsZkeymapZ key_styledatar r r __init__Bs zBaseRow.__init__cCst|j|ffSr)r __class__ __getstate__rr r r __reduce__Us zBaseRow.__reduce__cCst|j||j|j|jSr)Rowrrrr)rfiltersr r r _filter_on_values[szBaseRow._filter_on_valuescCst|Srlistr$r r r _values_impldszBaseRow._values_implcCs t|jSr)iterrr$r r r __iter__gszBaseRow.__iter__cCs t|jSrlenrr$r r r __len__jszBaseRow.__len__cCs t|jSr)hashrr$r r r __hash__mszBaseRow.__hash__cCs |j|Srrrkeyr r r _get_by_int_implpszBaseRow._get_by_int_implc Cst|jjkr|j|S|jtkr,|j|z|j|}Wn`t k rj}z|j ||}W5d}~XYn2t k rt |t rt|j|YSYnX|t}|dkr|j|n|jtkr||kr|j||j|Sr)intr"__mro__rrKEY_INTEGER_ONLYrZ_raise_for_nonintrKeyError _key_fallback TypeError isinstanceslicerMD_INDEX _raise_for_ambiguous_column_nameKEY_OBJECTS_BUT_WARNZ_warn_for_nonintrr5ZrecZkeZmdindexr r r _get_by_key_implss$      zBaseRow._get_by_key_implc Csz|j|}Wn0tk r>}z|j||}W5d}~XYnX|t}|dkr^|j|n|jtkr|t|j j kr|t||j |Sr) rr:rr;r?r@rKEY_OBJECTS_ONLYr7r"r8rrBr r r _get_by_key_impl_mappings  z BaseRow._get_by_key_impl_mappingc CsLz ||WStk rF}ztjt|jd|dW5d}~XYnXdS)Nr)Zreplace_context)rEr:rZraise_AttributeErrorargs)rnameer r r __getattr__s zBaseRow.__getattr__N)__name__ __module__ __qualname__ __slots__r!r%r(r+r-r0r2r6rC __getitem__rErJr r r r r?s "rc@seZdZdZdZeZeddZddZ e dZ e dZ d d Z d d Z d dZddZejZddZddZddZddZddZddZddZejdd d!d"d#Zed$d%Zd&d'Zd(d)Zed*d+Zd,S)-r&aRepresent 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:`coretutorial_selecting` - 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. r cCst|jd|jtj|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, 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) RowMappingrr_default_key_stylerr$r r r _mappingsz Row._mappingcstfdd}|S)z3Handle ambiguous names such as "count" and "index" cs,jrSfdd}|SdS)Ncsttjf||Sr)getattrrSequence)argkw)rHrr r meths z4Row._special_name_accessor..go..meth)r_has_keyrJ)rrWrHr$r gos  z&Row._special_name_accessor..go)property)rHrZr rYr _special_name_accessors zRow._special_name_accessorcountindexcCs ||jkSrr3r4r r r __contains__szRow.__contains__cCs|j|j|jdS)Nrrrr`r$r r r r#szRow.__getstate__cCs.|d|_}|d|_|j|_|d|_dS)Nrrrr)rr rr r r rs zRow.__setstate__cCs*t|tr|t|t|S|t||Sr)r=r&r)rotheropr r r _ops zRow._opcCs||tjSr)rcoperatorltrrar r r __lt__sz Row.__lt__cCs||tjSr)rcrdlerfr r r __le__!sz Row.__le__cCs||tjSr)rcrdgerfr r r __ge__$sz Row.__ge__cCs||tjSr)rcrdgtrfr r r __gt__'sz Row.__gt__cCs||tjSr)rcrdeqrfr r r __eq__*sz Row.__eq__cCs||tjSr)rcrdnerfr r r __ne__-sz Row.__ne__cCstt|Sr)reprsql_utilZ _repr_rowr$r r r __repr__0sz Row.__repr__z:meth:`.Row.keys`zqUse the namedtuple standard accessor :attr:`.Row._fields`, or for full mapping behavior use row._mapping.keys() ) alternativecCs|jjS)aReturn 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` rkeysr$r r r rw3szRow.keyscCstdd|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|qSrr rkr r r r`szRow._fields..)rrrwr$r r r _fieldsMsz Row._fieldscCs 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` )dictrRr$r r r _asdictbsz Row._asdictcCs tdSrNotImplementedErrorr$r r r _replacessz Row._replacecCs tdSrr}r$r r r _field_defaultsvszRow._field_defaultsN) rKrLrM__doc__rNrArQr[rRr\r]r^r_r#rrcrr2rgrirkrmrorqrtrZ deprecated_20rwrzr|rrr r r r r&s>!   r&c@seZdZdZdZejreZne ZddZ e ddddZ e dd d d Z e dd d dZe ddddZe ddddZdS) LegacyRowaA 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`. r cCs|j||Sr)rZ _containsr4r r r r_szLegacyRow.__contains__z1.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`.cCs |j|S)aReturn 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` rrXr4r r r has_keyszLegacyRow.has_keyzThe :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()'.csfddDS)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. csg|]}||fqSr r rr5r$r r rsz#LegacyRow.items..)rwr$r r$r itemsszLegacyRow.itemszThe :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()'.cCs t|jjS)zReturn a an iterator against the :meth:`.Row.keys` method. This method is analogous to the Python-2-only dictionary ``.iterkeys()`` method. )r,rrwr$r r r iterkeyss zLegacyRow.iterkeyszThe :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()'.cCst|S)zReturn a an iterator against the :meth:`.Row.values` method. This method is analogous to the Python-2-only dictionary ``.itervalues()`` method. )r,r$r r r itervaluess zLegacyRow.itervalueszThe :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()'.cCs|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. )r+r$r r r valuesszLegacyRow.valuesN)rKrLrMrrNrZSQLALCHEMY_WARN_20rArQKEY_OBJECTS_NO_WARNr_ deprecatedrrrrrr r r r r{s>     rc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS) ROMappingViewrR_itemscCs||_||_dSrr)rmappingrr r r r!szROMappingView.__init__cCs t|jSr)r/rr$r r r r0 szROMappingView.__len__cCs d|S)Nz&{0.__class__.__name__}({0._mapping!r}))formatr$r r r rt szROMappingView.__repr__cCs t|jSr)r,rr$r r r r-szROMappingView.__iter__cCs ||jkSr)r)ritemr r r r_szROMappingView.__contains__cCst|t|kSrr)rfr r r roszROMappingView.__eq__cCst|t|kSrr)rfr r r rqszROMappingView.__ne__N) rKrLrMrNr!r0rtr-r_rorqr r r r rsrc@sbeZdZdZdZeZes&ej Z ddZ ddZ ddZ d d Zd d Zd dZddZddZdS)rPaA ``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 cCs t|jSr)r*rr$r r r r+>szRowMapping._values_implcCsdd|jjDS)Ncss|]}|dk r|VqdSrr rxr r r Bsz&RowMapping.__iter__..rvr$r r r r-AszRowMapping.__iter__cCs t|jSrr.r$r r r r0DszRowMapping.__len__cCs |j|Srrr4r r r r_GszRowMapping.__contains__cCs tt|Sr)rrr{r$r r r rtJszRowMapping.__repr__cstfddDS)zeReturn a view of key/value tuples for the elements in the underlying :class:`.Row`. csg|]}||fqSr r rr$r r rRsz$RowMapping.items..)rrwr$r r$r rMszRowMapping.itemscCs|jjS)znReturn a view of 'keys' for string column names represented by the underlying :class:`.Row`. rvr$r r r rwTszRowMapping.keyscCst||S)zeReturn a view of values for the values represented in the underlying :class:`.Row`. )rr+r$r r r r\szRowMapping.valuesN)rKrLrMrrNrDrQ_baserow_usecextrrErOr+r-r0r_rtrrwrr r r r rPsrP)rrdrZsqlrsZ util.compatrr?Zsqlalchemy.cresultproxyrr ImportErrorr9rDrArrrobjectrTr&rZ BaseRowProxyZRowProxyKeysView ValuesView ItemsViewrMappingrPr r r r s>      pM| !