o
    2g6(                     @  s  d Z ddlmZ ddlmZ ddlmZ ddlmZ G dd de	Z
G d	d
 d
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 )$aN  PRAW exception classes.

Includes two main exceptions: :class:`.RedditAPIException` for when something goes wrong
on the server side, and :class:`.ClientException` when something goes wrong on the
client side. Both of these classes extend :class:`.PRAWException`.

All other exceptions are subclassed from :class:`.ClientException`.

    )annotations)Any)warn   )_deprecate_argsc                   @     e Zd ZdZdS )PRAWExceptionz@The base PRAW Exception that all other exception classes extend.N__name__
__module____qualname____doc__ r   r   G/home/garg/my-data/venv/lib/python3.10/site-packages/praw/exceptions.pyr          r   c                      sb   e Zd ZdZedddZd fd	d
ZedddddddddZdddZ	dddZ
  ZS )RedditErrorItemz5Represents a single error returned from Reddit's API.returnstrc                 C  s6   | j }| jr|d| j7 }| jr|d| j7 }|S )z'Get the completed error message string.z: z
 on field 
error_typemessagefield)self	error_strr   r   r   error_message   s   zRedditErrorItem.error_messageotherRedditErrorItem | list[str]boolc                   s6   t |tr| j| j| jf|j|j|jfkS t |S )zCheck for equality.)
isinstancer   r   r   r   super__eq__)r   r   	__class__r   r   r    $   s   
zRedditErrorItem.__eq__r   r   r   N)r   r   
str | Nonec                C  s   || _ || _|| _dS )a  Initialize a :class:`.RedditErrorItem` instance.

        :param error_type: The error type set on Reddit's end.
        :param field: The input field associated with the error, if available.
        :param message: The associated message for the error.

        Nr   )r   r   r   r   r   r   r   __init__.   s   
zRedditErrorItem.__init__c                 C  s&   | j j d| jd| jd| jdS )z?Return an object initialization representation of the instance.z(error_type=z
, message=z, field=))r"   r
   r   r   r   r   r   r   r   __repr__A   s   zRedditErrorItem.__repr__c                 C  s   | j S )z(Get the message returned from str(self).)r   r&   r   r   r   __str__H   s   zRedditErrorItem.__str__r   r   )r   r   r   r   )r   r   r   r#   r   r#   )r
   r   r   r   propertyr   r    r   r$   r'   r(   __classcell__r   r   r!   r   r      s    	


r   c                   @  r   )ClientExceptionzEIndicate exceptions that don't involve interaction with Reddit's API.Nr	   r   r   r   r   r,   M   r   r,   c                          e Zd ZdZ fddZ  ZS )DuplicateReplaceExceptionzKIndicate exceptions that involve the replacement of :class:`.MoreComments`.c                      t  d dS )z:Initialize a :class:`.DuplicateReplaceException` instance.ziA duplicate comment has been detected. Are you attempting to call 'replace_more_comments' more than once?Nr   r$   r&   r!   r   r   r$   T   s   z"DuplicateReplaceException.__init__r
   r   r   r   r$   r+   r   r   r!   r   r.   Q       r.   c                      s"   e Zd ZdZd fddZ  ZS )InvalidFlairTemplateIDz@Indicate exceptions where an invalid flair template ID is given.template_idr   c                   s   t  d| d dS )z8Initialize an :class:`.InvalidFlairTemplateID` instance.zThe flair template ID 'zO' is invalid. If you are trying to create a flair, please use the 'add' method.Nr0   )r   r4   r!   r   r   r$   _   s   
zInvalidFlairTemplateID.__init__)r4   r   r1   r   r   r!   r   r3   \   s    r3   c                      r-   )InvalidImplicitAuthzDIndicate exceptions where an implicit auth type is used incorrectly.c                   r/   )z5Initialize an :class:`.InvalidImplicitAuth` instance.z<Implicit authorization can only be used with installed apps.Nr0   r&   r!   r   r   r$   j   s   zInvalidImplicitAuth.__init__r1   r   r   r!   r   r5   g   r2   r5   c                      s2   e Zd ZdZeddddd	 fddZ  ZS )

InvalidURLz4Indicate exceptions where an invalid URL is entered.urlr   zInvalid URL: {})r   r   c                  s   t  || dS )zInitialize an :class:`.InvalidURL` instance.

        :param url: The invalid URL.
        :param message: The message to display. Must contain a format identifier (``{}``
            or ``{0}``) (default: ``"Invalid URL: {}"``).

        N)r   r$   format)r   r7   r   r!   r   r   r$   r   s   	zInvalidURL.__init__)r7   r   r   r   r
   r   r   r   r   r$   r+   r   r   r!   r   r6   o   s    r6   c                   @  r   )!MissingRequiredAttributeExceptionzAIndicate exceptions caused by not including a required attribute.Nr	   r   r   r   r   r:   ~   r   r:   c                   @  r   )ReadOnlyExceptionzJRaised when a method call requires :attr:`.read_only` mode to be disabled.Nr	   r   r   r   r   r;      r   r;   c                      s,   e Zd ZdZeddd fddZ  ZS )TooLargeMediaExceptionz:Indicate exceptions from uploading media that's too large.maximum_sizeactualintc                  s*   || _ || _t d| d| d dS )zInitialize a :class:`.TooLargeMediaException` instance.

        :param actual: The actual size of the uploaded media.
        :param maximum_size: The maximum size of the uploaded media.

        z;The media that you uploaded was too large (maximum size is z bytes, uploaded z bytes)N)r=   r>   r   r$   )r   r>   r=   r!   r   r   r$      s   zTooLargeMediaException.__init__)r>   r?   r=   r?   r9   r   r   r!   r   r<      s    r<   c                      sN   e Zd ZdZedddZejdddZejdd Zd fddZ  Z	S )WebSocketExceptionz0Indicate exceptions caused by use of WebSockets.r   	Exceptionc                 C  s   t dtdd | jS )z=Access the ``original_exception`` attribute (now deprecated).zAccessing the attribute 'original_exception' is deprecated. Please rewrite your code in such a way that this attribute does not need to be used. It will be removed in PRAW 8.0.   category
