o
    NK&hh                     @   s  d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZ G dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZeZeZG dd deZeZG dd deZeZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZ G d#d$ d$eZ!G d%d& d&eZ"e"Z#G d'd( d(eZ$e$Z%G d)d* d*eZ&G d+d, d,e"Z'G d-d. d.eZ(G d/d0 d0eZ)G d1d2 d2eZ*G d3d4 d4eZ+G d5d6 d6eZ,d7S )8    )CancelledError)Sequence)PathLike)AnyOptionalUnion)STATUS_CODES)Rangec                   @      e Zd ZdZdS )RequestCancelledTN)__name__
__module____qualname__quiet r   r   C/var/www/html/venv/lib/python3.10/site-packages/sanic/exceptions.pyr   
       r   c                   @      e Zd ZdZdZdS )ServerKilledz]Exception Sanic server uses when killing a server process for something unexpected happening.TN)r   r   r   __doc__r   r   r   r   r   r      s    r   c                       s   e Zd ZU dZdZeed< dZee	 ed< i Z
eeef ed< dZeed< 				dd	d	d	d	d
deeeef  dee dee	 deeeef  deeeef  deeeef  dd	f fddZ  ZS )SanicExceptionap  Generic exception that will generate an HTTP response when raised in the context of a request lifecycle.

    Usually, it is best practice to use one of the more specific exceptions
    than this generic one. Even when trying to raise a 500, it is generally
    preferable to use `ServerError`.

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`,
            then the appropriate HTTP response status message will be used instead. Defaults to `None`.
        status_code (Optional[int], optional): The HTTP response code to send, if applicable. If `None`,
            then it will be 500. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed from the logs.
            Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.

    Examples:
        ```python
        raise SanicException(
            "Something went wrong",
            status_code=999,
            context={
                "info": "Some additional details to send to the client",
            },
            headers={
                "X-Foo": "bar"
            }
        )
        ```
      status_codeFr   headers messageNr   contextextrar   r   r   returnc                   s   || _ || _|pt| jdd }|d ur|nt| jdd }|p$t| jdi }|d u r;| j}|s:|r:t|d}| }n	t|t	rD| }t
 | |pN| j| _|| _|| _z|| _W d S  tyf   Y d S w )Nr   r   r       )r   r   getattr	__class__r   r   getdecode
isinstancebytessuper__init__r   r   r   AttributeError)selfr   r   r   r   r   r   msgr"   r   r   r(   =   s6   

zSanicException.__init__NN)r   r   r   r   r   int__annotations__r   r   boolr   dictstrr   r   r&   r   r(   __classcell__r   r   r,   r   r      s8   
 #	r   c                       s~   e Zd ZdZ	dddddddeeeef  dee dee	ee
f  dee	ee
f  dee	ee
f  d	df fd
dZ  ZS )HTTPExceptionzDA base class for other exceptions and should not be called directly.Nr   r   r   r   r   r   r   c                   s   t  j|||||d d S Nr   r'   r(   )r*   r   r   r   r   r   r,   r   r   r(   h   s   	
zHTTPException.__init__N)r   r   r   r   r   r   r2   r&   r0   r1   r   r(   r3   r   r   r,   r   r4   e   s*    r4   c                   @      e Zd ZdZdZdZdS )NotFounda  A base class for other exceptions and should not be called directly.

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`,
            then the appropriate HTTP response status message will be used instead. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed from the logs.
            Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    i  TNr   r   r   r   r   r   r   r   r   r   r9   z       r9   c                   @   r8   )
BadRequest\  400 Bad Request

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    i  TNr:   r   r   r   r   r<      r;   r<   c                       s   e Zd ZdZdZdZ			dddddddeeee	f  ded	ee
e  d
ee deeeef  deeeef  deeeef  f fddZ  ZS )MethodNotAllowedab  405 Method Not Allowed

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Method Not Allowed' will be sent. Defaults to `None`.
        method (Optional[str], optional): The HTTP method that was used. Defaults to an empty string.
        allowed_methods (Optional[Sequence[str]], optional): The HTTP methods that can be used instead of the
            one that was attempted.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    i  TNr   r   r   methodallowed_methodsr   r   r   r   c                   sD   t  j|||||d |ri | jdd|i| _|| _|| _d S )Nr   Allow, )r'   r(   r   joinr?   r@   )r*   r   r?   r@   r   r   r   r   r,   r   r   r(      s   

