o znh:@s dZddlZddlmZddlmZddlmZddlmZddlmZe d d Z e d d Z e d dZ e ddZ e ddZej ddddZej ddddZej ddddZej ddddZej ddddZej d d!d"dZej d#d$d%dZej d&d'd(dZej d)d*d+dZej d,d-eeBeBeBeBdZej d.d/eeAdZej d0d1eeAdZej d2d3eeAdZej d4d5eeAdZej d6d7eeAdZd8Zd9Zd:Z e d;Z!e d<Z"e d=Z#e d>d?Z$e d@dAZ%e dBdCZ&e dDdEZ'e(egZ)e(dee gZ*e dFZ+e dGZ,dHdIZ-dJdKZ.e/eZ0e/dLZ1dMdNZ2dOdPZ3dQdRZ4dSdTZ5dUdVZ6dWdXZ7dYdZZ8e9e:d[d\Z;d]d^ZdcddZ?dedfZ@dgdhZAdidjZBeCdkZDe9eEdxdmdnZFdydpdqZGGdrdsdse:ZHGdtdudueHZIGdvdwdwe:ZJdS)zz=Constants and rudimental functions used throughout the ORM. N)exc) inspection)util) expressionPASSIVE_NO_RESULTzSymbol returned by a loader callable or other attribute/history retrieval operation when a value could not be determined, based on loader callable flags. ATTR_WAS_SETzSymbol returned by a loader callable to indicate the retrieved value, or values, were assigned to their attributes on the target object. ATTR_EMPTYz@Symbol used internally to indicate an attribute had no callable.NO_VALUEzSymbol which may be placed as the 'previous' value of an attribute, indicating no value was loaded for an attribute when it was modified, and flags indicated we were not to load it. NEVER_SETzSymbol which may be placed as the 'previous' value of an attribute indicating that the attribute had not been assigned to previously. NO_CHANGEz]No callables or SQL should be emitted on attribute access and no state should change ) canonical CALLABLES_OKzELoader callables can be fired off if a value is not present. SQL_OKzBLoader callables can emit SQL at least on scalar value attributes.RELATED_OBJECT_OKzZCallables can use SQL to load related objects as well as scalar value attributes. INIT_OKzAttributes should be initialized with a blank value (None or an empty collection) upon get, if no other value can be obtained. NON_PERSISTENT_OKz9Callables can be emitted if the parent is not persistent.LOAD_AGAINST_COMMITTEDzUCallables should use committed values as primary/foreign keys during a load. NO_AUTOFLUSHz*Loader callables should disable autoflush.@NO_RAISEz0Loader callables should not raise any assertions PASSIVE_OFFz&Callables can be emitted in all cases.PASSIVE_RETURN_NEVER_SETzPASSIVE_OFF ^ INIT_OKPASSIVE_NO_INITIALIZEz'PASSIVE_RETURN_NEVER_SET ^ CALLABLES_OKPASSIVE_NO_FETCHzPASSIVE_OFF ^ SQL_OKPASSIVE_NO_FETCH_RELATEDzPASSIVE_OFF ^ RELATED_OBJECT_OKPASSIVE_ONLY_PERSISTENTzPASSIVE_OFF ^ NON_PERSISTENT_OK_sa_class_manager_sa_instance_state)mapper instrumentor EXT_CONTINUEEXT_STOPEXT_SKIP ONETOMANYzIndicates the one-to-many direction for a :func:`.relationship`. This symbol is typically used by the internals but may be exposed within certain API features. MANYTOONEzIndicates the many-to-one direction for a :func:`.relationship`. This symbol is typically used by the internals but may be exposed within certain API features. MANYTOMANYzIndicates the many-to-many direction for a :func:`.relationship`. This symbol is typically used by the internals but may be exposed within certain API features. NOT_EXTENSIONzSymbol indicating an :class:`InspectionAttr` that's not part of sqlalchemy.ext. Is assigned to the :attr:`.InspectionAttr.extension_type` attribute. SET_DEFERRED_EXPIREDDEFER_FOR_STATEcstjfdd}|S)z1Mark a method as generative, e.g. method-chained.csD|d}D]}|||jq||g|ddRi||S)Nrr)_clone__name__)fnargskwself assertion assertions>/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/base.pygenerates z_generative..generate)r decorator)r8r;r9r7r: _generativesr=cCs|jtdSN)__dict__getDEFAULT_MANAGER_ATTR)clsr9r9r:manager_of_classsrCr?cCs tt|S)z'Return a string describing an instance.) state_strinstance_stateinstancer9r9r: instance_strs rHcCs$|durdSd|jjt|fS)z=Return a string describing an instance via its InstanceState.NNonez <%s at 0x%x>)class_r1idobjstater9r9r:rDsrDcCs|durdSd|jjfS)zNReturn a string describing an instance's class via its InstanceState. NrIz<%s>)rJr1rMr9r9r:state_class_strsrOcCt|d|SN.)rH)rG attributer9r9r: attribute_strrTcCrPrQ)rD)rNrSr9r9r:state_attribute_str rUrVcCs 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_stater%rFr9r9r: object_mappers rXcCst|}|dur t||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:`.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_objectrUnmappedInstanceError)rGrNr9r9r:rW"s rWcCs6zt|WStjyYdStjyYdSwr>)rErUnmappedClassErrorNO_STATErFr9r9r:rY:s rYcCs$t|d}|dur |jSt|)NF)rinspectr%rr[)class_or_mapperinspr9r9r:_class_to_mapperFs  r`cCst|d}|dur |jSdS)z\Return the :class:`.Mapper` for the given class or None if the class is not mapped. FN)rr]r%entityr_r9r9r:_mapper_or_noneNs rccCs(t|d}|duo|j o|jp|jS)zhReturn True if the given object is a mapped class, :class:`.Mapper`, or :class:`.AliasedClass`. FN)rr]is_clause_element is_mapperis_aliased_classrar9r9r:_is_mapped_classZs  rgcCst|dr|jSt|S)Nkey)hasattrrhr_column_as_key)attrr9r9r: _attr_as_keygs  rlcCs:t|d}t|drt|jdrdd|jjDS|gS)NF selectableccSsg|]}|qSr9r9).0rnr9r9r: qsz _orm_columns..)rr]rirmrnrar9r9r: _orm_columnsns rqcCs t|d}|duot|ddS)NFrf)rr]getattrrar9r9r:_is_aliased_classvs rscCsxt|}|jr|}|j}n|jr|j}|}nt|dr#|jj}}n|}zt ||WSt y;t d||fw)zReturn a class attribute given an entity and string name. May return :class:`.InstrumentedAttribute` or user-defined attribute. r%z Entity '%s' has no property '%s') rr] is_selectablernrfrbrir%rJrrAttributeErrorsa_excInvalidRequestError)rbrhr_ descriptionr9r9r:_entity_descriptor{s"     ryzmanager.mapperFcCsLzt|}|js WdS|j}Wn tjyYdSw|r$|jr$||Sr>)rC is_mappedr%rr\ _new_mappers_configure_all)rJ configure class_managerr%r9r9r:_inspect_mapped_classs  rTcCs<t||d}|durt|tstd|ft||S)aGiven a class, return the primary :class:`.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:`.inspect` function as:: inspect(some_mapped_class) Using the inspection system will raise :class:`sqlalchemy.exc.NoInspectionAvailable` if the class is not mapped. )r}Nz Class object expected, got '%r'.)r isinstancetyperv ArgumentErrorrr[)rJr}r%r9r9r: class_mappers   rc@sHeZdZdZdZdZ dZ dZ dZ dZ dZ dZ dZ e ZdS)InspectionAttra A base class applied to all ORM objects that can be returned by the :func:`.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. r9FN)r1 __module__ __qualname____doc__ __slots__rtrf is_instancere is_property is_attribute_is_internal_proxyrdr-extension_typer9r9r9r:rs*rc@seZdZdZejddZdS)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. cCsiS)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:`.relationship`, or :func:`.composite` functions. .. versionchanged:: 1.0.0 :attr:`.MapperProperty.info` is also available on extension types via the :attr:`.InspectionAttrInfo.info` attribute, so that it can apply to a wider variety of ORM and extension constructs. .. seealso:: :attr:`.QueryableAttribute.info` :attr:`.SchemaItem.info` r9)r5r9r9r:infoszInspectionAttrInfo.infoN)r1rrrrmemoized_propertyrr9r9r9r:r src@seZdZdZdZdS)_MappedAttributezVMixin for attributes which should be replaced by mapper-assigned attributes. r9N)r1rrrrr9r9r9r:r/sr)F)T)Kroperatorrrvrrsqlrsymbolrr r r r r rrrrrrrrrrrr r!r"rADEFAULT_STATE_ATTR _INSTRUMENTORr'r(r)r*r+r,r- frozenset _never_set _none_set_SET_DEFERRED_EXPIRED_DEFER_FOR_STATEr=rC attrgetterrE instance_dictrHrDrOrTrVrXrW _inspectsobjectrYr`rcrgrlrqrsry dottedgetter _state_mapperrrrrrrr9r9r9r:s2                           I"