a
    [gq                     @  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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 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) d d$lm$Z$ d d%l*m+Z+ d d&l*m,Z, d d'l-m.Z. d d(l/m0Z0 d d)l/m1Z1 d d*l2m3Z3 d d+l4m5Z5 d d,l4m6Z6 d d-l4m7Z7 d d.l4m8Z8 d d/l4m9Z9 d d0l4m:Z: d d1l4m;Z; erdd2l<m=Z= dd3l<m>Z> dd4l<m?Z? dd5l<m@Z@ dd6lmAZA dd7lBmCZC dd8lDmEZE dd9lFmGZG dd:lHmIZI dd;lHmJZJ d d<lKmLZL d d=lMmNZN d d>lMmOZO d d?lPmQZQ d d@l4mRZR d dAl4mSZS edBedCZTedDedCZUedEdFdCZVg dGZWe)jXG dHdI dIeeT e!eT ee)jYZZG dJdK dKeZeT eeT Z[G dLdM dMeeeT eeT Z\dNS )Oz|MapperProperty implementations.

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

    )annotations)Any)cast)Dict)List)Optional)Sequence)Set)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )
attributes)strategy_options)_DeclarativeMapped)class_mapper)CompositeProperty)ConcreteInheritedProperty)SynonymProperty)_AttributeOptions)_DEFAULT_ATTRIBUTE_OPTIONS)_IntrospectsAnnotations)_MapsColumns)MapperProperty)PropComparator)StrategizedProperty)RelationshipProperty)de_stringify_annotation   )exc)
ForeignKey)log)util)	coercions)roles)_NoArg)Column)SchemaConst)
TypeEngine)de_optionalize_union_types)get_args)includes_none)
is_fwd_ref)	is_pep593)	is_pep695)Self)_IdentityKeyType)_InstanceDict)_ORMColumnExprArgument)_RegistryType)Mapped)_ClassScanMapperConfig)Mapper)Session)_InstallLoaderCallableProto)InstanceState)	_InfoType)ColumnElement)NamedColumn)OperatorType)_AnnotationScanType)RODescriptorReference_T)bound_PT_NCzNamedColumn[Any])ColumnPropertyr   r   r   r   c                      s  e Zd ZU dZejZdZdZde	d< de	d< de	d	< d
e	d< dZ
dddddddddddddddddddddddddd fddZddddddddddd
dd Zed!d"d#d$Zed%d"d&d'Zdd"d(d)Zed*d+d,d"d-d.Zed*d+d,d"d/d0Zd1d"d2d3Zed1d"d4d5Zd6dd7d8d9Zdd" fd:d;Zd<d"d=d>Zd?d@dAd@dAddBdCddD	dEdFZG dGdH dHejee Zdd"dIdJZ  Z S )KrF   zDescribes an object attribute that corresponds to a table column
    or other column expression.

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

    TFzList[NamedColumn[Any]]columnsbool_is_polymorphic_discriminatorOptional[str]_mapped_by_synonymzType[PropComparator[_T]]comparator_factory)rG   groupdeferred