zMethodNotAllowed.__init__)Nr   N)r   r   r   r   r   r   r   r   r2   r&   r   r0   r1   r   r(   r3   r   r   r,   r   r>      s6    
	r>   c                   @   r   )ServerErrora  500 Internal Server Error

    A general server-side error has occurred. If no other HTTP exception is
    appropriate, then this should be used

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    r   Nr   r   r   r   r   r   r   r   r   rD      s    rD   c                   @   r8   )ServiceUnavailablea  503 Service Unavailable

    The server is currently unavailable (because it is overloaded or
    down for maintenance). Generally, this is a temporary state.

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    i  TNr:   r   r   r   r   rF          rF   c                   @   r   )URLBuildErrora  500 Internal Server Error

    An exception used by Sanic internals when unable to build a URL.

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    r   NrE   r   r   r   r   rH   
  s    rH   c                       s   e Zd ZdZ			dddddddeeeef  dee dee dee	 dee
eef  d	ee
eef  d
ee
eef  f fddZ  ZS )FileNotFounda  404 Not Found

    A specific form of :class:`.NotFound` that is specifically when looking
    for a file on the file system at a known path.

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Not Found' will be sent. Defaults to `None`.
        path (Optional[PathLike], optional): The path, if any, to the file that could not
            be found. Defaults to `None`.
        relative_url (Optional[str], optional): A relative URL of the file. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    Nr   r   pathrelative_urlr   r   r   r   c                   s&   t  j|||||d || _|| _d S r5   )r'   r(   rJ   rK   )r*   r   rJ   rK   r   r   r   r   r,   r   r   r(   5  s   
zFileNotFound.__init__)NNN)r   r   r   r   r   r   r2   r&   r   r0   r1   r   r(   r3   r   r   r,   r   rI     s2    	rI   c                   @   r8   )RequestTimeoutaX  408 Request Timeout

    The Web server (running the Web site) thinks that there has been too
    long an interval of time between 1) the establishment of an IP
    connection (socket) between the client and the server and
    2) the receipt of any data on that socket, so the server has dropped
    the connection. The socket connection has actually been lost - the Web
    server has 'timed out' on that particular socket connection.

    This is an internal exception thrown by Sanic and should not be used
    directly.

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    i  TNr:   r   r   r   r   rL   K  s    rL   c                   @   r8   )PayloadTooLargea  413 Payload Too Large

    This is an internal exception thrown by Sanic and should not be used
    directly.

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    i  TNr:   r   r   r   r   rM   i  rG   rM   c                   @   r
   )HeaderNotFoundr=   Nr   r   r   r   r   r   r   r   rN     r   rN   c                   @   r
   )InvalidHeaderr=   NrO   r   r   r   r   rP     r   rP   c                       s   e Zd ZdZdZdZ		dddddddeeee	f  dee
 dee d	eeeef  d
eeeef  deeeef  f fddZ  ZS )RangeNotSatisfiablea  416 Range Not Satisfiable

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Range Not Satisfiable' will be sent. Defaults to `None`.
        content_range (Optional[ContentRange], optional): An object meeting the :class:`.ContentRange` protocol
            that has a `total` property. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
      TNr   r   content_ranger   r   r   r   c                   sB   t  j|||||d |d uri | jdd|j i| _d S d S )Nr   zContent-Rangezbytes */)r'   r(   r   total)r*   r   rS   r   r   r   r   r,   r   r   r(     s   
zRangeNotSatisfiable.__init__r-   )r   r   r   r   r   r   r   r   r2   r&   r	   r0   r1   r   r(   r3   r   r   r,   r   rQ     s0    rQ   c                   @   r8   )ExpectationFailedac  417 Expectation Failed

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    i  TNr:   r   r   r   r   rU     r;   rU   c                   @   r8   )	ForbiddenaZ  403 Forbidden

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    i  TNr:   r   r   r   r   rV     r;   rV   c                   @   r8   )InvalidRangeTypeaf  416 Range Not Satisfiable

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
    rR   TNr:   r   r   r   r   rW     r;   rW   c                       sn   e Zd Z	d
