o
    y¬´\/*  ã                   @   s„   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ ddlmZ dgZe
jG dd„ deƒƒZdS )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)Ú
expressionÚColumnPropertyc                       s–   e Zd ZdZdZdZ‡ fdd„Ze dd¡dd	„ ƒZ	e
d
d„ ƒZdd„ Z‡ fdd„Zdd„ Zejfdd„Zdd„ ZG dd„ dejeƒZdd„ Z‡  ZS )r   z�Describes an object attribute that corresponds to a table column.

    Public constructor is the :func:`.orm.column_property` function.

    Úcolumn)Ú_orig_columnsÚcolumnsÚgroupÚdeferredÚ
instrumentÚcomparator_factoryÚ
descriptorÚ	extensionÚactive_historyÚexpire_on_flushÚinfoÚdocÚstrategy_keyÚ_creation_orderÚ_is_polymorphic_discriminatorÚ_mapped_by_synonymÚ_deferred_column_loaderc                    sJ  t t| ƒ ¡  dd„ |D ƒ| _dd„ |D ƒ| _| dd¡| _| dd¡| _| dd	¡| _| d
| j	j
¡| _| dd¡| _| dd¡| _| dd¡| _| dd	¡| _d|v r[| d¡| _d|v rf| d¡| _nt| jƒD ]}t|ddƒ}|dur||| _ nqkd| _|r“td| j	jd t| ¡ ƒ¡f ƒ‚t | ¡ d| jfd| jff| _dS )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.

           .. deprecated:: 0.7

                :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.

        c                 S   s   g | ]}t  |¡‘qS © )r   Ú_labeled©Ú.0Úcr   r   úK/var/www/html/env/lib/python3.10/site-packages/sqlalchemy/orm/properties.pyÚ
<listcomp>ƒ   s    z+ColumnProperty.__init__.<locals>.<listcomp>c                 S   s   g | ]	}t  t|ƒ¡‘qS r   )r   r    r   r!   r   r   r$   r%   „   s    ÿr   Nr   FÚ_instrumentTr   r   r   r   r   r   r   z.%s received unexpected keyword argument(s): %sz, r   )Úsuperr   Ú__init__r   r   Úpopr   r   r   Ú	__class__Ú
Comparatorr   r   r   r   r   r   r   ÚreversedÚgetattrÚ	TypeErrorÚ__name__ÚjoinÚsortedÚkeysr
   Úset_creation_orderr   )Úselfr   ÚkwargsÚcolr   ©r*   r   r$   r(   9   sH   Iÿÿþÿÿ

þzColumnProperty.__init__zsqlalchemy.orm.statezsqlalchemy.orm.strategiesc                 C   s   |j  | jj| | j¡| j¡S ©N)ÚInstanceStateÚ"_instance_level_callable_processorÚparentÚclass_managerÚLoadDeferredColumnsÚkey)r4   ÚstateÚ
strategiesr   r   r$   Ú&_memoized_attr__deferred_column_loader­   s
   
ýz5ColumnProperty._memoized_attr__deferred_column_loaderc                 C   s
   | j d S )zJReturn the primary column or expression for this ColumnProperty.

        r   )r   ©r4   r   r   r$   r   µ   s   
zColumnProperty.expressionc                 C   s0   | j sd S tj|j| j|  | |¡|| jd� d S )N)Ú
comparatorÚparententityr   )r   r   Úregister_descriptorÚclass_r>   r   r   )r4   Úmapperr   r   r$   Úinstrument_class¼   s   

ûzColumnProperty.instrument_classc                    sb   t t| ƒ ¡  t| jƒdkr-t| jjƒ | j¡r/t	 
d| j| jd | jd | jf ¡ d S d S d S )Nr   z»On 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_initÚlenr   Úsetr;   Úprimary_keyÚ
issupersetr
   Úwarnr>   rB   r7   r   r$   rI   È   s   ÿúÿýzColumnProperty.do_initc                 C   s   t | j| j| j| jdœŽS )N)r   r   r   )r   r   r   r   r   rB   r   r   r$   Úcopy×   s   ýýzColumnProperty.copyc                 C   s   |  | j¡j|||d�S )N)Úpassive)Úget_implr>   Úget_committed_value)r4   r?   Údict_r   rP   r   r   r$   Ú_getcommittedß   s   ÿzColumnProperty._getcommittedc	                 C   s€   | j sd S | j|v r(|| j }	|s|	|| j< d S | | j¡}
|
 |||	d ¡ d S |jr<| j|vr>|j|| jgdd� d S d S d S )NT)Ú	no_loader)r   r>   rQ   rK   Úhas_identityÚ_expire_attributes)r4   ÚsessionÚsource_stateÚsource_dictÚ
dest_stateÚ	dest_dictÚloadÚ
_recursiveÚ_resolve_conflict_mapÚvalueÚimplr   r   r$   Úmergeæ   s   



ÿÿzColumnProperty.mergec                   @   s<   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )zColumnProperty.Comparatora€  Produce 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`

        )Ú__clause_element__r   c                 C   s4   | j r|   | jjd ¡S | jjd  | j| jdœ¡S )Nr   )rD   Úparentmapper)ÚadapterÚpropr   Ú	_annotateÚ_parententityrB   r   r   r$   Ú#_memoized_method___clause_element__  s   þÿz=ColumnProperty.Comparator._memoized_method___clause_element__c                 C   s,   |   ¡ }z|jW S  ty   | jj Y S w r8   )rc   r   ÚAttributeErrorrf   )r4   Úcer   r   r$   Ú_memoized_attr_info"  s   ÿz-ColumnProperty.Comparator._memoized_attr_infoc                 C   s   t |  ¡ |ƒS )z‡proxy attribute access down to the mapped column.

            this allows user-defined comparison methods to be accessed.
            )r-   rc   )r4   r>   r   r   r$   Ú_fallback_getattr)  s   z+ColumnProperty.Comparator._fallback_getattrc                 O   s   ||   ¡ g|¢R i |¤ŽS r8   )rc   )r4   ÚopÚotherr5   r   r   r$   Úoperate0  s   z!ColumnProperty.Comparator.operatec                 K   s"   |   ¡ }|| ||¡|fi |¤ŽS r8   )rc   Ú_bind_param)r4   rn   ro   r5   r6   r   r   r$   Úreverse_operate3  s   z)ColumnProperty.Comparator.reverse_operateN)
r/   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__ri   rl   rm   rp   rr   r   r   r   r$   r+      s    r+   c                 C   s   t | jjjƒd | j S )NÚ.)Ústrr;   rF   r/   r>   rB   r   r   r$   Ú__str__7  s   zColumnProperty.__str__)r/   rs   rt   ru   Ústrategy_wildcard_keyrv   r(   r
   ÚdependenciesrA   Úpropertyr   rH   rI   rO   r   ÚPASSIVE_OFFrT   rb   ÚMemoizedSlotsr   r+   ry   Ú__classcell__r   r   r7   r$   r      s"    
t

	
ÿ7N)ru   Ú
__future__r   Ú r   Ú
interfacesr   r   r
   r   r	   Úsqlr   Ú__all__Úclass_loggerr   r   r   r   r$   Ú<module>   s   