o
    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ryd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                      s4  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de fd d!Zdfd3d4Zedgd6d7Zedhd9d:Zdid;d<Zed=d>djd@dAZed=d>djdBdCZdkdEdFZedkdGdHZdldKdLZdm fdMdNZdndPdQZdod_d`ZG dadb dbejee ZdpdcddZ  Z S )qrF   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   _deferred_column_loader_raise_column_loader_renders_in_subqueries	raiseloadN)attribute_optionsrM   rN   rV   rL   rP   rQ   infodoc_instrument_assume_readonly_dc_attributescolumn_ORMColumnExprArgument[_T]additional_columns_ORMColumnExprArgument[Any]rW   Optional[_AttributeOptions]rM   rN   rV   "Optional[Type[PropComparator[_T]]]rP   rQ   rX   Optional[_InfoType]rY   rZ   r[   c                  s   t  j||d |f| }dd |D | _|| _|| _|| _|| _|d ur'|n| jj| _	|| _
|| _|	d ur<| j|	 |
d urD|
| _nt| jD ]}t|dd }
|
d urZ|
| _ nqId | _t|  d| jfd| jff| _| jrz|  jd7  _d S d S )N)rW   r[   c                 S  s   g | ]	}t tj|qS  )r%   expectr&   LabeledColumnExprRole.0crc   rc   S/var/www/html/api-tag/env/lib/python3.10/site-packages/sqlalchemy/orm/properties.py
<listcomp>   s    z+ColumnProperty.__init__.<locals>.<listcomp>rY   rN   rO   ))rV   T)super__init__rG   rM   rN   rV   rO   	__class__
ComparatorrL   rP   rQ   rX   updaterY   reversedgetattrr$   set_creation_orderstrategy_key)selfr\   rW   rM   rN   rV   rL   rP   rQ   rX   rY   rZ   r[   r^   rG   colrm   rc   ri   rl      sH   

zColumnProperty.__init__	decl_scanr7   registryr5   cls	Type[Any]originating_modulekeystrmapped_containerOptional[Type[Mapped[Any]]]
annotationOptional[_AnnotationScanType]extracted_mapped_annotationis_dataclass_fieldreturnNonec
                 C  s2   | j d }
|
jd u r||
_|
jd u r||
_d S d S Nr   )rG   r|   name)rt   rw   rx   ry   r{   r|   r~   r   r   r   r\   rc   rc   ri   declarative_scan   s   



zColumnProperty.declarative_scanOptional[MapperProperty[_T]]c                 C  s   | S Nrc   rt   rc   rc   ri   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(   tablerf   rc   rc   ri   rj      s    
z4ColumnProperty.columns_to_assign.<locals>.<listcomp>rG   r   rc   rc   ri   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)query_expressionT)rN   T)rs   strategy_have_default_expressionparent_readonly_propsr   rc   rc   ri   %_memoized_attr__renders_in_subqueries   s
   


z4ColumnProperty._memoized_attr__renders_in_subquerieszsqlalchemy.orm.statezsqlalchemy.orm.strategies _InstallLoaderCallableProto[Any]c                 C  s.   t jj}t jj}|j| jj|| j	| j	S r   
r$   	preloaded	orm_stateorm_strategiesr;   "_instance_level_callable_processorr   class_managerLoadDeferredColumnsr|   rt   state
strategiesrc   rc   ri   &_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   rc   rc   ri   #_memoized_attr__raise_column_loader   s   z2ColumnProperty._memoized_attr__raise_column_loaderroles.ColumnsClauseRolec                 C     | j S )zsAllow the ColumnProperty to work in expression before it is turned
        into an instrumented attribute.
        )
expressionr   rc   rc   ri   __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   rc   rc   ri   r     s   
zColumnProperty.expressionmapperMapper[Any]c                 C  s0   | j sd S tj|j| j| | ||| jd d S )N)
comparatorparententityrY   )rO   r   register_descriptorclass_r|   rL   rY   )rt   r   rc   rc   ri   instrument_class#  s   

zColumnProperty.instrument_classc                   s^   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   )rk   do_initlenrG   setr   primary_key
issupersetr$   warnr|   r   rv   rc   ri   r   /  s   
zColumnProperty.do_initColumnProperty[_T]c                 C  s   t | j| j| j| jdS )N)rN   rM   rP   )rF   rG   rN   rM   rP   r   rc   rc   ri   copy?  s   zColumnProperty.copysessionr9   source_stateInstanceState[Any]source_dictr3   
dest_state	dest_dictload
_recursiveDict[Any, object]_resolve_conflict_map#Dict[_IdentityKeyType[Any], object]c	                 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)rO   r|   get_implr   has_identity_expire_attributes)rt   r   r   r   r   r   r   r   r   valueimplrc   rc   ri   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Zer d&ddZd&ddZ	d'ddZ
d(ddZd)ddZd*d d!Z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   rX   expressionsz*RODescriptorReference[ColumnProperty[_PT]]propSequence[NamedColumn[Any]]r   r\   rE   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.

            )entity_namespacer   parentmapper	proxy_keyadapt_columnorm)compile_state_pluginplugin_subject)_parententityr   r|   _parentmapper_polymorphic_adaptertraverse	_annotate_set_propagate_attrs)rt   r\   per   ru   mapper_local_colrc   rc   ri   _orm_annotate_column  s   
z.ColumnProperty.Comparator._orm_annotate_columnNamedColumn[_PT]c                 C  s   d S r   rc   r   rc   rc   ri   r     s    z,ColumnProperty.Comparator.__clause_element__c                 C  s0   | j r|  | jjd | jjS | | jjd S r   )adapterr   rG   r|   r   r   rc   rc   ri   #_memoized_method___clause_element__  s   z=ColumnProperty.Comparator._memoized_method___clause_element__r<   c                 C  s,   |   }z|jW S  ty   | jj Y S w )z(The .info dictionary for this attribute.)r   rX   AttributeErrorr   )rt   cerc   rc   ri   _memoized_attr_info  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 | ]
}  | jjqS rc   )r   r   r|   rg   ru   r   rc   ri   rj     s    zHColumnProperty.Comparator._memoized_attr_expressions.<locals>.<listcomp>c                   s   g | ]}  |qS rc   )r   r   r   rc   ri   rj     s    
)r   r   rG   r   rc   r   ri   _memoized_attr_expressions  s   

z4ColumnProperty.Comparator._memoized_attr_expressionsr|   r}   r   c                 C  s   t |  |S )zproxy attribute access down to the mapped column.

            this allows user-defined comparison methods to be accessed.
            )rq   r   )rt   r|   rc   rc   ri   _fallback_getattr  s   z+ColumnProperty.Comparator._fallback_getattropr?   otherkwargsColumnElement[Any]c                 O     ||   g|R i |S r   r   rt   r   r   r   rc   rc   ri   operate     z!ColumnProperty.Comparator.operatec                 K  "   |   }|||||fi |S r   r   _bind_paramrt   r   r   r   ru   rc   rc   ri   reverse_operate     z)ColumnProperty.Comparator.reverse_operateN)r\   rE   r   rE   )r   r   )r   r<   )r   r   )r|   r}   r   r   r   r?   r   r   r   r   r   r   )__name__
__module____qualname____doc__r   	__slots____annotations__r   r   r   r   r   r   r   r   rc   rc   rc   ri   rn   a  s    
 

(



	

rn   c                 C  s.   | j r| jst| S t| j jjd | j S )N.)r   r|   object__repr__r}   r   r   r   rc   rc   ri   __str__  s   
zColumnProperty.__str__)r\   r]   r^   r_   rW   r`   rM   rJ   rN   rH   rV   rH   rL   ra   rP   rH   rQ   rH   rX   rb   rY   rJ   rZ   rH   r[   rH   rw   r7   rx   r5   ry   rz   r{   rJ   r|   r}   r~   r   r   r   r   r   r   rH   r   r   r   r   r   r   )r   rH   )r   r   )r   r   )r   r   r   r   )r   r   )r   r   )r   r9   r   r   r   r3   r   r   r   r3   r   rH   r   r   r   r   r   r   r   r}   )!r   r   r   r   r   _COLUMN_TOKENstrategy_wildcard_keyinherit_cache_links_to_entityr   r   rl   r   propertyr   r   r   r$   preload_moduler   r   r   r   r   r   r   r   MemoizedSlotsr   rD   rn   r   __classcell__rc   rc   rv   ri   rF   _   sV   
 
