o
    h9                     @  sr  d dl mZ d dlZd dl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) er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'lm2Z2 d d(l3m4Z4 d d)lm5Z5 d d*l6m7Z7 d d+l6m8Z8 ed,ed- d.Z9G d/d0 d0eZ:dd5d6Z;e<d7d8 e=d9eD Z>e>d:kZ?e>d;kZ@e>d<kZAeZBer;ddAdBZCnd dClDmCZC eEej+eZF	DdddJdKZGeArXd dLlmHZH nd dMlImJZH edeKeHf ZLeeKeHf ZMddQdRZNddTdUZOddWdXZPdYZQejRdd]d^ZSddadbZTddddeZUddfdgZVddhdiZWddmdnZXddpdqZYddvdwZZdxdy Z[dzd{ Z\dd|d}Z]dd~dZ^dddZ_dd Z`dd Zaebejcdrdd Zddd Zendd Zddd ZedddZfdddZgdddZhdd ZidddZjdddZkdddZlG dd dej5ZmeCemdddZnG dd de ZoeCeodddZpdddZqdddZrdddZsdddZtdS )    )annotationsN)Any)Callable)Dict)Iterable)Iterator)Optional)Protocol)Set)Type)TYPE_CHECKING)TypeVar)Union)__version__schema)sql)types)CheckConstraint)Column)ForeignKeyConstraint)visitors)DialectKWArgs)BindParameter)ColumnClause)
TextClause)UnaryExpression)traverse)	TypeGuardT)
_NONE_NAME)ClauseElement)Identity)Index)Table)
Connection)Dialect)Transaction)ColumnCollection)SQLCompiler)ColumnElement)
Constraint)
SchemaItem_CE)zColumnElement[Any]r+   )boundc                   @  s   e Zd Zd
ddZd	S )_CompilerProtocolelementr   compilerkwreturnstrc                 K     d S N )selfr/   r0   r1   r6   r6   l/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/alembic/util/sqla_compat.py__call__:   s    z_CompilerProtocol.__call__N)r/   r   r0   r   r1   r   r2   r3   )__name__
__module____qualname__r9   r6   r6   r6   r8   r.   9   s    r.   valuer3   r2   Union[int, str]c                 C  s   zt | W S    |  Y S r5   )int)r=   r6   r6   r8   	_safe_int=   s   
r@   c                 C  s   g | ]}t |qS r6   )r@   ).0xr6   r6   r8   
<listcomp>E       rC   z(\d+|[abc]\d))         )rE   rF      )   r/   Type[ClauseElement]dialects0Callable[[_CompilerProtocol], _CompilerProtocol]c                 G  r4   r5   r6   )r/   rK   r6   r6   r8   compilesO   s   rM   )rM   Fidentity&Union[Identity, schema.Sequence, None]dialect_kwargsboolDict[str, Any]c                   s    d u ri S t r$t dsJ   }|r"t tsJ | j |S i }t tjr; j	|d<  j
d ur; j
|d< d}| fdd|D  |S )N_as_dictalwayson_null)	start	incrementminvaluemaxvalue
nominvalue
nomaxvaluecyclecacheorderc                   s*   i | ]}t  |d d ur|t  |d qS r5   )getattrrA   keyrN   r6   r8   
<dictcomp>z   s
    z._get_identity_options_dict.<locals>.<dictcomp>)identity_has_dialect_kwargshasattrrS   
isinstancer   updaterP   r   r!   rT   rU   )rN   rP   as_dictattrsr6   rb   r8   _get_identity_options_dictZ   s*   



rj   )	_NoneName)symbolname_ConstraintName!TypeGuard[_ConstraintNameDefined]c                 C  s   | t u p
t| ttfS r5   )r   rf   r3   rk   rm   r6   r6   r8   constraint_name_defined   s   rq   TypeGuard[str]c                 C  s
   t | tS r5   )rf   r3   rp   r6   r6   r8   constraint_name_string      
rs   Optional[str]c                 C  s   t | r| S d S r5   )rs   rp   r6   r6   r8   constraint_name_or_none   s   rv   auto
connectionOptional[Connection]Iterator[None]c                 c  s    z| j }W n ty   d }Y nw |d u rd V  d S | s>| d us$J |   d V  W d    d S 1 s7w   Y  d S d V  d S r5   )in_transactionAttributeErrorbeginrx   r{   r6   r6   r8   _ensure_scope_for_ddl   s   


"
r   r$   r&   c                 C  s   |   }|r|S |  S r5   )get_transactionr}   rx   transactionr6   r6   r8   "_safe_begin_connection_transaction   s   r   Nonec                 C     |   }|r|  d S d S r5   )r   commitr   r6   r6   r8   #_safe_commit_connection_transaction      r   c                 C  r   r5   )r   rollbackr   r6   r6   r8   %_safe_rollback_connection_transaction   r   r   c                 C  s$   z| j }W | S  ty   Y dS w )NF)r{   r|   r~   r6   r6   r8   _get_connection_in_transaction   s   r   idxr"   Iterable[ColumnElement[Any]]c                 C     | j S r5   )expressions)r   r6   r6   r8   _idx_table_bound_expressions   s   r   schema_itemc                 K  s*   t | dr| jdi |S | jdi |S )N_copyr6   )re   r   copy)r   r1   r6   r6   r8   r      s   
r   connectable	tablename
schemanameUnion[str, None]c                 C  s   | j | ||S r5   )dialect	has_table)r   r   r   r6   r6   r8   _connectable_has_table   s   r   c                 K  s8   |   }|||W  d    S 1 sw   Y  d S r5   )_operation_contextexecute)	inspector	statementparamsconnr6   r6   r8   _exec_on_inspector   s   

