o
    Šågõ  ã                   @  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 er^d	dlmZ d	dlmZ d	dlmZ e	ded�ZeefZ	 G dd„ dejƒZeZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZ G dd„ dejƒZ!G dd „ d eƒZ"G d!d"„ d"eƒZ#G d#d$„ d$ejƒZ$G d%d&„ d&ejƒZ%G d'd(„ d(ejƒZ&d4d-d.„Z'e
 (d/¡d5d1d2„ƒZ)d3S )6zSQLAlchemy ORM exceptions.é    )Úannotations)ÚAny)ÚOptional)ÚTuple)ÚType)ÚTYPE_CHECKING)ÚTypeVaré   )Ú_mapper_property_as_plain_nameé   )Úexc)Úutil)ÚMultipleResultsFound)ÚNoResultFound)ÚLoaderStrategy)ÚMapperProperty)ÚInstanceStateÚ_T)Úboundc                   @  ó   e Zd ZdZdS )ÚStaleDataErroraa  An operation encountered database state that is unaccounted for.

    Conditions which cause this to happen include:

    * A flush may have attempted to update or delete rows
      and an unexpected number of rows were matched during
      the UPDATE or DELETE statement.   Note that when
      version_id_col is used, rows in UPDATE or DELETE statements
      are also matched against the current known version
      identifier.

    * A mapped object with version_id_col was refreshed,
      and the version number coming back from the database does
      not match that of the object itself.

    * A object is detached from its parent object, however
      the object was previously attached to a different parent
      identity which was garbage collected, and a decision
      cannot be made if the new parent was really the most
      recent "parent".

    N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úN/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/orm/exc.pyr   $   ó    r   c                   @  r   )Ú
FlushErrorz0A invalid condition was detected during flush().Nr   r   r   r   r   r   @   r   r   c                   @  r   )ÚUnmappedErrorz?Base for exceptions that involve expected mappings not present.Nr   r   r   r   r   r    D   r   r    c                   @  r   )ÚObjectDereferencedErrorzPAn operation cannot complete due to an object being garbage
    collected.

    Nr   r   r   r   r   r!   H   r   r!   c                   @  s   e Zd ZdZdZdS )ÚDetachedInstanceErrorzSAn attempt to access unloaded attributes on a
    mapped instance that is detached.Úbhk3N)r   r   r   r   Úcoder   r   r   r   r"   O   s    r"   c                   @  ó0   e Zd ZdZe d¡dddd	„ƒZddd„ZdS )ÚUnmappedInstanceErrorz;An mapping operation was requested for an unknown instance.úsqlalchemy.orm.baseNÚobjÚobjectÚmsgúOptional[str]c                 C  sˆ   t jj}|s<z| t|ƒ¡ tt|ƒƒ}d||f }W n  ty;   dtt|ƒƒ› d�}t|tƒr9|dt|ƒ 7 }Y nw t 	| |¡ d S )Nz“Class %r is mapped, but this instance lacks instrumentation.  This occurs when the instance is created before sqlalchemy.orm.mapper(%s) was called.úClass 'ú' is not mappedz;; was a class (%s) supplied where an instance was required?)