;






 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  rc   rc   rc   ri   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< dIddZdJddZedKddZ	edLddZ
edMdd ZdNd!d"ZdOd(d)ZdOd*d+ZdPd,d-ZdQd=d>Zed?dRdCdDZdSdFdGZdHS )T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


    )r\   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]r\   zOptional[Set[ForeignKey]]r  r   r  argr   kwc                   s$  | dt | _ | dd| _ d uo% tko%t fddt jD | _| dtj	}|tj	u| _
| j
r<||d< n jtj	urG 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 )NrW   use_existing_columnFc                 3  s*    | ]\}}|d kr | t juV  qdS )dataclasses_defaultN)r'   NO_ARG)rg   iattr	attr_optsrc   ri   	<genexpr>2  s    z(MappedColumn.__init__.<locals>.<genexpr>insert_defaultdefaultr  r  rN   rP   
sort_orderr  nullable)popr   r  r  any	enumerate_fieldsr  r'   r  r  r  r  r  rN   rP   r  r   r(   r\   r  getr)   NULL_UNSPECIFIEDr  r$   rr   )rt   r  r  r"  rc   r  ri   rl   (  s:   




zMappedColumn.__init__r   r1   c                 K  s   | j | j }| jjdi ||_| j|_| j|_| j|_|jj|_| j|_| j	|_	| j
|_
| j|_| j|_| j|_| j|_t| |S )Nrc   )rm   __new__r\   _copyrN   r  r  r  rP   r  r  r  r  r  r  r$   rr   )rt   r  newrc   rc   ri   r-  O  s   

