
     i                         S r  " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r	g)zU
Dirty Arbiters Error Classes

Exception hierarchy for dirty worker pool operations.
c                   L   ^  \ rS rSrSrSU 4S jjrS rS r\S 5       r	Sr
U =r$ )	
DirtyError   z,Base exception for all dirty arbiter errors.c                 P   > Xl         U=(       d    0 U l        [        TU ]  U5        g N)messagedetailssuper__init__)selfr   r   	__class__s      G/var/www/ias/venv/lib/python3.13/site-packages/gunicorn/dirty/errors.pyr
   DirtyError.__init__   s     }"!    c                 r    U R                   (       a  U R                   SU R                    3$ U R                  $ )Nz: r   r   r   s    r   __str__DirtyError.__str__   s,    <<ll^2dll^44||r   c                 ^    U R                   R                  U R                  U R                  S.$ )z*Serialize error for protocol transmission.)
error_typer   r   )r   __name__r   r   r   s    r   to_dictDirtyError.to_dict   s)     ..11||||
 	
r   c           	          [         [        [        [        [        [
        [        [        S.nUR                  SS5      nUR                  U[         5      n[        R                  U5      nUR                  SS5      Ul        UR                  S5      =(       d    0 Ul        [        R                  XUR                  5        U[        :X  a"  UR                  R                  S5      Ul        U$ U[        :X  a"  UR                  R                  S5      Ul        U$ U[        :X  aB  UR                  R                  S	5      Ul        UR                  R                  S
5      Ul        U$ U[        [
        4;   ab  UR                  R                  S5      Ul        UR                  R                  S5      Ul        UR                  R                  S
5      Ul        U$ U[        :X  a   UR                  R                  S5      Ul        U$ )a  Deserialize error from protocol transmission.

Creates an error instance from a serialized dict. The returned
error will be an instance of the appropriate subclass based on
the error_type field, but constructed using the base DirtyError
__init__ to preserve all details.
)r   DirtyTimeoutErrorDirtyConnectionErrorDirtyWorkerErrorDirtyAppErrorDirtyAppNotFoundErrorDirtyNoWorkersAvailableErrorDirtyProtocolErrorr   r   r   zUnknown errorr   timeoutsocket_path	worker_id	tracebackapp_pathaction)r   r   r   r   r   r   r    r!   get	Exception__new__r   r   r
   r"   r#   r$   r%   r&   r'   )clsdataerror_classesr   error_classerrors         r   	from_dictDirtyError.from_dict!   s    %!2$8 0*%:,H"4	
 XXlL9
#''
J? !!+.O<+1r5--0 ++!MM--i8EM  00 % 1 1- @E  ,,#mm//<EO#mm//<EO  ],ABB"]]..z:EN ==,,X6EL#mm//<EO  88"]]..z:ENr   r   r   )r   
__module____qualname____firstlineno____doc__r
   r   r   classmethodr0   __static_attributes____classcell__r   s   @r   r   r      s)    6"


 + +r   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   P   z(Raised when a dirty operation times out.c                 J   > U(       a  SU0O0 n[         TU ]  X5        X l        g )Nr"   )r	   r
   r"   )r   r   r"   r   r   s       r   r
   DirtyTimeoutError.__init__S   s#    *19g&r*r   )r"   )zOperation timed outNr   r2   r3   r4   r5   r
   r7   r8   r9   s   @r   r   r   P   s    2 r   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   Y   z.Raised when connection to dirty arbiter fails.c                 J   > U(       a  SU0O0 n[         TU ]  X5        X l        g )Nr#   )r	   r
   r#   )r   r   r#   r   r   s       r   r
   DirtyConnectionError.__init__\   s$    2==+.2*&r   )r#   )zConnection failedNr>   r9   s   @r   r   r   Y   s    8' 'r   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   b   z/Raised when a dirty worker encounters an error.c                 d   > 0 nUb  X$S'   U(       a  X4S'   [         TU ]  X5        X l        X0l        g )Nr$   r%   )r	   r
   r$   r%   )r   r   r$   r%   r   r   s        r   r
   DirtyWorkerError.__init__e   s8     #,K #,K *""r   )r%   r$   )NNr>   r9   s   @r   r   r   b   s    9# #r   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   p   z=Raised when a dirty app encounters an error during execution.c                    > 0 nU(       a  X%S'   U(       a  X5S'   U(       a  XES'   [         TU ]  X5        X l        X0l        X@l        g )Nr&   r'   r%   )r	   r
   r&   r'   r%   )r   r   r&   r'   r%   r   r   s         r   r
   DirtyAppError.__init__s   sE    "*J &H#,K * "r   )r'   r&   r%   )NNNr>   r9   s   @r   r   r   p   s    G# #r   r   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r      z%Raised when a dirty app is not found.c                 (   > [         TU ]  SU 3US9  g )NzDirty app not found: r&   )r	   r
   )r   r&   r   s     r   r
   DirtyAppNotFoundError.__init__   s    0
;hOr    r>   r9   s   @r   r   r      s    /P Pr   r   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r       aT  
Raised when no workers are available for the requested app.

This exception is raised when a request targets an app that has
worker limits configured, and no workers with that app are currently
available (e.g., all workers for that app crashed and haven't been
respawned yet).

Web applications can catch this exception to provide graceful
degradation, such as queuing requests for retry or showing a
maintenance page.

Example::

    from gunicorn.dirty import get_dirty_client
    from gunicorn.dirty.errors import DirtyNoWorkersAvailableError

    def my_view(request):
        client = get_dirty_client()
        try:
            result = client.execute("myapp.ml:HeavyModel", "predict", data)
        except DirtyNoWorkersAvailableError as e:
            return {"error": "Service temporarily unavailable",
                    "app": e.app_path}
c                 B   > Uc  SU 3n[         TU ]  USU0S9  Xl        g )NzNo workers available for app: r&   )r   )r	   r
   r&   )r   r&   r   r   s      r   r
   %DirtyNoWorkersAvailableError.__init__   s0    ?6xjAG:x*@A r   rN   r   r>   r9   s   @r   r    r       s    4! !r   r    c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r!      z,Raised when there is a protocol-level error.c                    > 0 nUb9  [        U[        5      (       a  US S R                  5       n[        U5      S S US'   [        TU ]  X5        g )Nd      raw_data)
isinstancebyteshexstrr	   r
   )r   r   rZ   r   r   s       r   r
   DirtyProtocolError.__init__   sQ    (E**#DS>--/"%h-"5GJ*r   rP   )zProtocol errorNr>   r9   s   @r   r!   r!      s    6+ +r   r!   N)
r5   r)   r   r   r   r   r   r   r    r!   rP   r   r   <module>r`      sp   
A AH
 ': '#z ##J #"PM P!: !D
+ 
+r   