o
    E6dk                     @  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   )
attributes)strategy_options)_DeclarativeMapped)class_mapper)CompositeProperty)ConcreteInheritedProperty)SynonymProperty)_AttributeOptions)_DEFAULT_ATTRIBUTE_OPTIONS)_IntrospectsAnnotations)_MapsColumns)MapperProperty)PropComparator)StrategizedProperty)RelationshipProperty)de_stringify_annotation)de_stringify_union_elements   )exc)
ForeignKey)log)util)	coercions)roles)_NoArg)Column)SchemaConst)
TypeEngine)de_optionalize_union_types)
is_fwd_ref)is_optional_union)	is_pep593)is_union)Self)typing_get_args)_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   Z_deferred_column_loaderZ_raise_column_loaderZ_renders_in_subqueries	raiseloadN)attribute_optionsrM   rN   rS   rL   rP   rQ   infodoc_instrument_assume_readonly_dc_attributescolumn_ORMColumnExprArgument[_T]additional_columns_ORMColumnExprArgument[Any]rT   Optional[_AttributeOptions]rM   rN   rS   "Optional[Type[PropComparator[_T]]]rP   rQ   rU   Optional[_InfoType]rV   rW   rX   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)rT   rX   c                 S  s   g | ]	}t tj|qS  )r%   expectr&   ZLabeledColumnExprRole.0cr`   r`   pC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\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   r[   rG   colri   r`   re   rh      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   rx   name)rp   rs   rt   ru   rw   rx   rz   r|   r~   r   rY   r`   r`   re   declarative_scan   s   



zColumnProperty.declarative_scanOptional[MapperProperty[_T]]c                 C  s   | S Nr`   rp   r`   r`   re   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(   tablerb   r`   r`   re   rf      s    
z4ColumnProperty.columns_to_assign.<locals>.<listcomp>rG   r   r`   r`   re   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)ro   ZstrategyZ_have_default_expressionparentZ_readonly_propsr   r`   r`   re   %_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$   	preloadedZ	orm_stateZorm_strategiesr;   Z"_instance_level_callable_processorr   Zclass_managerZLoadDeferredColumnsrx   rp   state
strategiesr`   r`   re   &_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`   re   #_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   r`   r`   re   __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`   re   r     s   
zColumnProperty.expressionmapperMapper[Any]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   )rp   r   r`   r`   re   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   )rg   do_initlenrG   setr   Zprimary_key
issupersetr$   warnrx   r   rr   r`   re   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   r`   r`   re   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)Z	no_loader)rO   rx   Zget_implr   Zhas_identityZ_expire_attributes)rp   r   r   r   r   r   r   r   r   valueimplr`   r`   re   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   rU   expressionsz*RODescriptorReference[ColumnProperty[_PT]]propSequence[NamedColumn[Any]]r   rY   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.

            )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)rp   rY   per   rq   Zmapper_local_colr`   r`   re   _orm_annotate_column  s   
z.ColumnProperty.Comparator._orm_annotate_columnNamedColumn[_PT]c                 C  s   d S r   r`   r   r`   r`   re   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   rx   r   r   r`   r`   re   #_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   rU   AttributeErrorr   )rp   Zcer`   r`   re   _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 r`   )r   r   rx   rc   rq   r   r`   re   rf     s    zHColumnProperty.Comparator._memoized_attr_expressions.<locals>.<listcomp>c                   s   g | ]}  |qS r`   )r   r   r   r`   re   rf     s    
)r   r   rG   r   r`   r   re   _memoized_attr_expressions  s   

z4ColumnProperty.Comparator._memoized_attr_expressionsrx   ry   r   c                 C  s   t |  |S )zproxy attribute access down to the mapped column.

            this allows user-defined comparison methods to be accessed.
            )rm   r   )rp   rx   r`   r`   re   _fallback_getattr  s   z+ColumnProperty.Comparator._fallback_getattropr?   otherkwargsColumnElement[Any]c                 O     ||   g|R i |S r   r   rp   r   r   r   r`   r`   re   operate     z!ColumnProperty.Comparator.operatec                 K  "   |   }|||||fi |S r   r   Z_bind_paramrp   r   r   r   rq   r`   r`   re   reverse_operate     z)ColumnProperty.Comparator.reverse_operateN)rY   rE   r   rE   )r   r   )r   r<   )r   r   )rx   ry   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   r`   r`   r`   re   rj   a  s    
 