$r   c                 C  s   ddl m} | j|ju S )Nr   r   )sqlalchemy.sqlr   _user_defined_nullableNULL_UNSPECIFIED)metadata_columnr   r6   r6   r8   _nullability_might_be_unset   s   r   c                  G     t dd | D S )Nc                 s      | ]	}t |tjV  qd S r5   )rf   r   ComputedrA   sdr6   r6   r8   	<genexpr>       z._server_default_is_computed.<locals>.<genexpr>anyserver_defaultr6   r6   r8   _server_default_is_computed      r   c                  G  r   )Nc                 s  r   r5   )rf   r   r!   r   r6   r6   r8   r      r   z._server_default_is_identity.<locals>.<genexpr>r   r   r6   r6   r8   _server_default_is_identity   r   r   
constraintr*   r#   c                 C  s&   t | tr| j}|d usJ |S | jS r5   )rf   r   parenttable)r   r   r6   r6   r8   _table_for_constraint   s
   
r   c                 C  s8   t | trdd | jD S t | trt| jS t| jS )Nc                 S  s   g | ]}|j qS r6   )r   )rA   fkr6   r6   r8   rC     s    z+_columns_for_constraint.<locals>.<listcomp>)rf   r   elementsr   _find_columnssqltextlistcolumnsr   r6   r6   r8   _columns_for_constraint  s
   



r   c                 C  s&   t | rt| \}}||j|S | S r5   )_type_has_variants_get_variant_mappinggetrm   )type_r   	base_typemappingr6   r6   r8   _resolve_for_variant  s   r   _variant_mappingc                 C  s
   t | jS r5   )rQ   r   r   r6   r6   r8   r     rt   r   c                 C  s
   | | j fS r5   )r   r   r6   r6   r8   r     rt   r   c                 C  s   t | tju S r5   )typesqltypesVariantr   r6   r6   r8   r   !  s   c                 C  s   | j | jfS r5   )implr   r   r6   r6   r8   r   $  s   r   r   c              
     s   t r jd us	J  jd usJ t jtsJ  fdd jD } jj} jj} jd j	j
