a
    |fk                     @   s  d Z ddlZddlZddlZi 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G d)d* d*eZG d+d, d,eZd3d.d/Zd0d1 ZeeD ]$Zeed2dZedureee< qdS )4zrCustom exceptions for :mod:`gcloud` package.

See: https://cloud.google.com/storage/docs/json_api/v1/status-codes
    Nc                       s:   e Zd ZdZdZd
 fdd	Zdd Zedd	 Z  Z	S )GCloudErrorzwBase error class for gcloud errors (abstract).

    Each subclass represents a single type of HTTP error response.
    N c                    s   t t|   || _|| _d S )N)superr   __init__message_errors)selfr   errors	__class__r   KD:\Projects\storyit_web\backend\venv\Lib\site-packages\gcloud/exceptions.pyr   &   s    zGCloudError.__init__c                 C   s   d| j | jf S )Nz%d %s)coder   r   r   r   r   __str__,   s    zGCloudError.__str__c                 C   s   dd | j D S )z|Detailed error information.

        :rtype: list(dict)
        :returns: a list of mappings describing each error.
        c                 S   s   g | ]}t |qS r   )copydeepcopy).0errorr   r   r   
<listcomp>6       z&GCloudError.errors.<locals>.<listcomp>)r   r   r   r   r   r	   /   s    zGCloudError.errors)r   )
__name__
__module____qualname____doc__r   r   r   propertyr	   __classcell__r   r   r
   r   r      s   r   c                   @   s   e Zd ZdZdS )Redirectionz8Base for 3xx responses

    This class is abstract.
    Nr   r   r   r   r   r   r   r   r   9   s   r   c                   @   s   e Zd ZdZdZdS )MovedPermanentlyz5Exception mapping a '301 Moved Permanently' response.i-  Nr   r   r   r   r   r   r   r   r   r   @   s   r   c                   @   s   e Zd ZdZdZdS )NotModifiedz0Exception mapping a '304 Not Modified' response.i0  Nr   r   r   r   r   r    E   s   r    c                   @   s   e Zd ZdZdZdS )TemporaryRedirectz6Exception mapping a '307 Temporary Redirect' response.i3  Nr   r   r   r   r   r!   J   s   r!   c                   @   s   e Zd ZdZdZdS )ResumeIncompletez5Exception mapping a '308 Resume Incomplete' response.i4  Nr   r   r   r   r   r"   O   s   r"   c                   @   s   e Zd ZdZdS )ClientErrorz7Base for 4xx responses

    This class is abstract
    Nr   r   r   r   r   r#   T   s   r#   c                   @   s   e Zd ZdZdZdS )
BadRequestz/Exception mapping a '400 Bad Request' response.i  Nr   r   r   r   r   r$   [   s   r$   c                   @   s   e Zd ZdZdZdS )Unauthorizedz0Exception mapping a '401 Unauthorized' response.i  Nr   r   r   r   r   r%   `   s   r%   c                   @   s   e Zd ZdZdZdS )	Forbiddenz-Exception mapping a '403 Forbidden' response.i  Nr   r   r   r   r   r&   e   s   r&   c                   @   s   e Zd ZdZdZdS )NotFoundz-Exception mapping a '404 Not Found' response.i  Nr   r   r   r   r   r'   j   s   r'   c                   @   s   e Zd ZdZdZdS )MethodNotAllowedz6Exception mapping a '405 Method Not Allowed' response.i  Nr   r   r   r   r   r(   o   s   r(   c                   @   s   e Zd ZdZdZdS )Conflictz,Exception mapping a '409 Conflict' response.i  Nr   r   r   r   r   r)   t   s   r)   c                   @   s   e Zd ZdZdZdS )LengthRequiredz3Exception mapping a '411 Length Required' response.i  Nr   r   r   r   r   r*   y   s   r*   c                   @   s   e Zd ZdZdZdS )PreconditionFailedz7Exception mapping a '412 Precondition Failed' response.i  Nr   r   r   r   r   r+   ~   s   r+   c                   @   s   e Zd ZdZdZdS )RequestRangeNotSatisfiablezAException mapping a '416 Request Range Not Satisfiable' response.i  Nr   r   r   r   r   r,      s   r,   c                   @   s   e Zd ZdZdZdS )TooManyRequestsz5Exception mapping a '429 Too Many Requests' response.i  Nr   r   r   r   r   r-      s   r-   c                   @   s   e Zd ZdZdS )ServerErrorz#Base for 5xx responses:  (abstract)Nr   r   r   r   r   r.      s   r.   c                   @   s   e Zd ZdZdZdS )InternalServerErrorz9Exception mapping a '500 Internal Server Error' response.i  Nr   r   r   r   r   r/      s   r/   c                   @   s   e Zd ZdZdZdS )MethodNotImplementedz3Exception mapping a '501 Not Implemented' response.i  Nr   r   r   r   r   r0      s   r0   c                   @   s   e Zd ZdZdZdS )ServiceUnavailablez7Exception mapping a '503 Service Unavailable' response.i  Nr   r   r   r   r   r1      s   r1   Tc           	      C   s   t |tjr|d}t |tjrbd}|rLzt|}W n tyJ   Y n0 |du rfdd|ii}n|}|di dd}|di dd}|dur|d|f 7 }zt	| j
 }W n$ ty   t||}| j
|_Y n0 |||}|S )	a  Factory:  create exception based on HTTP response code.

    :type response: :class:`httplib2.Response` or other HTTP response object
    :param response: A response object that defines a status code as the
                     status attribute.

    :type content: string or dictionary
    :param content: The body of the HTTP error response.

    :type error_info: string
    :param error_info: Optional string giving extra information about the
                       failed request.

    :type use_json: bool
    :param use_json: Flag indicating if ``content`` is expected to be JSON.

    :rtype: instance of :class:`GCloudError`, or a concrete subclass.
    :returns: Exception specific to the error response.
    zutf-8Nr   r    r	   r   z (%s))
isinstancesixbinary_typedecodestring_typesjsonloads
ValueErrorget_HTTP_CODE_TO_EXCEPTIONstatusKeyErrorr   r   )	responsecontent
error_infoZuse_jsonpayloadr   r	   klassr   r   r   r   make_exception   s.    


rD   c                 c   s,   |   D ]}|V  t|D ]
}|V  qqdS )zRecursively walk subclass tree.N)__subclasses___walk_subclasses)rC   subZsubsubr   r   r   rF      s    rF   r   )NT) r   r   r8   r4   r<   	Exceptionr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   rD   rF   Z_eklassgetattrr   r   r   r   r   <module>   s>   
4	