instrumentrL   active_historyexpire_on_flush_creation_orderrI   rK   Z_deferred_column_loaderZ_raise_column_loaderZ_renders_in_subqueries	raiseloadN)attribute_optionsrM   rN   rS   rL   rP   rQ   infodoc_instrument_assume_readonly_dc_attributesz_ORMColumnExprArgument[_T]z_ORMColumnExprArgument[Any]zOptional[_AttributeOptions]z"Optional[Type[PropComparator[_T]]]zOptional[_InfoType])columnadditional_columnsrT   rM   rN   rS   rL   rP   rQ   rU   rV   rW   rX   c                  s   t  j||d |f| }dd |D | _|| _|| _|| _|| _|d urN|n| jj| _	|| _
|| _|	d urx| j|	 |
d ur|
| _n4t| jD ]"}t|dd }
|
d ur|
| _ qqd | _t|  d| jfd| jff| _| jr|  jd7  _d S )N)rT   rX   c                 S  s   g | ]}t tj|qS  )r%   expectr&   ZLabeledColumnExprRole.0cr[   r[   g/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/sqlalchemy/orm/properties.py
<listcomp>   s   z+ColumnProperty.__init__.<locals>.<listcomp>rV   rN   rO   ))rS   T)super__init__rG   rM   rN   rS   rO   	__class__
ComparatorrL   rP   rQ   rU   updaterV   reversedgetattrr$   set_creation_orderstrategy_key)selfrY   rT   rM   rN   rS   rL   rP   rQ   rU   rV   rW   rX   rZ   rG   colrd   r[   r`   rc      sD    

zColumnProperty.__init__r7   r5   	Type[Any]strOptional[Type[Mapped[Any]]]Optional[_AnnotationScanType]None
	decl_scanregistryclsoriginating_modulekeymapped_container
annotationextracted_mapped_annotationis_dataclass_fieldreturnc
                 C  s.   | j d }
|
jd u r||
_|
jd u r*||
_d S Nr   )rG   rx   name)rk   rt   ru   rv   rw   rx   ry   rz   r{   r|   rY   r[   r[   r`   declarative_scan   s
    


zColumnProperty.declarative_scanOptional[MapperProperty[_T]]r}   c                 C  s   | S Nr[   rk   r[   r[   r`   mapper_property_to_assign   s    z(ColumnProperty.mapper_property_to_assignList[Tuple[Column[Any], int]]c                 C  s   dd | j D S )Nc                 S  s(   g | ] }t |tr|jd u r|dfqS r~   )
isinstancer(   tabler]   r[   r[   r`   ra      s   z4ColumnProperty.columns_to_assign.<locals>.<listcomp>rG   r   r[   r[   r`   columns_to_assign   s    z ColumnProperty.columns_to_assignc                 C  s(   d| j v r| jjS d| j vp&| | jjvS )N)Zquery_expressionT)rN   T)rj   ZstrategyZ_have_default_expressionparentZ_readonly_propsr   r[   r[   r`   %_memoized_attr__renders_in_subqueries   s
    


z4ColumnProperty._memoized_attr__renders_in_subquerieszsqlalchemy.orm.statezsqlalchemy.orm.strategiesz _InstallLoaderCallableProto[Any]c                 C  s.   t jj}t jj}|j| jj|| j	| j	S r   
r$   	preloadedZ	orm_stateZorm_strategiesr;   Z"_instance_level_callable_processorr   Zclass_managerZLoadDeferredColumnsrx   rk   state
strategiesr[   r[   r`   &_memoized_attr__deferred_column_loader   s    
z5ColumnProperty._memoized_attr__deferred_column_loaderc                 C  s0   t jj}t jj}|j| jj|| j	d| j	S )NTr   r   r[   r[   r`   #_memoized_attr__raise_column_loader   s    z2ColumnProperty._memoized_attr__raise_column_loaderzroles.ColumnsClauseRolec                 C  s   | j S )zsAllow the ColumnProperty to work in expression before it is turned
        into an instrumented attribute.
        )
expressionr   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   r   r[   r[   r`   r     s    zColumnProperty.expressionzMapper[Any])mapperr}   c                 C  s0   | j s
d S tj|j| j| | ||| jd d S )N)Z
comparatorparententityrV   )rO   r   Zregister_descriptorclass_rx   rL   rV   )rk   r   r[   r[   r`   instrument_class#  s    
zColumnProperty.instrument_classc                   sV   t    t| jdkrRt| jj| jrRt	d| j| jd | jd | j
f  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   )rb   do_initlenrG   setr   Zprimary_key
issupersetr$   warnrx   r   rm   r[   r`   r   /  s    
zColumnProperty.do_initzColumnProperty[_T]c                 C  s   t | j| j| j| jdS )N)rN   rM   rP   )rF   rG   rN   rM   rP   r   r[   r[   r`   copy?  s    zColumnProperty.copyr9   zInstanceState[Any]r3   zDict[Any, object]z#Dict[_IdentityKeyType[Any], object])	sessionsource_statesource_dict
dest_state	dest_dictload
_recursive_resolve_conflict_mapr}   c	                 C  st   | j s
d S | j|v rL|| j }	|s.|	|| j< qp|| j}
|
|||	d  n$|jrp| j|vrp|j|| jgdd d S )NT)Z	no_loader)rO   rx   Zget_implr   Zhas_identityZ_expire_attributes)rk   r   r   r   r   r   r   r   r   valueimplr[   r[   r`   mergeG  s    


zColumnProperty.mergec                   @  s   e Zd ZU dZesdZded< ded< dddd	d
ZerHddddZddddZ	ddddZ
ddddZdddddZdddddddZddddd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`

        )r   rU   expressionsz*RODescriptorReference[ColumnProperty[_PT]]propzSequence[NamedColumn[Any]]r   rE   )rY   r}   c                 C  sT   | j }|||| jjd}|}| jjr>|}| jj|}||d< ||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.

            )Zentity_namespacer   Zparentmapper	proxy_keyZadapt_columnZorm)Zcompile_state_pluginZplugin_subject)Z_parententityr   rx   Z_parentmapperZ_polymorphic_adaptertraverseZ	_annotateZ_set_propagate_attrs)rk   rY   per   rl   Zmapper_local_colr[   r[   r`   _orm_annotate_column  s    
z.ColumnProperty.Comparator._orm_annotate_columnzNamedColumn[_PT]r   c                 C  s   d S r   r[   r   r[   r[   r`   r         z,ColumnProperty.Comparator.__clause_element__c                 C  s4   | j r|  | jjd | jjS | | jjd S d S r~   )adapterr   rG   rx   r   r   r[   r[   r`   #_memoized_method___clause_element__  s    z=ColumnProperty.Comparator._memoized_method___clause_element__r<   c                 C  s0   |   }z|jW S  ty*   | jj Y S 0 dS )z(The .info dictionary for this attribute.N)r   rU   AttributeErrorr   )rk   Zcer[   r[   r`   _memoized_attr_info  s
    z-ColumnProperty.Comparator._memoized_attr_infoc                   s6    j r fdd jjD S  fdd jjD S dS )zThe full sequence of columns referenced by this
            attribute, adjusted for any aliasing in progress.

            .. versionadded:: 1.3.17

            c                   s   g | ]}  | jjqS r[   )r   r   rx   r^   rl   r   r[   r`   ra     s   zHColumnProperty.Comparator._memoized_attr_expressions.<locals>.<listcomp>c                   s   g | ]}  |qS r[   )r   r   r   r[   r`   ra     s   N)r   r   rG   r   r[   r   r`   _memoized_attr_expressions  s    

z4ColumnProperty.Comparator._memoized_attr_expressionsro   r   )rx   r}   c                 C  s   t |  |S )zproxy attribute access down to the mapped column.

            this allows user-defined comparison methods to be accessed.
            )rh   r   )rk   rx   r[   r[   r`   _fallback_getattr  s    z+ColumnProperty.Comparator._fallback_getattrr?   ColumnElement[Any]opotherkwargsr}   c                 O  s   ||   g|R i |S r   r   rk   r   r   r   r[   r[   r`   operate  s    z!ColumnProperty.Comparator.operatec                 K  s"   |   }|||||fi |S r   r   Z_bind_paramrk   r   r   r   rl   r[   r[   r`   reverse_operate  s    z)ColumnProperty.Comparator.reverse_operateN)__name__