(



	

rj   c                 C  s.   | j r| jst| S t| j jjd | j S )N.)r   rx   object__repr__ry   r   r   r   r`   r`   re   __str__  s   
zColumnProperty.__str__)rY   rZ   r[   r\   rT   r]   rM   rJ   rN   rH   rS   rH   rL   r^   rP   rH   rQ   rH   rU   r_   rV   rJ   rW   rH   rX   rH   rs   r7   rt   r5   ru   rv   rw   rJ   rx   ry   rz   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   ry   )!r   r   r   r   r   Z_COLUMN_TOKENZstrategy_wildcard_keyinherit_cacheZ_links_to_entityr   r   rh   r   propertyr   r   r   r$   preload_moduler   r   r   r   r   r   r   r   ZMemoizedSlotsr   rD   rj   r   __classcell__r`   r`   rr   re   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   r`   r`   r`   re   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< dHddZdIddZedJddZ	edKddZ
edLddZdMd d!ZdNd'd(ZdNd)d*ZdOd+d,ZdPd<d=Zed>dQdBdCZdRdEdFZdGS )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_columnrH   rN   r   rJ   r   
Column[_T]rY   zOptional[Set[ForeignKey]]r   r   r   argr   kwc                 O  sZ  | dt | _}| dd| _d| _|d ur4|tkr4|jtjur%d| _n|jtjus1|j	tjur4d| _| dtj}|tju| _
| j
rI||d< n|jtjurT|j|d< | dd | _| dd | _| d	tj| _| jtju ryt| jpv| j| _| d
d| _| dd| _tdt|i || _| jj| _d|v o|dd tjfv| _t|  d S )NrT   Zuse_existing_columnFTinsert_defaultdefaultr   r   rN   rP   Z
sort_orderr   r   nullable)popr   r   r   r   Zdataclasses_default_factoryr'   ZNO_ARGZdataclasses_initZdataclasses_reprr   Zdataclasses_defaultr   r   rN   rH   rP   r   r   r(   rY   r   getr)   ZNULL_UNSPECIFIEDr   r$   rn   )rp   r   r   Z	attr_optsr   r`   r`   re   rh   )  sB   




zMappedColumn.__init__r   r0   c                 K  s   | j | j }| jjdi ||_| j|_| j|_| j|_|jj|_| j|_| j	|_	| j
|_
| j|_| j|_| j|_| j|_t| |S )Nr`   )ri   __new__rY   _copyrN   r   r   r   rP   r   r   r   r   r   r   r$   rn   )rp   r   newr`   r`   re   r   U  s   

zMappedColumn._copyry   c                 C  s   | j jS r   )rY   r   r   r`   r`   re   r   f  s   zMappedColumn.namer   c                 C  s0   | j s| jrt| j| j | j| j| j| jdS d S )N)rN   rM   rS   rT   rP   )rN   rP   rF   rY   r   r   r   r   r`   r`   re   r   j  s   	z&MappedColumn.mapper_property_to_assignr   c                 C  s   | j | jfgS r   )rY   r   r   r`   r`   re   r   x  s   zMappedColumn.columns_to_assignc                 C  r   r   )rY   r   r`   r`   re   r   |  s   zMappedColumn.__clause_element__r   r?   r   r   r   c                 O  r   r   r   r   r`   r`   re   r     r   zMappedColumn.operatec                 K  r   r   r   r   r`   r`   re   r     r   zMappedColumn.reverse_operatec                 C  s   t  S r   )r   r   r`   r`   re   found_in_pep593_annotated  s   z&MappedColumn.found_in_pep593_annotatedrs   r7   rt   r5   ru   rv   rw   rx   rz   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)rY   r   ZinheritssingleZis_deferredsa_excArgumentErrorr   r   Zlocal_tablerd   r   rx   type_isnullr   Z_raise_for_required_init_column_for_annotation)rp   rs   rt   ru   rw   rx   rz   r|   r~   r   rY   Zsupercls_mapperZcolnamesqltyper`   r`   re   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   Zorm_decl_baseZ_undefer_column_namerY   r  )rp   rt   ru   rw   rx   r  r  	decl_baser`   r`   re   declarative_scan_for_composite  s
   
z+MappedColumn.declarative_scan_for_compositeargumentc                 C  s  | j j}t|tst|ddr|d usJ t|||dd}t|r-|d us'J t|||}t|}| j	s8|| j _
t|}d }t|rpd}	t|}
|
d }t|r]t|}d}| j	s]|| j _
|
dd  D ]}t|trn|} nqcnd}	d }|d ur| js|j jd urd | j _|j | j  | j j}|jr| j jsd }|	r||g}n|g}|D ]}||}|d ur n,qt|tst|trt|trtd| j jd| d	td
| d| j jd| j | d S d S d S )NT)Zcheck_generic)Zinclude_genericr   r   Fz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   ry   r,   r   r/   r   r-   r   r   r+   r.   r1   r   r   r   _merger  r   Z_resolve_typer*   
issubclassr   r   rx   Z	_set_type)rp   ru   rt   r  rw   r  r   Zour_typeZuse_args_fromZour_type_is_pep593Zpep_593_componentsZraw_pep_593_typeelemZnew_sqltypeZchecksZ
check_typer`   r`   re   r    s   



z(MappedColumn._init_column_for_annotationN)r   r   r   r   )r   r   r   r0   r   r   r   )r   r   r   )r   r   r   )rt   r5   ru   rv   rw   rJ   rx   ry   r  ry   r  r@   r   r   )
ru   rv   rt   r5   r  r@   rw   rJ   r   r   )r   r   r   r   r   r   rh   r   r   r   r   r   r   r   r   r   r   r$   r   r  r  r`   r`   r`   re   r     s2   
 

,




2r   N)]r   
__future__r   typingr   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"   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`   re   <module>   s   	
   
