o
    2g                     @  sp  d Z ddlmZ ddlmZmZ ddlmZ er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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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d,S )-z3Provide exception classes for the prawcore package.    )annotations)TYPE_CHECKINGAny)urlparse)Responsec                   @     e Zd ZdZdS )PrawcoreExceptionzCBase exception class for exceptions that occur within this package.N__name__
__module____qualname____doc__ r   r   K/home/garg/my-data/venv/lib/python3.10/site-packages/prawcore/exceptions.pyr          r   c                   @  r   )InvalidInvocationz6Indicate that the code to execute cannot be completed.Nr	   r   r   r   r   r      r   r   c                   @  s   e Zd ZdZ	ddddZdS )OAuthExceptionzAIndicate that there was an OAuth2 related error with the request.Nresponser   errorstrdescription
str | NonereturnNonec                 C  s@   || _ || _|| _| d}|r|d| d7 }t| | dS )zInitialize a OAuthException instance.

        :param response: A ``requests.response`` instance.
        :param error: The error type returned by Reddit.
        :param description: A description of the error when provided.

        z error processing requestz ()N)r   r   r   r   __init__)selfr   r   r   messager   r   r   r      s   

zOAuthException.__init__)N)r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r      s    r   c                      s"   e Zd ZdZd fd
dZ  ZS )RequestExceptionzBIndicate that there was an error with the incomplete HTTP request.original_exception	Exceptionrequest_argstuple[Any, ...]request_kwargsBdict[str, bool | (dict[str, int] | (dict[str, str] | str)) | None]r   r   c                   s(   || _ || _|| _t d|  dS )a  Initialize a RequestException instance.

        :param original_exception: The original exception that occurred.
        :param request_args: The arguments to the request function.
        :param request_kwargs: The keyword arguments to the request function.

        zerror with request N)r    r"   r$   superr   )r   r    r"   r$   	__class__r   r   r   ,   s   zRequestException.__init__)r    r!   r"   r#   r$   r%   r   r   r
   r   r   r   r   __classcell__r   r   r'   r   r   )       r   c                      s"   e Zd ZdZd fddZ  ZS )	ResponseExceptionzAIndicate that there was an error with the completed HTTP request.r   r   r   r   c                   s    || _ t d|j d dS )znInitialize a ResponseException instance.

        :param response: A ``requests.response`` instance.

        	received  HTTP responseN)r   r&   r   status_code)r   r   r'   r   r   r   D   s   zResponseException.__init__r   r   r   r   r)   r   r   r'   r   r,   A   r+   r,   c                   @  r   )BadJSONz1Indicate the response did not contain valid JSON.Nr	   r   r   r   r   r1   N   r   r1   c                   @  r   )
BadRequestz,Indicate invalid parameters for the request.Nr	   r   r   r   r   r2   R   r   r2   c                   @  r   )Conflictz5Indicate a conflicting change in the target resource.Nr	   r   r   r   r   r3   V   r   r3   c                   @  r   )	Forbiddenz=Indicate the authentication is not permitted for the request.Nr	   r   r   r   r   r4   Z   r   r4   c                   @  r   )InsufficientScopez5Indicate that the request requires a different scope.Nr	   r   r   r   r   r5   ^   r   r5   c                   @  r   )InvalidTokenz7Indicate that the request used an invalid access token.Nr	   r   r   r   r   r6   b   r   r6   c                   @  r   )NotFoundz.Indicate that the requested URL was not found.Nr	   r   r   r   r   r7   f   r   r7   c                   @     e Zd ZdZd	ddZdS )
RedirectzIndicate the request resulted in a redirect.

    This class adds the attribute ``path``, which is the path to which the response
    redirects.

    r   r   r   r   c                 C  sd   t |jd j}|dr|dd n|| _|| _d| j }|d| jv r'dnd7 }t| | dS )	zInitialize a Redirect exception instance.

        :param response: A ``requests.response`` instance containing a location header.

        locationz.jsonNzRedirect to z/login/zP (You may be trying to perform a non-read-only action via a read-only instance.) )r   headerspathendswithr   r   r   )r   r   r>   msgr   r   r   r   r   s   
zRedirect.__init__Nr0   r   r   r   r   r   r9   j   s    r9   c                   @  r   )ServerErrorzAIndicate issues on the server end preventing request fulfillment.Nr	   r   r   r   r   rA      r   rA   c                   @  r8   )
SpecialErrorz*Indicate syntax or spam-prevention issues.r   r   r   r   c                 C  sR   || _ | j  }|dd| _|dd| _|dg | _t| d| j dS )zInitialize a SpecialError exception instance.

        :param response: A ``requests.response`` instance containing a message and a
            list of special errors.

        r   r<   reasonspecial_errorszSpecial error N)r   jsongetr   rC   rD   r   r   )r   r   	resp_dictr   r   r   r      s   
zSpecialError.__init__Nr0   r   r   r   r   r   rB          rB   c                   @  r   )TooLargez9Indicate that the request data exceeds the allowed limit.Nr	   r   r   r   r   rI      r   rI   c                   @  r8   )
TooManyRequestszLIndicate that the user has sent too many requests in a given amount of time.r   r   r   r   c                 C  sV   || _ |jd| _|j| _d|j d}| jr#|dt| j d7 }t	| | dS )zInitialize a TooManyRequests exception instance.

        :param response: A ``requests.response`` instance that may contain a retry-after
            header and a message.

        zretry-afterr-   r.   z. Please wait at least z' seconds before re-trying this request.N)
r   r=   rF   retry_aftertextr   r/   floatr   r   )r   r   r@   r   r   r   r      s   zTooManyRequests.__init__Nr0   r   r   r   r   r   rJ      rH   rJ   c                   @  r   )
URITooLongzFIndicate that the length of the request URI exceeds the allowed limit.Nr	   r   r   r   r   rN      r   rN   c                   @  r   )UnavailableForLegalReasonszDIndicate that the requested URL is unavailable due to legal reasons.Nr	   r   r   r   r   rO      r   rO   N)r   
__future__r   typingr   r   urllib.parser   requests.modelsr   r!   r   r   r   r   r,   r1   r2   r3   r4   r5   r6   r7   r9   rA   rB   rI   rJ   rN   rO   r   r   r   r   <module>   s2    