stacklevel)r   DeprecationWarning_original_exceptionr&   r   r   r   original_exception   s   z%WebSocketException.original_exceptionvaluec                 C  s
   || _ d S NrG   )r   rI   r   r   r   rH      s   
c                 C  s   | ` d S rJ   rK   r&   r   r   r   rH      s   r   r   	exceptionException | Nonec                   s   t  | || _dS )a  Initialize a :class:`.WebSocketException` instance.

        :param message: The exception message.
        :param exception: The exception thrown by the websocket library.

            .. note::

                This parameter is deprecated. It will be removed in PRAW 8.0.

        N)r   r$   rG   )r   r   rL   r!   r   r   r$      s   
zWebSocketException.__init__)r   rA   )rI   rA   )r   r   rL   rM   )
r
   r   r   r   r*   rH   setterdeleterr$   r+   r   r   r!   r   r@      s    
r@   c                      r-   )MediaPostFailedz0Indicate exceptions where media uploads failed..c                   s   t  dd dS )z0Initialize a :class:`.MediaPostFailed` instance.zThe attempted media upload action has failed. Possible causes include the corruption of media files. Check that the media file can be opened on your local machine.Nr0   r&   r!   r   r   r$      s   zMediaPostFailed.__init__r1   r   r   r!   r   rP      r2   rP   c                      sd   e Zd ZdZedddZedd	d
ZedddZedddZ	d fddZ
dddZ  ZS )APIExceptionzOld class preserved for alias purposes.

    .. deprecated:: 7.0

        Class :class:`.APIException` has been deprecated in favor of
        :class:`.RedditAPIException`. This class will be removed in PRAW 8.0.

    
exceptions!list[RedditErrorItem | list[str]]r   list[RedditErrorItem]c                 C  s   dd | D S )z?Covert an exception list into a :class:`.RedditErrorItem` list.c                 S  sT   g | ]&}t |tr|nt|d  t|d r|d ndt|d r$|d nddqS )r   rB    r   )r   r   r   )r   r   r   ).0rL   r   r   r   
<listcomp>   s    
z5APIException.parse_exception_list.<locals>.<listcomp>r   )rR   r   r   r   parse_exception_list   s   
z!APIException.parse_exception_listr   c                 C  
   |  dS )aW  Get error_type.

        .. deprecated:: 7.0

            Accessing attributes through instances of :class:`.RedditAPIException` is
            deprecated. This behavior will be removed in PRAW 8.0. Check out the
            :ref:`PRAW 7 Migration tutorial <Exception_Handling>` on how to migrate code
            from this behavior.

        r   _get_old_attrr&   r   r   r   r         
zAPIException.error_typec                 C  rY   )aR  Get field.

        .. deprecated:: 7.0

            Accessing attributes through instances of :class:`.RedditAPIException` is
            deprecated. This behavior will be removed in PRAW 8.0. Check out the
            :ref:`PRAW 7 Migration tutorial <Exception_Handling>` on how to migrate code
            from this behavior.

        r   rZ   r&   r   r   r   r      r\   zAPIException.fieldc                 C  rY   )aT  Get message.

        .. deprecated:: 7.0

            Accessing attributes through instances of :class:`.RedditAPIException` is
            deprecated. This behavior will be removed in PRAW 8.0. Check out the
            :ref:`PRAW 7 Migration tutorial <Exception_Handling>` on how to migrate code
            from this behavior.

        r   rZ   r&   r   r   r   r     r\   zAPIException.messageitems-list[RedditErrorItem | list[str] | str] | stroptional_argsc                   sT   t |tr|g|g}nt |trt |d tr|g}| || _t j| j  dS )a@  Initialize a :class:`.RedditAPIException` instance.

        :param items: Either a list of instances of :class:`.RedditErrorItem` or a list
            containing lists of unformed errors.
        :param optional_args: Takes the second and third arguments that
            :class:`.APIException` used to take.

        r   N)r   r   listrX   r]   r   r$   )r   r]   r_   r!   r   r   r$     s   
zAPIException.__init__attrnamer   c                 C  s&   t d| dtdd t| jd |S )NzAccessing attribute 'z' through APIException is deprecated. This behavior will be removed in PRAW 8.0. Check out https://praw.readthedocs.io/en/latest/package_info/praw7_migration.html to learn how to migrate your code.   rC   r   )r   rF   getattrr]   )r   ra   r   r   r   r[   &  s   
zAPIException._get_old_attr)rR   rS   r   rT   r)   )r]   r^   r_   r   )ra   r   r   r   )r
   r   r   r   staticmethodrX   r*   r   r   r   r$   r[   r+   r   r   r!   r   rQ      s    	rQ   c                   @  r   )RedditAPIExceptionz/Container for error messages from Reddit's API.Nr	   r   r   r   r   re   2  r   re   N)r   
__future__r   typingr   warningsr   utilr   rA   r   r   r,   r.   r3   r5   r6   r:   r;   r<   r@   rP   rQ   re   r   r   r   r   <module>   s&    
6&f