zMappedColumn._copyr}   c                 C  s   | j jS r   )r\   r   r   rc   rc   ri   r   `  s   zMappedColumn.namer   c                 C  sL   | j }|tju rt| jp| j}|s| jr$t| j|| j| j| j	| jdS d S )N)rN   rM   rV   rW   rP   )
rN   r'   r  rH   r  r  rP   rF   r\   r  )rt   effective_deferredrc   rc   ri   r   d  s   


	z&MappedColumn.mapper_property_to_assignr   c                 C  s"   | j | jtjur| jfgS dfgS r   )r\   r  r'   r  r   rc   rc   ri   r   x  s   zMappedColumn.columns_to_assignc                 C  r   r   )r\   r   rc   rc   ri   r     s   zMappedColumn.__clause_element__r   r?   r   r   r   c                 O  r   r   r   r   rc   rc   ri   r     r   zMappedColumn.operatec                 K  r   r   r   r   rc   rc   ri   r     r   zMappedColumn.reverse_operatec                 C  s   t  S r   )r  r   rc   rc   ri   found_in_pep593_annotated  s   z&MappedColumn.found_in_pep593_annotatedrw   r7   rx   r5   ry   rz   r{   r|   r~   r   r   r   r   r   r   c
                 C  s   | j }
| jr/|jr/|jr/|jrtdt|jd}|
jd ur"|
jn|}|j	j
||
 }
| _ |
jd u r7||
_|
jd u r?||
_|
j}|d u rV|jrT| j jsT| || nd S | |||| d S )Nz3Can't use use_existing_column with deferred mappersF)r\   r  inheritssingleis_deferredsa_excArgumentErrorr   r   local_tablerh   r*  r|   type_isnullr  _raise_for_required_init_column_for_annotation)rt   rw   rx   ry   r{   r|   r~   r   r   r   r\   supercls_mappercolnamesqltyperc   rc   ri   r     s>   


zMappedColumn.declarative_scanzsqlalchemy.orm.decl_base
param_nameparam_annotationr@   c                 C  s*   t jj}||| j | |||| d S r   )r$   r   orm_decl_base_undefer_column_namer\   r:  )rt   rx   ry   r{   r|   r>  r?  	decl_baserc   rc   ri   declarative_scan_for_composite  s
   
z+MappedColumn.declarative_scan_for_compositeargumentc                 C  s  | j j}t|dddr|d usJ t|||dd}t|}| js$|| j _t|}d}d}	d }
t|rId}	t	|}|d }
|rBt|
}
|dd  }nt
|r[t|jr[t	|jdd  }|D ]}t|trh|} nq]d }|d ur| js}|j jd ur}d | j _|j | j  | j j}|jtjur| jtju r|j| _|jd ur| jd u r|j| _|jd ur| jd u r|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rt|jj D ]\}}|j| tjur|!d
d}td| dd	 q|j"rk| j j#smd }|	r ||
g}n|g}|D ]}|$|}|d ur3 n0q%t|t%sGt|trUt&|t%rUt'(d| j jd| dt'(d| d| j jd| j )| d S d S d S )NT)check_genericcheck_for_plain_string)include_genericrc   Fr   r   z_Can't use the 'key' or 'name' arguments in Annotated with mapped_column(); this will be ignoredz2.0.22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)*r\   r7  r.   r   r-   r  r%  r+   r/   r,   r0   	__value__r   r  r  r#  _mergerN   r'   r  r  r  r  rP   r  r|   r   r$   warn_deprecatedr  r(  r  r)  replacer8  r  _resolve_typer*   
issubclassr4  r5  	_set_type)rt   ry   rx   rD  r{   r=  r%  our_typefind_mapped_inour_type_is_pep593raw_pep_593_typepep_593_componentselemuse_args_fromidxr  new_sqltypechecks
check_typerc   rc   ri   r:    s   










z(MappedColumn._init_column_for_annotationN)r  r   r  r   )r  r   r   r1   r  r  r  )r   r  r   )r   r   r   )rx   r5   ry   rz   r{   rJ   r|   r}   r>  r}   r?  r@   r   r   )
ry   rz   rx   r5   rD  r@   r{   rJ   r   r   )r   r   r   r   r   r   rl   r-  r  r   r   r   r   r   r   r0  r   r$   r	  rC  r:  rc   rc   rc   ri   r    s2   
 

'




2r  N)]r   
__future__r   typingr   r   r   r   r   r   r	   r
   r   r   r   r   rI  r   r   baser   r   descriptor_propsr   r   r   
interfacesr   r   r   r   r   r   r   relationshipsr   r$   r   r!   r4  r"   r#   sqlr%   r&   sql.baser'   
sql.schemar(   r)   sql.type_apir*   util.typingr+   r,   r-   r.   r/   r0   r1   _typingr2   r3   r4   r5   r6   rB  r7   r   r8   r   r9   r   r:   r;   sql._typingr<   sql.elementsr=   r>   sql.operatorsr?   r@   rA   rB   rD   rE   __all__class_logger
IdentifiedrF   r  r  rc   rc   rc   ri   <module>   s   	
   