__module____qualname____doc__r   	__slots____annotations__r   r   r   r   r   r   r   r   r[   r[   r[   r`   re   a  s   
(	re   c                 C  s.   | j r| jst| S t| j jjd | j S )N.)r   rx   object__repr__ro   r   r   r   r[   r[   r`   __str__  s    
zColumnProperty.__str__)!r   r   r   r   r   Z_COLUMN_TOKENZstrategy_wildcard_keyinherit_cacheZ_links_to_entityr   r   rc   r   propertyr   r   r   r$   preload_moduler   r   r   r   r   r   r   r   ZMemoizedSlotsr   rD   re   r   __classcell__r[   r[   rm   r`   rF   _   sR   
.; 

 rF   c                   @  s   e Zd ZdZdZdS )MappedSQLExpressionaN  Declarative front-end for the :class:`.ColumnProperty` class.

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

    .. versionchanged:: 2.0 Added :class:`_orm.MappedSQLExpression` as
       a Declarative compatible subclass for :class:`_orm.ColumnProperty`.

    .. seealso::

        :class:`.MappedColumn`

    TN)r   r   r   r   r   r[   r[   r[   r`   r     s   r   c                   @  s:  e Zd ZU dZdZded< ded< ded< d	ed
< ded< ded< dddddZdddddZeddddZ	eddddZ
edddd Zd	dd!d"Zd#ddd$d%d&d'Zd#ddd$d%d(d)Zddd*d+Zd,d-d.ddd/d0d0dd1d2
d3d4Zed5d-d.dddd6d1d7d8d9Zd.d-d6dd1d:d;d<Zd=S )>MappedColumna_  Maps a single :class:`_schema.Column` on a class.

    :class:`_orm.MappedColumn` is a specialization of the
    :class:`_orm.ColumnProperty` class and is oriented towards declarative
    configuration.

    To construct :class:`_orm.MappedColumn` objects, use the
    :func:`_orm.mapped_column` constructor function.

    .. versionadded:: 2.0


    )rY   rR   _sort_orderforeign_keys_has_nullable_has_insert_defaultrN   deferred_groupdeferred_raiseloadrP   _attribute_options_has_dataclass_arguments_use_existing_columnzUnion[_NoArg, bool]rN   rH   r   rJ   r   
Column[_T]rY   zOptional[Set[ForeignKey]]r   r   r   r   )argkwc                   s&  | dt | _ | dd| _ d uoJ tkoJt fddt jD | _| dtj	}|tj	u| _
| j
rx||d< n jtj	ur j|d< | dd | _| d	d | _| d
tj	| _| dd| _| dtj	| _tdt|i || _| jj| _d|v o|dd tjfv| _t|  d S )NrT   Zuse_existing_columnFc                 3  s(   | ] \}}|d kr | t juV  qdS )dataclasses_defaultN)r'   NO_ARG)r^   iattrZ	attr_optsr[   r`   	<genexpr>2  s   z(MappedColumn.__init__.<locals>.<genexpr>insert_defaultdefaultr   r   rN   rP   Z
sort_orderr   nullable)popr   r   r   any	enumerate_fieldsr   r'   r   r   r   r   r   rN   rP   r   r   r(   rY   r   getr)   ZNULL_UNSPECIFIEDr   r$   ri   )rk   r   r   r   r[   r   r`   rc   (  s:    




