
    +h9                         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dlmZ ddlmZ ddlmZ ddlmZ g dZej(                   G d de             Zy)z|MapperProperty implementations.

This is a private module which defines the behavior of individual ORM-
mapped attributes.

    )absolute_import   )
attributes)CompositeProperty)ConcreteInheritedProperty)SynonymProperty)PropComparator)StrategizedProperty)RelationshipProperty   )log)util)	coercions)roles)ColumnPropertyr   r   r   r   c                       e Zd ZdZdZdZdZdZ fdZd Z	 e
j                  dd	      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
j0                  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.

    columnTF)columnsgroupdeferred
instrumentcomparator_factory
descriptoractive_historyexpire_on_flushinfodocstrategy_key_creation_order_is_polymorphic_discriminator_mapped_by_synonym_deferred_column_loader_raise_column_loader_renders_in_subqueries	raiseloadc           
      ^   t         t        |           |D cg c]&  }t        j                  t
        j                  |      ( c}| _        |j                  dd      | _	        |j                  dd      | _
        |j                  dd      | _        |j                  dd      | _        |j                  d| j                  j                        | _        |j                  d	d      | _        |j                  d
d      | _        |j                  dd      | _        d|v r|j                  d      | _        d|v r|j                  d      | _        n9t+        | j                        D ]  }t-        |dd      }||| _         n d| _        |rJt/        | j                  j0                  ddj3                  t5        |j7                                           t9        j:                  |        d| j                  fd| j                  ff| _        | j                  r| xj<                  dz  c_        yyc c}w )a4  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 raiseload: if True, indicates the column should raise an error
            when undeferred, rather than loading the value.  This can be
            altered at query time by using the :func:`.deferred` option with
            raiseload=False.

            .. versionadded:: 1.4

            .. seealso::

                :ref:`deferred_raiseload`

        .. seealso::

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

            :ref:`mapper_column_property_sql_expressions` - to map SQL
            expressions

        r   Nr   Fr%   _instrumentTr   r   r   r   r   r   z* received unexpected keyword argument(s): z, r   ))r%   T)superr   __init__r   expectr   LabeledColumnExprRoler   popr   r   r%   r   	__class__
Comparatorr   r   r   r   r   r   reversedgetattr	TypeError__name__joinsortedkeysr   set_creation_orderr   )selfr   kwargsccolr   r-   s         L/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/orm/properties.pyr)   zColumnProperty.__init__G   s   h 	nd,.FM
ABIU88!<
 ZZ.


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

6*DIF?zz%(DH-  c5$/?"DH	   >>**DIIfV[[]6K,LN 
 	% '4??+
 >>!77 Q
s   +H*c                     d| j                   v r| j                  j                  S d| j                   vxs | | j                  j                  vS )N)query_expressionT)r   T)r   strategy_have_default_expressionparent_readonly_propsr7   s    r;   %_memoized_attr__renders_in_subqueriesz4ColumnProperty._memoized_attr__renders_in_subqueries   sJ    %):)::==999!):):: 
333	
    zsqlalchemy.orm.statezsqlalchemy.orm.strategiesc                    t         j                  j                  }t         j                  j                  }|j                  j                  | j                  j                  |j                  | j                        | j                        S N
r   	preloaded	orm_stateorm_strategiesInstanceState"_instance_level_callable_processorr@   class_managerLoadDeferredColumnskeyr7   state
strategiess      r;   &_memoized_attr__deferred_column_loaderz5ColumnProperty._memoized_attr__deferred_column_loader   s_    ((^^22
""EEKK%%**4884HH
 	
rD   c                    t         j                  j                  }t         j                  j                  }|j                  j                  | j                  j                  |j                  | j                  d      | j                        S )NTrG   rP   s      r;   #_memoized_attr__raise_column_loaderz2ColumnProperty._memoized_attr__raise_column_loader   sa    ((^^22
""EEKK%%**488T:HH
 	
rD   c                     | j                   S )zsAllow the ColumnProperty to work in expression before it is turned
        into an instrumented attribute.
        )
expressionrB   s    r;   __clause_element__z!ColumnProperty.__clause_element__   s    
 rD   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   rB   s    r;   rW   zColumnProperty.expression   s    ( ||ArD   c                     | j                   sy t        j                  |j                  | j                  | j                  | |      || j                         y )N)
comparatorparententityr   )r   r   register_descriptorclass_rO   r   r   )r7   mappers     r;   instrument_classzColumnProperty.instrument_class   sB    &&MMHH..tV<	
rD   c                 n   t         t        |           t        | j                        dkD  rt        | j                  j                        j                  | j                        rQt        j                  d| j                  d| j                  d   d| j                  d   d| j                  d	       y y y )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   setr@   primary_key
issupersetr   warnrO   )r7   r-   s    r;   rb   zColumnProperty.do_init  s    nd+-t||q S)@)@%A%L%LLL&
 II ;;Qa$((L&
 rD   c                 l    t        | j                  | j                  | j                  | j                  dS )N)r   r   r   )r   r   r   r   r   rB   s    r;   copyzColumnProperty.copy  s1     \\ ]]**..
 	
