
    ؄_1                         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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                       e Zd ZdZdZdZ ej        d           fd            Z ej	        dd          d	             Z
d
 Zed             Zd Z fdZd Zej        fdZd Z G d dej        e          Zd Z x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           
      F   t          t          |                                            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 r|                    d          | _        n:t%          | j                  D ]}t'          |dd          }|	|| _         nd| _        |rPt)          | j	        j        dd                    t/          |                                                              t3          j        |            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                 6    g | ]}t          j        |          S  )r   _labeled.0cs     ^/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/orm/properties.py
<listcomp>z+ColumnProperty.__init__.<locals>.<listcomp>   s#    FFFj1!44FFF    c                 P    g | ]#}t          j        t          |                    $S r$   )r   r%   r   r&   s     r)   r*   z+ColumnProperty.__init__.<locals>.<listcomp>   s9     
 
 
=>J 4Q 7 788
 
 
r+   r   Nr   F_instrumentTr   r   r   r   r   r   r   z* received unexpected keyword argument(s): z, 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   r1   s        r)   r/   zColumnProperty.__init__:   s    n 	nd##,,...FFgFFF
 
BI
 
 
 ZZ..


:u55 **]D99"(** $.";#
 #
 !**\488K66$jj)95AA%zz*;TBBV

6**DIF??zz%((DHH--    c5$//?"DHE #   	>***DIIfV[[]]6K6K,L,L,LN  
 	%%% '4?+
r+   zsqlalchemy.orm.statezsqlalchemy.orm.strategiesc                     |j                             | j        j        |                    | j                  | j                  S N)InstanceState"_instance_level_callable_processorparentclass_managerLoadDeferredColumnskey)r;   state
strategiess      r)   &_memoized_attr__deferred_column_loaderz5ColumnProperty._memoized_attr__deferred_column_loader   s=    "EEK%**4844H
 
 	
r+   c                     | j         S )zsAllow the ColumnProperty to work in expression before it is turned
        into an instrumented attribute.
        r   r;   s    r)   __clause_element__z!ColumnProperty.__clause_element__   s    
 r+   c                     | 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   rJ   s    r)   r   zColumnProperty.expression   s    ( |Ar+   c                     | j         sd S t          j        |j        | j        |                     | |          || j                   d S )N)
comparatorparententityr   )r   r   register_descriptorclass_rE   r   r   )r;   mappers     r)   instrument_classzColumnProperty.instrument_class   sZ     	F&MH..tV<<	
 	
 	
 	
 	
 	
r+   c                 r   t          t          |                                            t          | j                  dk    rtt          | j        j                                      | j                  rEt          j
        d| j        d| j        d         d| j        d         d| j        d	           d S d S d S )Nr   z
On mapper z, primary key column 'z6' is being combined with distinct primary key column 'r   z' in attribute 'zM'. Use explicit properties to give each column its own mapped attribute name.)r.   r   do_initlenr   setrB   primary_key
issupersetr   warnrE   )r;   r1   s    r)   rU   zColumnProperty.do_init   s    nd##++---t|q  S)@%A%A%L%LL&
 &
  II ;;;Qa$(((L     !   r+   c                 F    t          | j        | j        | j        | j        dS )N)r   r   r   )r   r   r   r   r   rJ   s    r)   copyzColumnProperty.copy   s2     \ ]*.
 
 
 	
r+   c                 b    |                     | j                                      |||          S )N)passive)get_implrE   get_committed_value)r;   rF   dict_r   r^   s        r)   _getcommittedzColumnProperty._getcommitted  s6     ~~dh'';;5' < 
 
 	
r+   c	                 ,   | j         sd S | j        |v rO|| j                 }	|s|	|| j        <   d S |                    | j                  }
|
                    |||	d            d S |j        r)| j        |vr"|                    || j        gd           d S d S d S )NT)	no_loader)r   rE   r_   rW   has_identity_expire_attributes)r;   sessionsource_statesource_dict
