o znh#+@sdZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lmZdd l m Z d gZ e jGd d d eZdS)z|MapperProperty implementations. This is a private module which defines the behavior of individual ORM- mapped attributes. )absolute_import) attributes)PropComparator)StrategizedProperty)_orm_full_deannotate)log)util expressionColumnPropertycseZdZdZdZdZejddfddZe dd d d Z d d Z e ddZ ddZfddZddZejfddZddZGdddejeZddZZS)r zDescribes an object attribute that corresponds to a table column. Public constructor is the :func:`.orm.column_property` function. column) _orig_columnscolumnsgroupdeferred instrumentcomparator_factory descriptor extensionactive_historyexpire_on_flushinfodoc strategy_key_creation_order_is_polymorphic_discriminator_mapped_by_synonym_deferred_column_loader)z0.7z:class:`.AttributeExtension` is deprecated in favor of the :class:`.AttributeEvents` listener interface. The :paramref:`.column_property.extension` parameter will be removed in a future release.)rcsJtt|dd|D|_dd|D|_|dd|_|dd|_|dd |_|d |j j |_ |d d|_ |d d|_ |d d|_|dd |_d|vr[|d|_d|vrf|d|_nt|jD]}t|dd}|dur|||_nqkd|_|rtd|j jdt|ft|d|jfd|jff|_dS)a\ Provide a column-level property for use with a Mapper. Column-based properties can normally be applied to the mapper's ``properties`` dictionary using the :class:`.Column` element directly. Use this function when the given column is not directly present within the mapper's selectable; examples include SQL expressions, functions, and scalar SELECT queries. Columns that aren't present in the mapper's selectable won't be persisted by the mapper and are effectively "read-only" attributes. :param \*cols: list of Column objects to be mapped. :param active_history=False: When ``True``, indicates that the "previous" value for a scalar attribute should be loaded when replaced, if not already loaded. Normally, history tracking logic for simple non-primary-key scalar values only needs to be aware of the "new" value in order to perform a flush. This flag is available for applications that make use of :func:`.attributes.get_history` or :meth:`.Session.is_modified` which also need to know the "previous" value of the attribute. :param comparator_factory: a class which extends :class:`.ColumnProperty.Comparator` which provides custom SQL clause generation for comparison operations. :param group: a group name for this property when marked as deferred. :param deferred: when True, the column property is "deferred", meaning that it does not load immediately, and is instead loaded when the attribute is first accessed on an instance. See also :func:`~sqlalchemy.orm.deferred`. :param doc: optional string that will be applied as the doc on the class-bound descriptor. :param expire_on_flush=True: Disable expiry on flush. A column_property() which refers to a SQL expression (and not a single table-bound column) is considered to be a "read only" property; populating it has no effect on the state of data, and it can only return database state. For this reason a column_property()'s value is expired whenever the parent object is involved in a flush, that is, has any kind of "dirty" state within a flush. Setting this parameter to ``False`` will have the effect of leaving any existing value present after the flush proceeds. Note however that the :class:`.Session` with default expiration settings still expires all attributes after a :meth:`.Session.commit` call, however. :param info: Optional data dictionary which will be populated into the :attr:`.MapperProperty.info` attribute of this object. :param extension: an :class:`.AttributeExtension` instance, or list of extensions, which will be prepended to the list of attribute listeners for the resulting descriptor placed on the class. cSsg|]}t|qS)r _labeled.0cr r D/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/properties.py sz+ColumnProperty.__init__..cSsg|] }tt|qSr )r r!rr"r r r%r&srNrF _instrumentTrrrrrrrz.%s received unexpected keyword argument(s): %sz, r)superr __init__rrpoprrr __class__ Comparatorrrrrrrrreversedgetattr TypeError__name__joinsortedkeysr set_creation_orderr)selfrkwargscolrr+r r%r):sHK    zColumnProperty.__init__zsqlalchemy.orm.statezsqlalchemy.orm.strategiescCs|j|jj||j|jSN) InstanceState"_instance_level_callable_processorparent class_managerLoadDeferredColumnskey)r5state strategiesr r r%&_memoized_attr__deferred_column_loaders  z5ColumnProperty._memoized_attr__deferred_column_loadercCs|jS)zsAllow the ColumnProperty to work in expression before it is turned into an instrumented attribute. r r5r r r%__clause_element__sz!ColumnProperty.__clause_element__cCs |jdS)zJReturn the primary column or expression for this ColumnProperty. r)rrCr r r%r s zColumnProperty.expressioncCs0|jsdStj|j|j|||||jddS)N) comparator parententityr)rrregister_descriptorclass_r?rr)r5mapperr r r%instrument_classs  zColumnProperty.instrument_classcsbtt|t|jdkr-t|jj|jr/t d|j|jd|jd|j fdSdSdS)NrzOn mapper %s, primary key column '%s' is being combined with distinct primary key column '%s' in attribute '%s'. Use explicit properties to give each column its own mapped attribute name.r) r(r do_initlenrsetr< primary_key issupersetr warnr?rCr8r r%rKszColumnProperty.do_initcCst|j|j|j|jdS)N)rrr)r rrrrrCr r r%copys zColumnProperty.copycCs||jj|||dS)N)passive)get_implr?get_committed_value)r5r@dict_rrRr r r% _getcommitteds zColumnProperty._getcommittedc Cs|jsdS|j|vr(||j} |s| ||j<dS||j} | ||| ddS|jr<|j|vr>|j||jgdddSdSdS)NT) no_loader)rr?rSrM has_identity_expire_attributes) r5session source_state source_dict dest_state dest_dictload _recursive_resolve_conflict_mapvalueimplr r r%merges      zColumnProperty.mergec@s<eZdZdZdZddZddZddZd d Zd d Z d S)zColumnProperty.ComparatoraProduce boolean, comparison, and other operators for :class:`.ColumnProperty` attributes. See the documentation for :class:`.PropComparator` for a brief overview. .. seealso:: :class:`.PropComparator` :class:`.ColumnOperators` :ref:`types_operators` :attr:`.TypeEngine.comparator_factory` )rDrcCs4|jr ||jjdS|jjd|j|jdS)Nr)rF parentmapper)adapterpropr _annotate _parententityrCr r r%#_memoized_method___clause_element__s z=ColumnProperty.Comparator._memoized_method___clause_element__cCs,|}z|jWSty|jjYSwr9)rDrAttributeErrorrg)r5cer r r%_memoized_attr_info,s   z-ColumnProperty.Comparator._memoized_attr_infocCst||S)zproxy attribute access down to the mapped column. this allows user-defined comparison methods to be accessed. )r.rD)r5r?r r r%_fallback_getattr3sz+ColumnProperty.Comparator._fallback_getattrcOs||g|Ri|Sr9)rD)r5opotherr6r r r%operate:sz!ColumnProperty.Comparator.operatecKs"|}|||||fi|Sr9)rD _bind_param)r5rorpr6r7r r r%reverse_operate=sz)ColumnProperty.Comparator.reverse_operateN) r0 __module__ __qualname____doc__ __slots__rjrmrnrqrsr r r r%r, s  r,cCst|jjjd|jS)N.)strr<rHr0r?rCr r r%__str__AszColumnProperty.__str__)r0rtrurvstrategy_wildcard_keyrwr deprecated_paramsr) dependenciesrBrDpropertyr rJrKrQr PASSIVE_OFFrVrd MemoizedSlotsrr,rz __classcell__r r r8r%r s* m    7N)rv __future__rr interfacesrrr rr sqlr __all__ class_loggerr r r r r%s