rD   c                 \    |j                  | j                        j                  |||      S )N)passive)get_implrO   get_committed_value)r7   rQ   dict_r   rk   s        r;   _getcommittedzColumnProperty._getcommitted$  s0     ~~dhh';;5' < 
 	
rD   c	                 R   | j                   sy | j                  |v rQ|| j                     }	|s|	|| j                  <   y |j                  | j                        }
|
j                  |||	d        y |j                  r/| j                  |vr |j                  || j                  gd       y y y )NT)	no_loader)r   rO   rl   rd   has_identity_expire_attributes)r7   sessionsource_statesource_dict
dest_state	dest_dictload
_recursive_resolve_conflict_mapvalueimpls              r;   mergezColumnProperty.merge+  s     XX$)E&+	$((#!**4884Yt<$$)B))DHH: *  *C$rD   c                   >    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zy
)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`

        )rX   r   expressionsc                    | j                   }|||| j                  j                  d}|}| j                  j                  r,|}| j                  j                  j                  |      }||d<   |j                  |      j                  d|d      S )a  annotate and possibly adapt a column to be returned
            as the mapped-attribute exposed version of the column.

            The column in this context needs to act as much like the
            column in an ORM mapped context as possible, so includes
            annotations to give hints to various ORM functions as to
            the source entity of this column.   It also adapts it
            to the mapper's with_polymorphic selectable if one is
            present.

            )entity_namespacer\   parentmapper	proxy_keyadapt_columnorm)compile_state_pluginplugin_subject)_parententityproprO   _parentmapper_polymorphic_adaptertraverse	_annotate_set_propagate_attrs)r7   r   peannotationsr:   mapper_local_cols         r;   _orm_annotate_columnz.ColumnProperty.Comparator._orm_annotate_columnZ  s     ##B$& " "!YY]]	K C !!66#& ((==FFsK
 /?N+==-BB)."E rD   c                     | j                   r=| j                  | j                  j                  d   | j                  j                        S | j	                  | j                  j                  d         S )Nr   adapterr   r   rO   r   rB   s    r;   #_memoized_method___clause_element__z=ColumnProperty.Comparator._memoized_method___clause_element__  sQ    ||||DII$5$5a$8$))--HH001B1B11EFFrD   c                     | j                         }	 |j                  S # t        $ r | j                  j                  cY S w xY w)z(The .info dictionary for this attribute.)rX   r   AttributeErrorr   )r7   ces     r;   _memoized_attr_infoz-ColumnProperty.Comparator._memoized_attr_info  s=     ((*B&ww! &yy~~%&s    A A c                 $   | j                   rH| j                  j                  D cg c](  }| j                  || j                  j                        * c}S | j                  j                  D cg c]  }| j	                  |       c}S c c}w c c}w )zThe full sequence of columns referenced by this
            attribute, adjusted for any aliasing in progress.

            .. versionadded:: 1.3.17

            r   )r7   r:   s     r;   _memoized_attr_expressionsz4ColumnProperty.Comparator._memoized_attr_expressions  s     ||  $yy00 LLdiimm4  ?Cii>O>O7:D--c2 
s   -B-Bc                 6    t        | j                         |      S )zproxy attribute access down to the mapped column.

            this allows user-defined comparison methods to be accessed.
            )r0   rX   )r7   rO   s     r;   _fallback_getattrz+ColumnProperty.Comparator._fallback_getattr  s    
 4224c::rD   c                 6     || j                         g|i |S rF   )rX   )r7   opotherr8   s       r;   operatez!ColumnProperty.Comparator.operate  s     d--/B%B6BBrD   c                 V    | j                         } ||j                  ||      |fi |S rF   )rX   _bind_param)r7   r   r   r8   r:   s        r;   reverse_operatez)ColumnProperty.Comparator.reverse_operate  s-    ))+Ccoob%0#@@@rD   N)r2   
__module____qualname____doc__	__slots__r   r   r   r   r   r   r    rD   r;   r.   r   E  s6    	$ @	&	P	G	&	"	;	C	ArD   r.   c                 t    t        | j                  j                  j                        dz   | j                  z   S )N.)strr@   r^   r2   rO   rB   s    r;   __str__zColumnProperty.__str__  s+    4;;%%../#5@@rD   )r2   r   r   r   strategy_wildcard_keyinherit_cache_links_to_entityr   r)   rC   r   preload_modulerS   rU   rX   propertyrW   r`   rb   ri   r   PASSIVE_OFFro   r~   MemoizedSlotsr	   r.   r   __classcell__)r-   s   @r;   r   r   &   s     %MI*~8@
 T/1LM
 N
 T/1LM
 N
  *

 
 -7,B,B
4iAT'' iAVArD   r   N)r   
__future__r    r   descriptor_propsr   r   r   
interfacesr	   r
   relationshipsr   r   r   sqlr   r   __all__class_loggerr   r   rD   r;   <module>r      s_    '  / 7 - & + /     JA( JA JArD   