o
    i1                     @   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ejdd fddZe	dd	d
d Z
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   zDescribes 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_loader)z0.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.)r   c                    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| _|rt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 mapping.

        Column-based properties can normally be applied to the mapper's
        ``properties`` dictionary using the :class:`_schema.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.

        The :func:`_orm.column_property` function returns an instance of
        :class:`.ColumnProperty`.

        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.

        .. seealso::

            :ref:`column_property_options` - to map columns while including
            mapping options

            :ref:`mapper_column_property_sql_expressions` - to map SQL
            expressions

        c                 S   s   g | ]}t |qS  )r   _labeled.0cr    r    T/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/sqlalchemy/orm/properties.py
<listcomp>       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*   :   sH   W

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)r6   state
strategiesr    r    r%   &_memoized_attr__deferred_column_loader   s
   
z5ColumnProperty._memoized_attr__deferred_column_loaderc                 C   s   | j S )zsAllow the ColumnProperty to work in expression before it is turned
        into an instrumented attribute.
        r   r6   r    r    r%   __clause_element__   s   z!ColumnProperty.__clause_element__c                 C   s
   | j d S )a  Return the primary column or expression for this ColumnProperty.

        E.g.::


            class File(Base):
                # ...

                name = Column(String(64))
                extension = Column(String(8))
                filename = column_property(name + '.' + extension)
                path = column_property('C:/' + filename.expression)

        .. seealso::

            :ref:`mapper_column_property_sql_expressions_composed`

        r   )r   rD   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   )r6   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   zOn 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@   rD   r9   r    r%   rL      s   zColumnProperty.do_initc                 C   s   t | j| j| j| jdS )N)r   r   r   )r   r   r   r   r   rD   r    r    r%   copy   s   zColumnProperty.copyc                 C   s   | | jj|||dS )N)passive)get_implr@   get_committed_value)r6   rA   dict_r   rS   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@   rT   rN   has_identity_expire_attributes)r6   sessionsource_statesource_dict
dest_state	dest_dictload
_recursive_resolve_conflict_mapvalueimplr    r    r%   merge  s   



zColumnProperty.mergec                   @   sD   e Zd ZdZdZd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`

        )rE   r   expressionsc                 C   s4   | j r|  | jjd S | jjd | j| jdS )Nr   )rG   parentmapper)adapterpropr   	_annotate_parententityrD   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 )z(The .info dictionary for this attribute.)rE   r   AttributeErrorri   )r6   cer    r    r%   _memoized_attr_infoG  s   z-ColumnProperty.Comparator._memoized_attr_infoc                    s2    j r fdd jjD S  fdd jjD S )zThe full sequence of columns referenced by this
            attribute, adjusted for any aliasing in progress.

            .. versionadded:: 1.3.17

            c                    s   g | ]}  |qS r    )rh   r#   r8   rD   r    r%   r&   X  r'   zHColumnProperty.Comparator._memoized_attr_expressions.<locals>.<listcomp>c                    s&   g | ]}|  j j jjd qS ))rG   rg   orm_key)rj   rk   ri   r@   rp   rD   r    r%   r&   \  s    )rh   ri   r   rD   r    rD   r%   _memoized_attr_expressionsP  s
   
z4ColumnProperty.Comparator._memoized_attr_expressionsc                 C   s   t |  |S )zproxy attribute access down to the mapped column.

            this allows user-defined comparison methods to be accessed.
            )r/   rE   )r6   r@   r    r    r%   _fallback_getattrg  s   z+ColumnProperty.Comparator._fallback_getattrc                 O   s   ||   g|R i |S r:   )rE   )r6   opotherr7   r    r    r%   operaten  s   z!ColumnProperty.Comparator.operatec                 K   s"   |   }|||||fi |S r:   )rE   _bind_param)r6   rt   ru   r7   r8   r    r    r%   reverse_operateq  s   z)ColumnProperty.Comparator.reverse_operateN)r1   
__module____qualname____doc__	__slots__rl   ro   rr   rs   rv   rx   r    r    r    r%   r-   %  s    	r-   c                 C   s   t | jjjd | j S )N.)strr=   rI   r1   r@   rD   r    r    r%   __str__u  s   zColumnProperty.__str__)r1   ry   rz   r{   strategy_wildcard_keyr|   r
   deprecated_paramsr*   dependenciesrC   rE   propertyr   rK   rL   rR   r   PASSIVE_OFFrW   re   MemoizedSlotsr   r-   r   __classcell__r    r    r9   r%   r      s*    	
y

	
PN)r{   
__future__r    r   
interfacesr   r   r
   r   r	   sqlr   __all__class_loggerr   r    r    r    r%   <module>   s   