
    AҐi                         d Z  G d de      Z G d de      Z G d de      Z G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z	y)zU
Dirty Arbiters Error Classes

Exception hierarchy for dirty worker pool operations.
c                   @     e Zd ZdZd fd	Zd Zd Zed        Z xZ	S )
DirtyErrorz,Base exception for all dirty arbiter errors.c                 H    || _         |xs i | _        t        |   |       y N)messagedetailssuper__init__)selfr   r   	__class__s      N/var/www/descvideos/venv/lib/python3.12/site-packages/gunicorn/dirty/errors.pyr	   zDirtyError.__init__   s"    }"!    c                 h    | j                   r| j                   d| j                    S | j                  S )Nz: )r   r   r
   s    r   __str__zDirtyError.__str__   s,    <<ll^2dll^44||r   c                 ^    | j                   j                  | j                  | j                  dS )z*Serialize error for protocol transmission.)
error_typer   r   )r   __name__r   r   r   s    r   to_dictzDirtyError.to_dict   s)     ..11||||
 	
r   c           	         t         t        t        t        t        t
        t        t        d}|j                  dd      }|j                  |t               }t        j                  |      }|j                  dd      |_        |j                  d      xs i |_        t        j                  ||j                         |t        k(  r"|j                  j                  d      |_        |S |t        k(  r"|j                  j                  d      |_        |S |t        k(  rB|j                  j                  d	      |_        |j                  j                  d
      |_        |S |t        t
        fv rb|j                  j                  d      |_        |j                  j                  d      |_        |j                  j                  d
      |_        |S |t        k(  r |j                  j                  d      |_        |S )a7  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_dictz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   
__module____qualname____doc__r	   r   r   classmethodr+   __classcell__r   s   @r   r   r      s)    6"


 + +r   r   c                   $     e Zd ZdZd fd	Z xZS )r   z(Raised when a dirty operation times out.c                 D    |rd|ini }t         |   ||       || _        y )Nr   )r   r	   r   )r
   r   r   r   r   s       r   r	   zDirtyTimeoutError.__init__S   s'    *19g&r'*r   )zOperation timed outNr   r,   r-   r.   r	   r0   r1   s   @r   r   r   P   s    2 r   r   c                   $     e Zd ZdZd fd	Z xZS )r   z.Raised when connection to dirty arbiter fails.c                 D    |rd|ini }t         |   ||       || _        y )Nr   )r   r	   r   )r
   r   r   r   r   s       r   r	   zDirtyConnectionError.__init__\   s(    2==+.2'*&r   )zConnection failedNr4   r1   s   @r   r   r   Y   s    8' 'r   r   c                   $     e Zd ZdZd fd	Z xZS )r   z/Raised when a dirty worker encounters an error.c                 b    i }|||d<   |r||d<   t         |   ||       || _        || _        y )Nr   r    )r   r	   r   r    )r
   r   r   r    r   r   s        r   r	   zDirtyWorkerError.__init__e   sB     #,GK #,GK '*""r   )NNr4   r1   s   @r   r   r   b   s    9# #r   r   c                   $     e Zd ZdZd fd	Z xZS )r   z=Raised when a dirty app encounters an error during execution.c                 ~    i }|r||d<   |r||d<   |r||d<   t         |   ||       || _        || _        || _        y )Nr!   r"   r    )r   r	   r!   r"   r    )r
   r   r!   r"   r    r   r   s         r   r	   zDirtyAppError.__init__s   sS    "*GJ &GH#,GK '* "r   )NNNr4   r1   s   @r   r   r   p   s    G# #r   r   c                   "     e Zd ZdZ fdZ xZS )r   z%Raised when a dirty app is not found.c                 .    t         |   d| |       y )NzDirty app not found: )r!   )r   r	   )r
   r!   r   s     r   r	   zDirtyAppNotFoundError.__init__   s    0
;hOr   r4   r1   s   @r   r   r      s    /P Pr   r   c                   $     e Zd ZdZd fd	Z xZS )r   a  
    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                 H    |d| }t         |   |d|i       || _        y )NzNo workers available for app: r!   )r   )r   r	   r!   )r
   r!   r   r   s      r   r	   z%DirtyNoWorkersAvailableError.__init__   s2    ?6xjAG:x*@A r   r   r4   r1   s   @r   r   r      s    4! !r   r   c                   $     e Zd ZdZd fd	Z xZS )r   z,Raised when there is a protocol-level error.c                     i }|4t        |t              r|d d j                         }t        |      d d |d<   t        |   ||       y )Nd      raw_data)
isinstancebyteshexstrr   r	   )r
   r   rC   r   r   s       r   r	   zDirtyProtocolError.__init__   sP    (E*#DS>--/"%h-"5GJ'*r   )zProtocol errorNr4   r1   s   @r   r   r      s    6+ +r   r   N)
r.   r$   r   r   r   r   r   r   r   r    r   r   <module>rI      sp   
A AH
 ': '#z ##J #"PM P!: !D
+ 
+r   