U a=@s&dZddlZddlmZddlmZddlmZddlmZedd Zed d Z ed d Z eddZ eddZ e Z ejddddZejddddZejddddZejddddZejddddZejdd d!dZejd"d#d$dZejd%d&d'dZejd(d)d*dZejd+d,d-dZejd.d/eeBeBeBeBdZejd0d1eeAdZejd2d3eeAdZejd4d5eeAdZejd6d7eeAdZejd8d9eeAdZd:Zd;Zed<Z ed=Z!ed>Z"ed?d@Z#edAdBZ$edCdDZ%edEdFZ&e'e gZ(e'de egZ)edGZ*edHZ+edIZ,dJdKZ-dLdMZ.e/eZ0e/dNZ1dOdPZ2dQdRZ3dSdTZ4dUdVZ5dWdXZ6dYdZZ7d[d\Z8e9e:d]d^Z;d_d`ZdedfZ?dgdhZ@didjZAeBdkZCe9eDdxdmdnZEdydpdqZFGdrdsdse:ZGGdtdudueGZHGdvdwdwe:ZIdS)zz=Constants and rudimental functions used throughout the ORM. N)exc) inspection)utilPASSIVE_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. PASSIVE_CLASS_MISMATCHzSymbol indicating that an object is locally present for a given primary key identity but it is not of the requested class. The return value is therefore None and no SQL should be emitted. 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. 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 assertionsDEFERRED_HISTORY_LOADz.generate)r decorator)r1r4r2r0r3 _assertionssr6cCs|jtdSN)__dict__getDEFAULT_MANAGER_ATTR)clsr2r2r3manager_of_classsr<r8cCs tt|S)z'Return a string describing an instance.) state_strinstance_stateinstancer2r2r3 instance_strsrAcCs(|dkr dSd|jjt|fSdS)z=Return a string describing an instance via its InstanceState.NNonez <%s at 0x%x>)class_r+idobjstater2r2r3r=sr=cCs|dkr dSd|jjfSdS)zNReturn a string describing an instance's class via its InstanceState. NrBz<%s>)rCr+rFr2r2r3state_class_strsrHcCst|d|SN.)rA)r@ attributer2r2r3 attribute_strsrLcCst|d|SrI)r=)rGrKr2r2r3state_attribute_strsrMcCs 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_statemapperr?r2r2r3 object_mappersrPcCs$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)r@rGr2r2r3rN+s rNc Cs0z t|WStjftjk r*YdSXdSr7)r>rUnmappedClassErrorNO_STATEr?r2r2r3rQCs rQcCs(t|d}|dk r|jSt|dS)NF)rinspectrOrrR)Zclass_or_mapperinspr2r2r3_class_to_mapperKs rVcCs"t|d}|dk r|jSdSdS)z`Return the :class:`_orm.Mapper` for the given class or None if the class is not mapped. FN)rrTrOentityrUr2r2r3_mapper_or_noneSs rYcCs(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)rrTis_clause_element is_mapperis_aliased_classrWr2r2r3_is_mapped_class_s   r]cCs>t|d}t|dr4t|jdr4dd|jjDS|gSdS)NF selectableccSsg|]}|qSr2r2).0r_r2r2r3 osz _orm_columns..)rrThasattrr^r_rWr2r2r3 _orm_columnsls rccCs t|d}|dk ot|ddS)NFr\)rrTgetattrrWr2r2r3_is_aliased_classts rec Cst|}|jr|}|j}n.|jr.|j}|}nt|drF|jj}}n|}z t ||WSt k r}z t j t d||f|dW5d}~XYnXdS)zReturn a class attribute given an entity and string name. May return :class:`.InstrumentedAttribute` or user-defined attribute. rOz Entity '%s' has no property '%s')Zreplace_contextN)rrT is_selectabler_r\rXrbrOrCrdAttributeErrorrZraise_sa_excZInvalidRequestError)rXkeyrU descriptionerrr2r2r3_entity_descriptorys&    rlzmanager.mapperFcCsLzt|}|jsWdS|j}Wntjk r6YdSX|rD||SdSr7)r<Z is_mappedrOrrSZ_check_configure)rC configureZ class_managerrOr2r2r3_inspect_mapped_classs rnTcCsBt||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. )rmNz Class object expected, got '%r'.)rn isinstancetyperh ArgumentErrorrrR)rCrmrOr2r2r3 class_mappers   rrc@s<eZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ eZdS)InspectionAttra#A base class applied to all ORM objects 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. r2FN)r+ __module__ __qualname____doc__ __slots__rfr\Z is_instancer[Z is_bundleZ is_propertyZ is_attributeZ_is_internal_proxyrZr*Zextension_typer2r2r2r3rssrsc@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:`_orm.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` r2)r/r2r2r3infoszInspectionAttrInfo.infoN)r+rtrurvrZmemoized_propertyryr2r2r2r3rxsrxc@seZdZdZdZdS)_MappedAttributezVMixin for attributes which should be replaced by mapper-assigned attributes. r2N)r+rtrurvrwr2r2r2r3rz6srz)F)T)Jrvoperatorrrhrrsymbolrrr r r Z NEVER_SETr rrrrrrrrrrrr r!r"r#r:ZDEFAULT_STATE_ATTRr$r%r&r'r(r)r* frozensetZ _never_setZ _none_setZ_SET_DEFERRED_EXPIREDZ_DEFER_FOR_STATEZ_RAISE_FOR_STATEr6r< attrgetterr> instance_dictrAr=rHrLrMrPrNZ _inspectsobjectrQrVrYr]rcrerlZ dottedgetterZ _state_mapperrprnrrrsrxrzr2r2r2r3s<                          N#