L imkdZddlmZddlmZddlZddlZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl"m#Z#ej rZddlm$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,e-Z<ed.ed/0Z=ed1e>-Z?Gd2d3eZ@eAe@\ZBZCZDZEZFeFZGGd4d5eZHeHjj\ZKZLZMZNZOZPZQZRZSZTZUZVZWZXZYZZZ[Z\d6Z]d7Z^Gd8d9eZ_eAe_\Z`ZaZbZcGd:d;eZdeAed\ZeZfZgGd<d=eZhGd>d?ehZiejeGgZkejdeGeBgZlejdgZmejd@ZoejdAZpejdBZqedCedDef-ZredEZs dxdFZter+dydGZue dzdHZve d{dIZv d{dJZvd|dKZwd}dLZxn*dMZudNZveje^ZwejdOZxd~dPZzddQZ{ddRZ|ddSZ}ddTZ~ddUZddVZeje>ddWZ ddXZ ddYZddZZdd[Ze dd\Zerdd]Znejd^Z d dd_Zdd`ZdddaZGdbdcZGdddeeZGdfdgee=e!ZGdhdie e=e!ZGdjdke e=e!ZGdldmee=ee=e!ZGdndoee=ee=ee=ej&ZGdpdqe e=e!ZGdrdsee=ee=ZGdtduee=ZGdvdwee=Zy)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.eZdZdZ dZ dZ dZ dZ eZy)LoaderCallableStatusrrrN) __name__ __module__ __qualname__PASSIVE_NO_RESULTPASSIVE_CLASS_MISMATCH ATTR_WAS_SET ATTR_EMPTYNO_VALUE NEVER_SETY/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/orm/base.pyr2r2?sG DL JJH Ir?r2ceZdZdZdZ dZ dZ dZ dZ dZ dZ d Z d Z d Z d Zee zezezezZ eez Z eez Z eez Z eez Z ee z Z ee zZy ) PassiveFlagz;Bitflag interface that passes options onto loader callablesrrrr4 @iN)r5r6r7__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@rBrBnsEILFLG CL4H:F # --7,FO-)G33lB,"V+*->>%),==%(*Mr?rB_sa_class_manager_sa_instance_stateceZdZdZdZdZdZy)EventConstantsrrr3r4N)r5r6r7 EXT_CONTINUEEXT_STOPEXT_SKIPNO_KEYr>r?r@r_r_sLHH Fr?r_c eZdZdZdZ dZ dZy)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`. rrr3N)r5r6r7rI ONETOMANY MANYTOONE MANYTOMANYr>r?r@reres+IIJr?receZdZdZy)InspectionAttrExtensionTypezXSymbols indicating the type of extension that a :class:`.InspectionAttr` is part of.N)r5r6r7rIr>r?r@rjrjs,r?rjceZdZdZy) NotExtension not_extensionN)r5r6r7 NOT_EXTENSIONr>r?r@rlrl s #Mr?rlSET_DEFERRED_EXPIREDDEFER_FOR_STATERAISE_FOR_STATE_F._Selfc:tjdfd }|S)NcTD]}|||j||g|i||SN)r5)fnselfargskw assertion assertionss r@generatez_assertions..generate,s7# )I dBKK ( ) 4$" r?) rwrrrxrsryrrzrreturnrs)r decorator)r|r}s` r@ _assertionsr)s" ^^ Or?cyrvr>clss r@manager_of_classr8r?cyrvr>rs r@opt_manager_of_classr:s>Ar?cyrvr>rs r@rr=s&)r?cyrvr>rs r@rrBs%(r?cyrvr>instances r@instance_staterFrr?cyrvr>rs r@ instance_dictrHrr?c |jtS#t$r}tj|d||d}~wwxYw)Nz2Can't locate an instrumentation manager for class )__dict__DEFAULT_MANAGER_ATTRKeyErrorrUnmappedClassError)rkes r@rrNsJ << 45 5 ((I#O  s =8=c@|jjtSrv)rgetrrs r@rrVs|| 455r?rc*tt|S)z'Return a string describing an instance.) state_strrrs r@ instance_strr^s ^H- ..r?cl|yd|jjt|jfzS)z=Return a string describing an instance via its InstanceState.Nonez <%s at 0x%x>)class_r5idobjstates r@rrds0 }!6!6599; HHHr?c<|yd|jjdS)zNReturn a string describing an instance's class via its InstanceState. r<>)rr5rs r@state_class_strrms&  }..00r?c$t|dz|zSN.)r)r attributes r@ attribute_strrxs  !C ') 33r?c$t|dz|zSr)r)rrs r@state_attribute_strr|s U c !I --r?c,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_statemapperrs r@ object_mapperrs  ! ( ((r?cJt|}|tj||S)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. )_inspect_mapped_objectrUnmappedInstanceError)rrs r@rrs)" #8 ,E }''11 r?cp t|S#tjftjz$rYywxYwrv)rrrNO_STATErs r@rrs6h''  " " $s|| 3s %55ctj|d}| |jSt|tsJt j |)NF)rinspectr isinstancetyperr)class_or_mapperinsps r@_class_to_mapperrsG   ou 5D {{/4000$$_55r?cLtj|d}| |jSy)z`Return the :class:`_orm.Mapper` for the given class or None if the class is not mapped. FN)rrrentityrs r@_mapper_or_noners)   fe ,D {{r?ctj|d}|duxr)|j xr|jxs |jS)zlReturn True if the given object is a mapped class, :class:`_orm.Mapper`, or :class:`.AliasedClass`. FN)rris_clause_element is_mapperis_aliased_classrs r@_is_mapped_classrsK   fe ,D D 6&& & 6 ^^ 4t44r?cTtj|d}|duxr t|ddS)NFr)rrgetattrrs r@_is_aliased_classrs.   fe ,D t  H.@% HHr?c\tj|}|jr|}|j}nB|jr|j }|}n't |dr|jjx}}n|} t||S#t$r"}tjd|d|d|d}~wwxYw)zReturn a class attribute given an entity and string name. May return :class:`.InstrumentedAttribute` or user-defined attribute. rzEntity 'z' has no property ''N) rr is_selectablecrrhasattrrrrAttributeErrorsa_excInvalidRequestError)rkeyr descriptionerrs r@_entity_descriptorrs   f %D     x #{{111 f vs## ((2=s C  s4 B B+ B&&B+cyrvr>rs r@ _state_mapperrrr?zmanager.mapperc t|}| |jsy|j}|r|j|S#tj $rYywxYwrv)r is_mappedr_check_configurerr)r configure class_managerrs r@_inspect_mapped_classrs[ ,V4  (?(?%%   # # % <<s< <AAcztj|d}t|r|Stjd|)NF)raiseerrz%Mapper or mapped class expected, got )rrrr ArgumentError)argrs r@_parse_mapper_argumentrs:   cE 2Dd   !FsgN OOr?ct||}|>t|tstjd|dt j ||S)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. )rzClass object expected, got 'z'.)rrrrrrr)rrrs r@ class_mapperrsP"#6Y ?F ~&$'&&6<> $$V,, r?cxeZdZUdZdZded<dZ dZ dZ dZ dZ dZ dZ dZ dZ ej Zded<y) 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__Frjextension_typeN)r5r6r7rIr__annotations__rr is_instancer is_bundle is_property is_attribute_is_internal_proxyrrlrnrr>r?r@rr8s "$I#M(GKHIEIAKIL  +3?2L2LN/L r?rc:eZdZdZdZej ddZy)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>ciS)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>)rxs r@infozInspectionAttrInfo.infos $ r?N)r~r))r5r6r7rIrrro_memoized_propertyrr>r?r@rrs&I r?rcveZdZdZej r' ddZ ddZ d d dZ d d dZ yy) SQLORMOperationsr>cyrvr>)rxrs r@of_typezSQLORMOperations.of_types$'r?cyrvr>)rxcriterias r@and_zSQLORMOperations.and_s#&r?Nc yrvr>rx criterionkwargss r@anyzSQLORMOperations.any#&r?c yrvr>rs r@haszSQLORMOperations.hasrr?)r_EntityType[Any]r~zPropComparator[_T_co])rz_ColumnExpressionArgument[bool]r~zPropComparator[bool]rv)rz)Optional[_ColumnExpressionArgument[bool]]rrr~zColumnElement[bool]) r5r6r7rtypingrrrrrr>r?r@rrsI  (* ( " ( '< ' ! ' DH &@ & &!  &DH &@ & &!  &!r?rceZdZdZdZej r2e ddZe d dZed dZ d dZyy) ORMDescriptorz`Represent any Python descriptor that provides a SQL expression construct at the class level.r>cyrvr>rxrowners r@__get__zORMDescriptor.__get__$'r?cyrvr>rs r@r zORMDescriptor.__get__s(+r?cyrvr>rs r@r zORMDescriptor.__get__BEr?cyrvr>rs r@r zORMDescriptor.__get__sKNr?N)rrr Literal[None]r~zORMDescriptor[_T_co])rrrrr~zSQLCoreOperations[_T_co]robjectrrr~r.)rrrrr~zr?r@rrs%I   ' '(5 ' ! '  '  +) +25 + % +  + E E O" O+. O I Or?rceZdZdZdZy)_MappedAnnotationBasezcommon class for Mapped and similar ORM container classes. these are classes that can appear on the left side of an ORM declarative mapping, containing a mapped class or in some cases a collection surrounding a mapped class. r>Nr5r6r7rIrr>r?r@rrsIr?rceZdZdZdZy)SQLORMExpressionaCA type that may be used to indicate any ORM-level attribute or object that acts in place of one, in the context of SQL expression construction. :class:`.SQLORMExpression` extends from the Core :class:`.SQLColumnExpression` to add additional SQL methods that are ORM specific, such as :meth:`.PropComparator.of_type`, and is part of the bases for :class:`.InstrumentedAttribute`. It may be used in :pep:`484` typing to indicate arguments or return values that should behave as ORM-level attribute expressions. .. versionadded:: 2.0.0b4 r>Nrr>r?r@rrs Ir?rceZdZdZdZej r:e d dZed dZ d dZe d dZ ddZ ddZ y y )MappedajRepresent an ORM mapped attribute on a mapped class. This class represents the complete descriptor interface for any class attribute that will have been :term:`instrumented` by the ORM :class:`_orm.Mapper` class. Provides appropriate information to type checkers such as pylance and mypy so that ORM-mapped attributes are correctly typed. The most prominent use of :class:`_orm.Mapped` is in the :ref:`Declarative Mapping ` 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>cyrvr>rs r@r zMapped.__get__(,/r?cyrvr>rs r@r zMapped.__get__-r r?cyrvr>rs r@r zMapped.__get__0s9)rarg1s r@_empty_constructorzMapped._empty_constructor4sADr?cyrvr>rxrvalues r@__set__zMapped.__set__7r?cyrvr>)rxrs r@ __delete__zMapped.__delete__;rr?Nrrrrr~zInstrumentedAttribute[_T_co]r)rOptional[object]rrr~z*Union[InstrumentedAttribute[_T_co], _T_co])rrr~z Mapped[_T_co])rrr"z&Union[SQLCoreOperations[_T_co], _T_co]r~r)rrr~r) r5r6r7rIrrrr r  classmethodrr#r&r>r?r@rrs "HI   /  /), / ) /  / E E =, =58 = 7 = D D  (N    9+r?rceZdZdZdZy)_MappedAttributezVMixin for attributes which should be replaced by mapper-assigned attributes. r>Nrr>r?r@r+r+>s Ir?r+c8eZdZdZdZddZeZ ddZy)_DeclarativeMappedzMixin for :class:`.MapperProperty` subclasses that allows them to be compatible with ORM-annotated declarative mappings. r>ctSrvNotImplementedrxopotherrs r@operatez_DeclarativeMapped.operateUsr?c tSrvr/r1s r@reverse_operatez"_DeclarativeMapped.reverse_operateZs r?N)r2r+r3rrrr~r)r5r6r7rIrr4__sa_operate__r6r>r?r@r-r-Gs? IN'*69 r?r-c~eZdZdZdZer3e ddZe d dZ d dZ d dZyy) 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>cyrvr>rs r@r zDynamicMapped.__get__rr?cyrvr>rs r@r zDynamicMapped.__get__r r?cyrvr>rs r@r zDynamicMapped.__get__sHKr?cyrvr>r!s r@r#zDynamicMapped.__set__r$r?Nr')rrrrr~zAppenderQuery[_T_co])rr(rrr~z9Union[InstrumentedAttribute[_T_co], AppenderQuery[_T_co]]rrr"ztyping.Collection[_T_co]r~r r5r6r7rIrrr r r#r>r?r@r9r9`s@I  /  /), / ) /  /  '" '+. ' ! '  ' L, L58 L F L  (@   !r?r9c~eZdZdZdZer3e ddZe d dZ d dZ d dZyy) 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>cyrvr>rs r@r zWriteOnlyMapped.__get__rr?cyrvr>rs r@r zWriteOnlyMapped.__get__s*-r?cyrvr>rs r@r zWriteOnlyMapped.__get__s r?cyrvr>r!s r@r#zWriteOnlyMapped.__set__r$r?Nr')rrrrr~zWriteOnlyCollection[_T_co])rr(rrr~z?Union[InstrumentedAttribute[_T_co], WriteOnlyCollection[_T_co]]r>r?r>r?r@rArAs8I  /  /), / ) /  /  -" -+. - ' -  - , 58      (@   %r?rA)r|rr~zCallable[[_F], _F])rType[_O]r~zClassManager[_O])rzAliasedClass[Any]r~r)rz_ExternalEntityType[_O]r~zOptional[ClassManager[_O]])rr0r~InstanceState[_O])rrr~zDict[str, Any])rrr~str)rInstanceState[Any]r~rH)rrrrHr~rH)rrIrrHr~rH)rr,r~ Mapper[_T])rr,r~zInstanceState[_T])rr,r~zOptional[InstanceState[_T]])rzUnion[Mapper[_T], Type[_T]]r~rJ)rz(Union[Type[_T], _InternalEntityType[_T]]r~zOptional[Mapper[_T]])rrr~bool)rrrrHr~r)rrGr~ Mapper[_O])F)rrFrrKr~zOptional[Mapper[_O]])rzUnion[Mapper[_O], Type[_O]]r~rL)T)rrFrrKr~rL)rI __future__renumroperatorrrrrrr r r r r rrrr_typingrrrrsqlr sql.elementsrrrutil.langhelpersr util.typingrrrr attributesr dynamicr!instrumentationr" interfacesr#rr$rr%r& writeonlyr' sql._typingr(r)r* sql.operatorsr+r,r.rr0r2tupler8r9r:r;r<r=rB __members__valuesrJrKrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZr[rDEFAULT_STATE_ATTRr_r`rarbrcrerfrgrhrjrl frozenset _never_set _none_set_none_only_setsymbol_SET_DEFERRED_EXPIRED_DEFER_FOR_STATE_RAISE_FOR_STATErrrsrrrrr attrgetterrrrrrrr _inspectsrrrrrrr dottedgetterrrrrrrrrrDDLConstraintColumnRolerr+r-r9rAr>r?r@rmsB"   #.,)! $,,1&-*$".7',, Tsd3 T !4!T     H+H|""$'    +) T ,1+@( h& D F$))>#? 9j,$, . { # tY(9: ; D6"# $:;4;;014;;01 T#s(+,   @ AA ) $) #))) $) #)?> 6)X(();