ddddddee dee deeeef  deeeef  deeeef  f
 fdd	Z	  Z
S )PyFileErrorNr   r   r   r   r   r   c                   s    t  jd| |||||d d S )Nz could not execute config file %s)r   r   r   r   r   r6   )r*   filer   r   r   r   r   r,   r   r   r(     s   

zPyFileError.__init__r7   )r   r   r   r   r.   r0   r1   r2   r   r(   r3   r   r   r,   r   rX     s$    rX   c                       s   e Zd ZdZdZdZ		dddddddeeee	f  dee dee
 d	eeeef  d
eeeef  deeeef  f fddZ  ZS )Unauthorizeda  
    **Status**: 401 Unauthorized

    When present, additional keyword arguments may be used to complete
    the WWW-Authentication header.

    Args:
        message (Optional[Union[str, bytes]], optional): The message to be sent to the client. If `None`
            then the HTTP status 'Bad Request' will be sent. Defaults to `None`.
        scheme (Optional[str], optional): Name of the authentication scheme to be used. Defaults to `None`.
        quiet (Optional[bool], optional): When `True`, the error traceback will be suppressed
            from the logs. Defaults to `None`.
        context (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will be
            sent to the client upon exception. Defaults to `None`.
        extra (Optional[Dict[str, Any]], optional): Additional mapping of key/value data that will NOT be
            sent to the client when in PRODUCTION mode. Defaults to `None`.
        headers (Optional[Dict[str, Any]], optional): Additional headers that should be sent with the HTTP
            response. Defaults to `None`.
        **challenges (Dict[str, Any]): Additional keyword arguments that will be used to complete the
            WWW-Authentication header. Defaults to `None`.

    Examples:
        With a Basic auth-scheme, realm MUST be present:
        ```python
        raise Unauthorized(
            "Auth required.",
            scheme="Basic",
            realm="Restricted Area"
        )
        ```

        With a Digest auth-scheme, things are a bit more complicated:
        ```python
        raise Unauthorized(
            "Auth required.",
            scheme="Digest",
            realm="Restricted Area",
            qop="auth, auth-int",
            algorithm="MD5",
            nonce="abcdef",
            opaque="zyxwvu"
        )
        ```

        With a Bearer auth-scheme, realm is optional so you can write:
        ```python
        raise Unauthorized("Auth required.", scheme="Bearer")
        ```

        or, if you want to specify the realm:
        ```python
        raise Unauthorized(
            "Auth required.",
            scheme="Bearer",
            realm="Restricted Area"
        )
        ```
    i  TNr   r   schemer   r   r   r   c          
         sd   t  j|||||d |d ur0dd | D }d|}	i | jd| d|	  i| _d S d S )Nr   c                 S   s    g | ]\}}|d |dqS )z=""r   ).0kvr   r   r   
<listcomp>z  s     z)Unauthorized.__init__.<locals>.<listcomp>rB   zWWW-Authenticate )r'   r(   itemsrC   r   rstrip)
r*   r   r[   r   r   r   r   
challengesvalues	challenger,   r   r   r(   e  s    	
zUnauthorized.__init__r-   )r   r   r   r   r   r   r   r   r2   r&   r0   r1   r   r(   r3   r   r   r,   r   rZ   &  s0    ;rZ   c                   @   r
   )LoadFileExceptionz.Exception raised when a file cannot be loaded.NrO   r   r   r   r   rg     r   rg   c                   @   r
   )InvalidSignalz0Exception raised when an invalid signal is sent.NrO   r   r   r   r   rh     r   rh   c                   @   r8   )WebsocketClosedz,Exception raised when a websocket is closed.Tz*Client has closed the websocket connectionN)r   r   r   r   r   r   r   r   r   r   ri     s    ri   N)-asyncior   collections.abcr   osr   typingr   r   r   sanic.helpersr   sanic.models.protocol_typesr	   r   	Exceptionr   r   r4   r9   r<   InvalidUsageBadURLr>   MethodNotSupportedrD   InternalServerErrorrF   rH   rI   rL   rM   rN   rP   rQ   ContentRangeErrorrU   HeaderExpectationFailedrV   rW   rX   rZ   rg   rh   ri   r   r   r   r   <module>   sH    Q1,-]