U kfJk@sdZddlmZddlmZddlZddlZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ejrddlm$Z$ddlm%Z%ddlm&Z&dd l'm(Z(dd!l)m*Z*dd"l+m,Z,dd#l-m.Z.dd$l/m0Z0dd%l1m2Z2dd&lm3Z3dd'l4m5Z5dd(l6m7Z7dd)l6m8Z8dd*lm9Z9dd+l:m;Z;ed,ed-Zd-Z?Gd2d3d3eZ@eAe@\ZBZCZDZEZFeFZGGd4d5d5eZHeHjIJ\ZKZLZMZNZOZPZQZRZSZTZUZVZWZXZYZZZ[Z\d6Z]d7Z^Gd8d9d9eZ_eAe_\Z`ZaZbZcGd:d;d;eZdeAed\ZeZfZgGdd?d?ehZiejeGgZkejdeGeBgZlemd@ZnemdAZoemdBZpedCedDefd-ZqedEZrdFdGdHdIdJZserdKdLdMdNdOZte dPdQdMdRdSZue dTdUdMdVdSZudTdUdMdWdSZud1dXdYdZd[Zvd\d]dYd^d_Zwn$d`dOZtdadSZuexe^ZvexdbZwd\dcdYdddeZydfdcdgdhdiZzdfdcdgdjdkZ{d\dcdcdldmdnZ|dfdcdcdodpdqZ}d,drdYdsdtZ~d,dudYdvdwZee>d,dxdYdydzZd{drd|d}d~ZdddddZdFddddZdFddddZe ddcdFdddZerdXddgddZn edZddKdddddZdddddZddKdddddZGdddZGdddeZGdddee=e!ZGddde e=e!ZGddde e=e!ZGdddee=ee=e!ZGdddee=ee=ee=ejZGddde e=e!ZGdddee=ee=ZGdddee=ZGdddee=ZdS)z=Constants and rudimental functions used throughout the ORM. ) annotations)EnumN)Any)Callable)Dict)Generic) no_type_check)Optional)overload)Tuple)Type) TYPE_CHECKING)TypeVar)Union)exc)insp_is_mapper) inspection)util)roles)SQLColumnExpression)SQLCoreOperations) FastIntFlag) TypingOnly)Literal) _EntityType)_ExternalEntityType)_InternalEntityType)InstrumentedAttribute) AppenderQuery) ClassManager)PropComparator)Mapper) InstanceState) AliasedClass)WriteOnlyCollection)_ColumnExpressionArgument) _InfoType) ColumnElement) OperatorType_T)bound_T_coT)r, covariant_Oc@s$eZdZdZdZdZdZdZeZdS)LoaderCallableStatusrrrN) __name__ __module__ __qualname__PASSIVE_NO_RESULTPASSIVE_CLASS_MISMATCH ATTR_WAS_SET ATTR_EMPTYNO_VALUE NEVER_SETr<r<C/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/orm/base.pyr0Asr0c@seZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zee BeBeBeBZeeAZeeAZeeAZeeAZee AZee BZd S) PassiveFlagz;Bitflag interface that passes options onto loader callablesrrrr2 @iN)r3r4r5__doc__ NO_CHANGE CALLABLES_OKSQL_OKRELATED_OBJECT_OKINIT_OKNON_PERSISTENT_OKLOAD_AGAINST_COMMITTED NO_AUTOFLUSHNO_RAISEDEFERRED_HISTORY_LOADINCLUDE_PENDING_MUTATIONS PASSIVE_OFFPASSIVE_RETURN_NO_VALUEPASSIVE_NO_INITIALIZEPASSIVE_NO_FETCHPASSIVE_NO_FETCH_RELATEDPASSIVE_ONLY_PERSISTENT PASSIVE_MERGEr<r<r<r=r>ps*r>Z_sa_class_managerZ_sa_instance_statec@seZdZdZdZdZdZdS)EventConstantsrrr1r2N)r3r4r5 EXT_CONTINUEEXT_STOPEXT_SKIPNO_KEYr<r<r<r=rXs rXc@seZdZdZdZdZdZdS)RelationshipDirectionzenumeration which indicates the 'direction' of a :class:`_orm.RelationshipProperty`. :class:`.RelationshipDirection` is accessible from the :attr:`_orm.Relationship.direction` attribute of :class:`_orm.RelationshipProperty`. rrr1N)r3r4r5rE ONETOMANY MANYTOONE MANYTOMANYr<r<r<r=r]s  r]c@seZdZdZdS)InspectionAttrExtensionTypezXSymbols indicating the type of extension that a :class:`.InspectionAttr` is part of.N)r3r4r5rEr<r<r<r=ra srac@seZdZdZdS) NotExtensionZ not_extensionN)r3r4r5 NOT_EXTENSIONr<r<r<r=rbsrbZSET_DEFERRED_EXPIREDZDEFER_FOR_STATEZRAISE_FOR_STATE_F._SelfrzCallable[[_F], _F]) assertionsreturncs$tjddddddfdd }|S)Nrdrer)fnselfargskwrgcs*D]}|||jq||f|||SN)r3)rhrirjrkZ assertionrfr<r=generate,sz_assertions..generate)r decorator)rfrnr<rmr= _assertions)srpzType[_O]zClassManager[_O])clsrgcCsdSrlr<rqr<r<r=manager_of_class8rszAliasedClass[Any]NonecCsdSrlr<rrr<r<r=opt_manager_of_class:srvz_ExternalEntityType[_O]zOptional[ClassManager[_O]]cCsdSrlr<rrr<r<r=rv=scCsdSrlr<rrr<r<r=rvBszInstanceState[_O]instancergcCsdSrlr<rxr<r<r=instance_stateFrtrzobjectzDict[str, Any]cCsdSrlr<ryr<r<r= instance_dictHrtr|c CsHz |jtWStk rB}zt|d||W5d}~XYnXdS)Nz2Can't locate an instrumentation manager for class )__dict__DEFAULT_MANAGER_ATTRKeyErrorrUnmappedClassError)rqZker<r<r=rsNs cCs |jtSrl)r}getr~rrr<r<r=rvVsr}strcCs tt|S)z'Return a string describing an instance.) state_strrzryr<r<r= instance_str^srzInstanceState[Any])statergcCs(|dkr dSd|jjt|fSdS)z=Return a string describing an instance via its InstanceState.Nruz <%s at 0x%x>)class_r3idobjrr<r<r=rdsrcCs|dkr dSd|jjfSdS)zNReturn a string describing an instance's class via its InstanceState. Nruz<%s>)rr3rr<r<r=state_class_strmsr)rx attributergcCst|d|SN.)r)rxrr<r<r= attribute_strxsr)rrrgcCst|d|Sr)r)rrr<r<r=state_attribute_str|srz Mapper[_T]cCs t|jS)aGiven an object, return the primary Mapper associated with the object instance. Raises :class:`sqlalchemy.orm.exc.UnmappedInstanceError` if no mapping is configured. This function is available via the inspection system as:: inspect(instance).mapper Using the inspection system will raise :class:`sqlalchemy.exc.NoInspectionAvailable` if the instance is not part of a mapping. ) object_statemapperryr<r<r= object_mappersrzInstanceState[_T]cCs$t|}|dkrt|n|SdS)aGiven an object, return the :class:`.InstanceState` associated with the object. Raises :class:`sqlalchemy.orm.exc.UnmappedInstanceError` if no mapping is configured. Equivalent functionality is available via the :func:`_sa.inspect` function as:: inspect(instance) Using the inspection system will raise :class:`sqlalchemy.exc.NoInspectionAvailable` if the instance is not part of a mapping. N)_inspect_mapped_objectrZUnmappedInstanceError)rxrr<r<r=rs rzOptional[InstanceState[_T]]c Cs0z t|WStjftjk r*YdSXdSrl)rzrrNO_STATEryr<r<r=rs rzUnion[Mapper[_T], Type[_T]])class_or_mapperrgcCs6t|d}|dk r|jSt|ts(tt|dS)NF)rinspectr isinstancetypeAssertionErrorrr)rinspr<r<r=_class_to_mappers  rz(Union[Type[_T], _InternalEntityType[_T]]zOptional[Mapper[_T]])entityrgcCs"t|d}|dk r|jSdSdS)z`Return the :class:`_orm.Mapper` for the given class or None if the class is not mapped. FN)rrrrrr<r<r=_mapper_or_nones rboolcCs(t|d}|dk o&|j o&|jp&|jS)zlReturn True if the given object is a mapped class, :class:`_orm.Mapper`, or :class:`.AliasedClass`. FN)rris_clause_element is_mapperis_aliased_classrr<r<r=_is_mapped_classs   rcCs t|d}|dk ot|ddS)NFr)rrgetattrrr<r<r=_is_aliased_classs r_EntityType[Any])rkeyrgc Cst|}|jr|}|j}n.|jr.|j}|}nt|drF|jj}}n|}z t ||WSt k r}zt d||f|W5d}~XYnXdS)zReturn a class attribute given an entity and string name. May return :class:`.InstrumentedAttribute` or user-defined attribute. rz Entity '%s' has no property '%s'N) rr is_selectablecrrhasattrrrrAttributeErrorsa_excZInvalidRequestError)rrr descriptionerrr<r<r=_entity_descriptors$    rz Mapper[_O]cCsdSrlr<rr<r<r= _state_mapperrtrzmanager.mapperFzOptional[Mapper[_O]])r configurergcCsTz&t|}|dks|jsWdS|j}Wntjk r>YdSX|rL||SdSrl)rvZ is_mappedrrrZ_check_configure)rrZ class_managerrr<r<r=_inspect_mapped_classs rzUnion[Mapper[_O], Type[_O]])argrgcCs.tj|dd}t|r|Std|dS)NF)Zraiseerrz%Mapper or mapped class expected, got )rrrr ArgumentError)rrr<r<r=_parse_mapper_argumentsrcCsBt||d}|dkr:t|ts.td|ft|n|SdS)aGiven a class, return the primary :class:`_orm.Mapper` associated with the key. Raises :exc:`.UnmappedClassError` if no mapping is configured on the given class, or :exc:`.ArgumentError` if a non-class object is passed. Equivalent functionality is available via the :func:`_sa.inspect` function as:: inspect(some_mapped_class) Using the inspection system will raise :class:`sqlalchemy.exc.NoInspectionAvailable` if the class is not mapped. )rNz Class object expected, got '%r'.)rrrrrrr)rrrr<r<r= class_mappers   rc@sPeZdZUdZdZded<dZdZdZdZ dZ dZ dZ dZ dZejZded<dS) InspectionAttraMA base class applied to all ORM objects and attributes that are related to things that can be returned by the :func:`_sa.inspect` function. The attributes defined here allow the usage of simple boolean checks to test basic facts about the object returned. While the boolean checks here are basically the same as using the Python isinstance() function, the flags here can be used without the need to import all of these classes, and also such that the SQLAlchemy class system can change while leaving the flags here intact for forwards-compatibility. r<zTuple[str, ...] __slots__Fraextension_typeN)r3r4r5rEr__annotations__rrZ is_instancerZ is_bundleZ is_propertyZ is_attributeZ_is_internal_proxyrrbrcrr<r<r<r=r8s  rc@s(eZdZdZdZejddddZdS)InspectionAttrInfoaAdds the ``.info`` attribute to :class:`.InspectionAttr`. The rationale for :class:`.InspectionAttr` vs. :class:`.InspectionAttrInfo` is that the former is compatible as a mixin for classes that specify ``__slots__``; this is essentially an implementation artifact. r<r()rgcCsiS)aInfo dictionary associated with the object, allowing user-defined data to be associated with this :class:`.InspectionAttr`. The dictionary is generated when first accessed. Alternatively, it can be specified as a constructor argument to the :func:`.column_property`, :func:`_orm.relationship`, or :func:`.composite` functions. .. seealso:: :attr:`.QueryableAttribute.info` :attr:`.SchemaItem.info` r<)rir<r<r=infoszInspectionAttrInfo.infoN)r3r4r5rErrZro_memoized_propertyrr<r<r<r=rsrc@s^eZdZdZejrZdddddZddd d d Zdd dddddZdd dddddZ d S)SQLORMOperationsr<rzPropComparator[_T_co])rrgcCsdSrlr<)rirr<r<r=of_typeszSQLORMOperations.of_typez_ColumnExpressionArgument[bool]zPropComparator[bool])criteriargcGsdSrlr<)rirr<r<r=and_szSQLORMOperations.and_Nz)Optional[_ColumnExpressionArgument[bool]]rzColumnElement[bool]) criterionkwargsrgcKsdSrlr<rirrr<r<r=anyszSQLORMOperations.anycKsdSrlr<rr<r<r=hasszSQLORMOperations.has)N)N) r3r4r5rtypingr rrrrr<r<r<r=rsrc@sneZdZdZdZejrjeddddddZeddd dd dZed dd dd dZd dddddZdS) ORMDescriptorz`Represent any Python descriptor that provides a SQL expression construct at the class level.r<rz Literal[None]zORMDescriptor[_T_co]rxownerrgcCsdSrlr<rirxrr<r<r=__get__szORMDescriptor.__get__zSQLCoreOperations[_T_co]cCsdSrlr<rr<r<r=rsr{r-cCsdSrlr<rr<r<r=rsz` form of :class:`_orm.Mapper` configuration, where used explicitly it drives the configuration of ORM attributes such as :func:`_orm.mapped_class` and :func:`_orm.relationship`. .. seealso:: :ref:`orm_explicit_declarative_base` :ref:`orm_declarative_table` .. tip:: The :class:`_orm.Mapped` class represents attributes that are handled directly by the :class:`_orm.Mapper` class. It does not include other Python descriptor classes that are provided as extensions, including :ref:`hybrids_toplevel` and the :ref:`associationproxy_toplevel`. While these systems still make use of ORM-specific superclasses and structures, they are not :term:`instrumented` by the :class:`_orm.Mapper` and instead provide their own functionality when they are accessed on a class. .. versionadded:: 1.4 r<rurInstrumentedAttribute[_T_co]rcCsdSrlr<rr<r<r=r(szMapped.__get__r{r-cCsdSrlr<rr<r<r=r-sOptional[object]z*Union[InstrumentedAttribute[_T_co], _T_co]cCsdSrlr<rr<r<r=r0sz Mapped[_T_co])arg1rgcCsdSrlr<)rqrr<r<r=_empty_constructor4szMapped._empty_constructorz&Union[SQLCoreOperations[_T_co], _T_co]rxvaluergcCsdSrlr<rirxrr<r<r=__set__7szMapped.__set__rwcCsdSrlr<)rirxr<r<r= __delete__;rtzMapped.__delete__N) r3r4r5rErrr r r classmethodrrrr<r<r<r=rs$rc@seZdZdZdZdS)_MappedAttributezVMixin for attributes which should be replaced by mapper-assigned attributes. r<Nrr<r<r<r=r>src@s@eZdZdZdZdddddddZeZddddddd Zd S) _DeclarativeMappedzMixin for :class:`.MapperProperty` subclasses that allows them to be compatible with ORM-annotated declarative mappings. r<r*r)opotherrrgcOstSrlNotImplementedrirrrr<r<r=operateUsz_DeclarativeMapped.operatecKstSrlrrr<r<r=reverse_operateZsz"_DeclarativeMapped.reverse_operateN)r3r4r5rErrZ__sa_operate__rr<r<r<r=rGs rc@sheZdZdZdZerdeddddddZed dd dd dZd dd dddZddddddZdS) DynamicMappedaRepresent the ORM mapped attribute type for a "dynamic" relationship. The :class:`_orm.DynamicMapped` type annotation may be used in an :ref:`Annotated Declarative Table ` mapping to indicate that the ``lazy="dynamic"`` loader strategy should be used for a particular :func:`_orm.relationship`. .. legacy:: The "dynamic" lazy loader strategy is the legacy form of what is now the "write_only" strategy described in the section :ref:`write_only_relationship`. E.g.:: class User(Base): __tablename__ = "user" id: Mapped[int] = mapped_column(primary_key=True) addresses: DynamicMapped[Address] = relationship( cascade="all,delete-orphan" ) See the section :ref:`dynamic_relationship` for background. .. versionadded:: 2.0 .. seealso:: :ref:`dynamic_relationship` - complete background :class:`.WriteOnlyMapped` - fully 2.0 style version r<rurrrcCsdSrlr<rr<r<r=rszDynamicMapped.__get__r{zAppenderQuery[_T_co]cCsdSrlr<rr<r<r=rsrz9Union[InstrumentedAttribute[_T_co], AppenderQuery[_T_co]]cCsdSrlr<rr<r<r=rstyping.Collection[_T_co]rcCsdSrlr<rr<r<r=rszDynamicMapped.__set__N r3r4r5rErr r rrr<r<r<r=r`s rc@sheZdZdZdZerdeddddddZed dd dd dZd dd dddZddddddZdS)WriteOnlyMappedadRepresent the ORM mapped attribute type for a "write only" relationship. The :class:`_orm.WriteOnlyMapped` type annotation may be used in an :ref:`Annotated Declarative Table ` mapping to indicate that the ``lazy="write_only"`` loader strategy should be used for a particular :func:`_orm.relationship`. E.g.:: class User(Base): __tablename__ = "user" id: Mapped[int] = mapped_column(primary_key=True) addresses: WriteOnlyMapped[Address] = relationship( cascade="all,delete-orphan" ) See the section :ref:`write_only_relationship` for background. .. versionadded:: 2.0 .. seealso:: :ref:`write_only_relationship` - complete background :class:`.DynamicMapped` - includes legacy :class:`_orm.Query` support r<rurrrcCsdSrlr<rr<r<r=rszWriteOnlyMapped.__get__r{zWriteOnlyCollection[_T_co]cCsdSrlr<rr<r<r=rsrz?Union[InstrumentedAttribute[_T_co], WriteOnlyCollection[_T_co]]cCsdSrlr<rr<r<r=rsrrcCsdSrlr<rr<r<r=rszWriteOnlyMapped.__set__Nrr<r<r<r=rsr)F)T)rE __future__renumroperatorrrrrrrr r r r r rrrZ_typingrrrrsqlrZ sql.elementsrrrZutil.langhelpersrZ util.typingrrrr attributesrZdynamicr Zinstrumentationr!Z interfacesr"rr#rr$r%Z writeonlyr&Z sql._typingr'r(r)Z sql.operatorsr*r+r-r{r/r0tupler6r7r8r9r:r;r> __members__valuesrFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrUrVrWr~ZDEFAULT_STATE_ATTRrXrYrZr[r\r]r^r_r`rarb frozensetZ _never_setZ _none_setsymbolZ_SET_DEFERRED_EXPIREDZ_DEFER_FOR_STATEZ_RAISE_FOR_STATErdrerprsrvrzr| attrgetterrrrrrrrZ _inspectsrrrrrrrZ dottedgetterrrrrrrrrrZDDLConstraintColumnRolerrrrrr<r<r<r=s&                                          *^ #            L   D 8