zMappedColumn.__init__r1   )r   r}   c                 K  s   | j | j }| jjf i ||_| j|_| j|_| j|_|jj|_| j|_| j	|_	| j
|_
| j|_| j|_| j|_| j|_t| |S r   )rd   __new__rY   _copyrN   r   r   r   rP   r   r   r   r   r   r   r$   ri   )rk   r   newr[   r[   r`   r   O  s    

zMappedColumn._copyro   r   c                 C  s   | j jS r   )rY   r   r   r[   r[   r`   r   `  s    zMappedColumn.namer   c                 C  sP   | j }|tju r t| jp| j}|s*| jrHt| j|| j| j| j	| jdS d S d S )N)rN   rM   rS   rT   rP   )
rN   r'   r   rH   r   r   rP   rF   rY   r   )rk   Zeffective_deferredr[   r[   r`   r   d  s    


	z&MappedColumn.mapper_property_to_assignr   c                 C  s   | j | jtjur| jndfgS r~   )rY   r   r'   r   r   r[   r[   r`   r   x  s    
zMappedColumn.columns_to_assignc                 C  s   | j S r   )rY   r   r[   r[   r`   r     s    zMappedColumn.__clause_element__r?   r   r   c                 O  s   ||   g|R i |S r   r   r   r[   r[   r`   r     s    zMappedColumn.operatec                 K  s"   |   }|||||fi |S r   r   r   r[   r[   r`   r     s    zMappedColumn.reverse_operatec                 C  s   t  S r   )r   r   r[   r[   r`   found_in_pep593_annotated  s    z&MappedColumn.found_in_pep593_annotatedr7   r5   rn   rp   rq   rr   rs   c
                 C  s   | j }
| jr^|jr^|jr^|jr(tdt|jd}|
jd urD|
jn|}|j	j
||
 }