dest_state	dest_dictload
_recursive_resolve_conflict_mapvalueimpls              r)   mergezColumnProperty.merge  s      	FX$$)E =&+	$(###!**4844Yt<<<<<$ 	)B)B))DH: *     	 	)B)Br+   c                   :    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	S )
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`

        )rK   r   expressionsc                     | j         r%|                      | j        j        d                   S | j        j        d                             | j        | j        d          S )Nr   )rO   parentmapper)adapterpropr   	_annotate_parententityrJ   s    r)   #_memoized_method___clause_element__z=ColumnProperty.Comparator._memoized_method___clause_element__:  sb    | 
||DI$5a$8999 y(+55(,(:(,(:   r+   c                 r    |                                  }	 |j        S # t          $ r | j        j        cY S w xY w)z(The .info dictionary for this attribute.)rK   r   AttributeErrorrx   )r;   ces     r)   _memoized_attr_infoz-ColumnProperty.Comparator._memoized_attr_infoG  sL     ((**B&w! & & &y~%%%&s    66c                 r      j         r fd j        j        D             S  f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                 :    g | ]}                     |          S r$   )rw   r'   r=   r;   s     r)   r*   zHColumnProperty.Comparator._memoized_attr_expressions.<locals>.<listcomp>X  s%    GGGcS))GGGr+   c                 j    g | ]/}|                     j        j        j        j        d           0S ))rO   rv   orm_key)ry   rz   rx   rE   r   s     r)   r*   zHColumnProperty.Comparator._memoized_attr_expressions.<locals>.<listcomp>\  sV     	 	 	  MM,0,>,0,>'+y}  	 	 	r+   )rw   rx   r   rJ   s   `r)   _memoized_attr_expressionsz4ColumnProperty.Comparator._memoized_attr_expressionsP  s`     | GGGGTY5FGGGG	 	 	 	  $y0	 	 	 	r+   c                 F    t          |                                 |          S )zproxy attribute access down to the mapped column.

            this allows user-defined comparison methods to be accessed.
            )r4   rK   )r;   rE   s     r)   _fallback_getattrz+ColumnProperty.Comparator._fallback_getattrg  s     
 42244c:::r+   c                 >     ||                                  g|R i |S r?   )rK   )r;   opotherr<   s       r)   operatez!ColumnProperty.Comparator.operaten  s.    2d--//B%BBB6BBBr+   c                 f    |                                  } ||                    ||          |fi |S r?   )rK   _bind_param)r;   r   r   r<   r=   s        r)   reverse_operatez)ColumnProperty.Comparator.reverse_operateq  s;    ))++C2coob%00#@@@@@r+   N)r6   
__module____qualname____doc__	__slots__r{   r   r   r   r   r   r$   r+   r)   r2   rs   %  s        	 	$ @		 	 		& 	& 	&	 	 	.	; 	; 	;	C 	C 	C	A 	A 	A 	A 	Ar+   r2   c                 T    t          | j        j        j                  dz   | j        z   S )N.)strrB   rQ   r6   rE   rJ   s    r)   __str__zColumnProperty.__str__u  s$    4;%.//#5@@r+   )r6   r   r   r   strategy_wildcard_keyr   r   deprecated_paramsr/   dependenciesrH   rK   propertyr   rS   rU   r\   r   PASSIVE_OFFrb   rq   MemoizedSlotsr   r2   r   __classcell__)r1   s   @r)   r   r      s         %I( T
  w
 w
 w
 w
 w
r T-/JKK
 
 LK
     X*

 

 

    
 
 
 -7,B
 
 
 
  4NA NA NA NA NAT' NA NA NA`A A A A A A Ar+   N)r   
__future__r    r   
interfacesr   r   r   r   r
   sqlr   __all__class_loggerr   r$   r+   r)   <module>r      s    ' & & & & &       & & & & & & + + + + + + & & & & & &                   
 YA YA YA YA YA( YA YA YA YA YAr+   