r   Ú	preloadedÚorm_baseÚclass_mapperÚtypeÚ_safe_cls_nameÚUnmappedClassErrorÚ
isinstancer    Ú__init__)Úselfr(   r*   ÚbaseÚnamer   r   r   r5   Y   s(   ýÿ
ÿÿ€ýzUnmappedInstanceError.__init__Úreturnr   c                 C  ó   | j d | jd ffS ©Nr   ©Ú	__class__Úargs©r6   r   r   r   Ú
__reduce__p   ó   z UnmappedInstanceError.__reduce__©N)r(   r)   r*   r+   ©r9   r   ©r   r   r   r   r   Úpreload_moduler5   r@   r   r   r   r   r&   V   s
    r&   c                   @  s&   e Zd ZdZdddd„Zddd„ZdS )r3   z8An mapping operation was requested for an unknown class.NÚclsúType[_T]r*   r+   c                 C  s   |st |ƒ}t | |¡ d S rB   )Ú_default_unmappedr    r5   )r6   rF   r*   r   r   r   r5   w   s   zUnmappedClassError.__init__r9   r   c                 C  r:   r;   r<   r?   r   r   r   r@   |   rA   zUnmappedClassError.__reduce__rB   )rF   rG   r*   r+   rC   )r   r   r   r   r5   r@   r   r   r   r   r3   t   s    r3   c                   @  r%   )ÚObjectDeletedErroraï  A refresh operation failed to retrieve the database
    row corresponding to an object's known primary key identity.

    A refresh operation proceeds when an expired attribute is
    accessed on an object, or when :meth:`_query.Query.get` is
    used to retrieve an object which is, upon retrieval, detected
    as expired.   A SELECT is emitted for the target row
    based on primary key; if no row is returned, this
    exception is raised.

    The true meaning of this exception is simply that
    no row exists for the primary key identifier associated
    with a persistent object.   The row may have been
    deleted, or in some cases the primary key updated
    to a new value, outside of the ORM's management of the target
    object.

    r'   NÚstateúInstanceState[Any]r*   r+   c                 C  s,   t jj}|sd| |¡ }tj | |¡ d S )NzDInstance '%s' has been deleted, or its row is otherwise not present.)r   r.   r/   Ú	state_strÚsa_excÚInvalidRequestErrorr5   )r6   rJ   r*   r7   r   r   r   r5   ”   s   ÿÿzObjectDeletedError.__init__r9   r   c                 C  r:   r;   r<   r?   r   r   r   r@       rA   zObjectDeletedError.__reduce__rB   )rJ   rK   r*   r+   rC   rD   r   r   r   r   rI   €   s
    rI   c                   @  r   )ÚUnmappedColumnErrorz5Mapping operation was requested on an unknown column.Nr   r   r   r   r   rO   ¤   r   rO   c                   @  s   e Zd ZdZddd„ZdS )ÚLoaderStrategyExceptionz2A loader strategy for an attribute does not exist.Úapplied_to_property_typeú	Type[Any]Úrequesting_propertyúMapperProperty[Any]Ú
applies_toú#Optional[Type[MapperProperty[Any]]]Úactual_strategy_typeúOptional[Type[LoaderStrategy]]Ústrategy_keyúTuple[Any, ...]c              	   C  sZ   |d u rt j | d||f ¡ d S |d usJ ‚t j | dt |¡|t|ƒt|ƒf ¡ d S )NzCan't find strategy %s for %szuCan't apply "%s" strategy to property "%s", which is a "%s"; this loader strategy is intended to be used with a "%s".)rM   rN   r5   r   Úclsname_as_plain_namer
   )r6   rQ   rS   rU   rW   rY   r   r   r   r5   «   s$   ÿþüýþz LoaderStrategyException.__init__N)
rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   )r   r   r   r   r5   r   r   r   r   rP   ¨   s    rP   rF   rR   r9   Ústrc                 C  sP   zd  | j| jf¡}W |S  ty'   t| dd ƒ}|d u r$t| ƒ}Y |S Y |S w )NÚ.r   )Újoinr   r   ÚAttributeErrorÚgetattrÚrepr)rF   Úcls_namer   r   r   r2   É   s   ü
þür2   r'   r+   c              	   C  sT   t jj}z| | ¡j}W n ttft y   i }Y nw t| ƒ}|s(d|› d�S d S )Nr,   r-   )	r   r.   r/   Úmanager_of_classÚmappersr3   Ú	TypeErrorÚNO_STATEr2   )rF   r7   rd   r8   r   r   r   rH   Ô   s   þ
ýürH   N)rF   rR   r9   r\   )rF   rR   r9   r+   )*r   Ú
__future__r   Útypingr   r   r   r   r   r   r   r
   Ú r   rM   r   r   Ú
interfacesr   r   rJ   r   r   r_   ÚKeyErrorrf   ÚSQLAlchemyErrorr   ÚConcurrentModificationErrorr   rN   r    r!   r"   r&   r3   rI   rO   rP   r2   rE   rH   r   r   r   r   Ú<module>   sD   $
!