| _ |
jd u rn||
_|
jd u r~||
_|
j}|d u r|jr| j js| || nd S | |||| d S )Nz3Can't use use_existing_column with deferred mappersF)rY   r   ZinheritssingleZis_deferredsa_excArgumentErrorr   r   Zlocal_tabler_   r   rx   type_isnullr   Z_raise_for_required_init_column_for_annotation)rk   rt   ru   rv   rw   rx   ry   rz   r{   r|   rY   Zsupercls_mapperZcolnamesqltyper[   r[   r`   r     s>    


zMappedColumn.declarative_scanzsqlalchemy.orm.decl_baser@   )ru   rv   rw   rx   
param_nameparam_annotationr}   c                 C  s*   t jj}||| j | |||| d S r   )r$   r   Zorm_decl_baseZ_undefer_column_namerY   r   )rk   ru   rv   rw   rx   r   r   	decl_baser[   r[   r`   declarative_scan_for_composite  s
    
z+MappedColumn.declarative_scan_for_composite)rv   ru   argumentrw   r}   c                 C  s  | j j}t|dddr2|d us"J t|||dd}t|}| jsH|| j _t|}d}d}	d }
t|rd}	t	|}|d }
|rt|
}
|dd  }n$t
|rt|jrt	|jdd  }|D ]}t|tr|} qqd }|d ur6| js|j jd urd | j _|j | j  | j j}|jtjur4| jtju r4|j| _|jd urT| jd u rT|j| _|jd urt| jd u rt|j| _|jr| jsd| _|jr|j| _|jd ur| jtju r|j| _|j jd us|j jd urtdd	 |jr6t|jj D ]<\}}|j| tjur|!d
d}td| dd	 q|j"r| j j#sd }|	r\||
g}n|g}|D ] }|$|}|d urf qqft|t%st|trt&|t%rt'(d| j jd| dnt'(d| d| j jd| j )| d S )NT)Zcheck_genericZcheck_for_plain_string)Zinclude_genericr[   Fr   r   z_Can't use the 'key' or 'name' arguments in Annotated with mapped_column(); this will be ignoredz2.0.22Zdataclasses_ z
Argument 'zp' is a dataclass argument and cannot be specified within a mapped_column() bundled inside of an Annotated objectzThe type provided inside the z4 attribute Mapped annotation is the SQLAlchemy type z . Expected a Python type insteadz6Could not locate SQLAlchemy Core type for Python type z inside the z attribute Mapped annotation)*rY   r   r.   r   r-   r   r   r+   r/   r,   r0   Z	__value__r   r   r   r   _mergerN   r'   r   r   r   r   rP   r   rx   r   r$   Zwarn_deprecatedr   r   r   r   replacer   r   Z_resolve_typer*   
issubclassr   r   Z	_set_type)rk   rv   ru   r   rw   r   r   Zour_typeZfind_mapped_inZour_type_is_pep593Zraw_pep_593_typeZpep_593_componentselemZuse_args_fromidxr   Znew_sqltypeZchecksZ
check_typer[   r[   r`   r     s    












z(MappedColumn._init_column_for_annotationN)r   r   r   r   r   r   rc   r   r   r   r   r   r   r   r   r   r   r$   r   r   r   r[   r[   r[   r`   r     s0   
' 2r   N)]r   
__future__r   typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   baser   r   Zdescriptor_propsr   r   r   Z
interfacesr   r   r   r   r   r   r   Zrelationshipsr   r$   r   r!   r   r"   r#   sqlr%   r&   Zsql.baser'   Z
sql.schemar(   r)   Zsql.type_apir*   Zutil.typingr+   r,   r-   r.   r/   r0   r1   Z_typingr2   r3   r4   r5   r6   r   r7   r   r8   r   r9   r   r:   r;   Zsql._typingr<   Zsql.elementsr=   r>   Zsql.operatorsr?   r@   rA   rB   rD   rE   __all__Zclass_loggerZ
IdentifiedrF   r   r   r[   r[   r[   r`   <module>   s   	
   