j} jd j	j
j}dd  jD } j} j} j}	 j}
|||||||||	|
f
S )Nc                   s   g | ]} j | jqS r6   )r   rm   r`   r   r6   r8   rC   .  s    z_fk_spec.<locals>.<listcomp>r   c                 S  s   g | ]}|j jqS r6   )columnrm   )rA   r/   r6   r6   r8   rC   6  rD   )r   r   r   rf   r   r#   column_keysrm   r   r   r   ondeleteonupdate
deferrable	initially)r   source_columnssource_tablesource_schematarget_schematarget_tabletarget_columnsr   r   r   r   r6   r   r8   _fk_spec(  s6   
r   c                 C  sF   | j d  }|d}|d d|}| jd usJ || jjkS )Nr   .)r   _get_colspecsplitpopjoinr   ra   )r   spectokenstablekeyr6   r6   r8   _fk_is_self_referentialI  s   


r   c                 C  r   r5   )_type_boundr   r6   r6   r8   _is_type_boundR  s   r   c                 C  s   t  }t| i d|ji |S )z2locate Column objects within the given expression.r   )setr   add)clausecolsr6   r6   r8   r   Y  s   r   
collectionr'   r   %Union[Column[Any], ColumnClause[Any]]c                 C  sJ   |j dusJ | |j  }t| dst| dr| j| dS | | dS )z(remove a column from a ColumnCollection.N
_immutable	_readonly)ra   re   _parentremove)r   r   	to_remover6   r6   r8   _remove_column_from_collectiona  s
   
r   r   text_*Union[str, TextClause, ColumnElement[Any]]&Union[ColumnElement[Any], Column[Any]]c                 C  sl   t |trt|tj}| | |S t |trt| |S t |tr't| |j	S t |t
jr2t|| S td)zAa workaround for the Index construct's severe lack of flexibilityz#String or text() construct expected)rf   r3   r   r   NULLTYPEappend_columnr   _textual_index_element_textual_index_columntextr   r)   _copy_expression
ValueError)r   r   cr6   r6   r8   r   s  s   





r   
expressionr   c                   s    fdd}t | i |S )Nc                   sP   t | tr&| jd ur&| j ur&| j jv r j| j S t| } | |S d S r5   )rf   r   r   rm   r   r   r   )colr   r   r6   r8   replace  s   


z!_copy_expression.<locals>.replace)r   replacement_traverse)r   r   r  r6   r   r8   r     s   r   c                   @  s&   e Zd ZdZdZdd	d
Zdd ZdS )r   aQ  Wrap around a sqlalchemy text() construct in such a way that
    we appear like a column-oriented SQL expression to an Index
    construct.

    The issue here is that currently the Postgresql dialect, the biggest
    recipient of functional indexes, keys all the index expressions to
    the corresponding column expressions when rendering CREATE INDEX,
    so the Index we create here needs to have a .columns collection that
    is the same length as the .expressions collection.  Ultimately
    SQLAlchemy should support text() expressions in indexes.

    See SQLAlchemy issue 3174.

    _textual_idx_elementr   r#   r   r   r2   r   c                 C  s8   || _ || _|j| _t| jjtj| _|| j d S r5   )	r   r   ra   r   r   r   r   fake_columnr   )r7   r   r   r6   r6   r8   __init__  s
   z_textual_index_element.__init__c                 K  s   | j gS r5   )r  )r7   r1   r6   r6   r8   get_children  s   z#_textual_index_element.get_childrenN)r   r#   r   r   r2   r   )r:   r;   r<   __doc____visit_name__r  r  r6   r6   r6   r8   r     s
    
r   r0   r(   c                 K  s   |j | jfi |S r5   )processr   r/   r0   r1   r6   r6   r8   _render_textual_index_column  s   r  c                   @  s   e Zd ZdS )_literal_bindparamN)r:   r;   r<   r6   r6   r6   r8   r    s    r  c                 K  s   |j | fi |S r5   )render_literal_bindparamr
  r6   r6   r8   _render_literal_bindparam  s   r  Union[Index, Constraint]r   Optional[Dialect]c                 C  s*   | j d u rd S |d usJ |jj| ddS NF)_alembic_quoterm   identifier_preparerformat_constraint)r   r   r6   r6   r8   _get_constraint_final_name  s   
r  Union[Constraint, Index]c                 C  s2   | j d u rdS |d usJ |jj| dd}|d uS r  r  )r   r   rm   r6   r6   r8   _constraint_is_named  s   
r  indexc                 C  s   | j D ]	}t|r dS qdS NTF)r   is_expression)r  exprr6   r6   r8   is_expression_index  s
   
r  r  c                 C  s2   t | tr| j} t | tst | tr| jrdS dS r  )rf   r   r/   r   
is_literal)r  r6   r6   r8   r    s   

r  )r=   r3   r2   r>   )r/   rJ   rK   r3   r2   rL   )F)rN   rO   rP   rQ   r2   rR   )rm   rn   r2   ro   )rm   rn   r2   rr   )rm   rn   r2   ru   )rx   ry   r2   rz   )rx   r$   r2   r&   )rx   r$   r2   r   )rx   ry   r2   rQ   )r   r"   r2   r   )r   r,   r2   r,   )r   r$   r   r3   r   r   r2   rQ   )r2   rQ   )r   r*   r2   r#   )r   r   r2   r   )r   r   r2   rQ   )r   r*   r2   rQ   )r   r'   r   r   r2   r   )r   r#   r   r   r2   r   )r   r,   r   r#   r2   r,   )r/   r   r0   r(   r2   r3   )r/   r  r0   r(   r2   r3   )r   r  r   r  r2   ru   )r   r  r   r  r2   rQ   )r  r"   r2   rQ   )r  r   r2   rQ   )u
__future__r   
contextlibretypingr   r   r   r   r   r   r	   r
   r   r   r   r   
sqlalchemyr   r   r   r   r   sqlalchemy.schemar   r   r   r   r   sqlalchemy.sql.baser   sqlalchemy.sql.elementsr   r   r   r   sqlalchemy.sql.visitorsr   typing_extensionsr   sqlalchemy.sql.namingr   r    r!   r"   r#   sqlalchemy.enginer$   r%   r&   r'   sqlalchemy.sql.compilerr(   r)   sqlalchemy.sql.schemar*   r+   r,   r.   r@   tuplefindall_vers
sqla_14_18
sqla_14_26sqla_2sqlalchemy_versionrM   sqlalchemy.ext.compiler
issubclassrd   rj   rk   sqlalchemy.utilrl   r3   rn   _ConstraintNameDefinedrq   rs   rv   AUTOINCREMENT_DEFAULTcontextmanagerr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   re   
TypeEnginer   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r6   r6   r6   r8   <module>   s   
)














		


!
	





