U
    	ڲgT                     @   s  d Z ddlmZ dZddl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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 )"z_Errors for the library.

All exceptions defined by the library
should be defined in this file.
    )absolute_importz$jcgregorio@google.com (Joe Gregorio)N)_helpersc                   @   s   e Zd ZdZdS )ErrorzBase error for this module.N__name__
__module____qualname____doc__ r
   r
   :/tmp/pip-unpacked-wheel-rfrvjkbl/googleapiclient/errors.pyr      s   r   c                   @   sD   e Zd ZdZeddddZedd Zdd	 Z	d
d Z
e
ZdS )	HttpErrorz$HTTP data was invalid or unexpected.   Nc                 C   s8   || _ t|tstd|| _|| _d| _|  | _d S )NzHTTP content should be bytes )	resp
isinstancebytes	TypeErrorcontenturierror_details_get_reasonreason)selfr   r   r   r
   r
   r   __init__&   s    
zHttpError.__init__c                 C   s   | j jS )z6Return the HTTP status code from the response content.)r   statusr   r
   r
   r   status_code0   s    zHttpError.status_codec              
      s  | j j}zzt| jd W n" tjk
rB   | jd Y nX t tr d d }t	 fdddD d}|r҈ d | | _
nLt trt dkr̈ d }|d d }d	|d kr|d d	 | _
n | _
W n tttfk
r   Y nX |d
krd}| S )z=Calculate the reason for the error from the response content.zutf-8errormessagec                 3   s   | ]}| d  kr|V  qdS )r   Nr
   ).0kwdatar
   r   	<genexpr>A   s   z(HttpError._get_reason.<locals>.<genexpr>)Zdetaildetailserrorsr   r   r   r$   N)r   r   jsonloadsr   decodeJSONDecodeErrorr   dictnextr   listlen
ValueErrorKeyErrorr   strip)r   r   Zerror_detail_keywordZfirst_errorr
   r!   r   r   5   s6    


zHttpError._get_reasonc                 C   sR   | j r d| jj| j| j| j f S | jr<d| jj| j| jf S d| jj| jf S d S )Nz><HttpError %s when requesting %s returned "%s". Details: "%s">z/<HttpError %s when requesting %s returned "%s">z<HttpError %s "%s">)r   r   r   r   r   r   r
   r
   r   __repr__W   s    zHttpError.__repr__)N)r   r   r   r	   util
positionalr   propertyr   r   r1   __str__r
   r
   r
   r   r   #   s   	
"r   c                   @   s   e Zd ZdZdS )InvalidJsonErrorz&The JSON returned could not be parsed.Nr   r
   r
   r
   r   r6   k   s   r6   c                   @   s   e Zd ZdZdS )UnknownFileTypez File type unknown or unexpected.Nr   r
   r
   r
   r   r7   q   s   r7   c                   @   s   e Zd ZdZdS )UnknownLinkTypez Link type unknown or unexpected.Nr   r
   r
   r
   r   r8   w   s   r8   c                   @   s   e Zd ZdZdS )UnknownApiNameOrVersionz)No API with that name and version exists.Nr   r
   r
   r
   r   r9   }   s   r9   c                   @   s   e Zd ZdZdS )UnacceptableMimeTypeErrorz4That is an unacceptable mimetype for this operation.Nr   r
   r
   r
   r   r:      s   r:   c                   @   s   e Zd ZdZdS )MediaUploadSizeErrorz+Media is larger than the method can accept.Nr   r
   r
   r
   r   r;      s   r;   c                   @   s   e Zd ZdZdS )ResumableUploadErrorz'Error occurred during resumable upload.Nr   r
   r
   r
   r   r<      s   r<   c                   @   s   e Zd ZdZdS )InvalidChunkSizeErrorz!The given chunksize is not valid.Nr   r
   r
   r
   r   r=      s   r=   c                   @   s   e Zd ZdZdS )InvalidNotificationErrorz$The channel Notification is invalid.Nr   r
   r
   r
   r   r>      s   r>   c                   @   s0   e Zd ZdZeddddZdd ZeZdS )	
BatchErrorz'Error occurred during batch operations.   Nc                 C   s   || _ || _|| _d S )N)r   r   r   )r   r   r   r   r
   r
   r   r      s    zBatchError.__init__c                 C   s2   t | jdd d krd| j S d| jj| jf S d S )Nr   z<BatchError "%s">z<BatchError %s "%s">)getattrr   r   r   r   r
   r
   r   r1      s    
zBatchError.__repr__)NN)	r   r   r   r	   r2   r3   r   r1   r5   r
   r
   r
   r   r?      s
   r?   c                       s,   e Zd ZdZedd fdd	Z  ZS )UnexpectedMethodErrorz;Exception raised by RequestMockBuilder on unexpected calls.   Nc                    s   t t| d|  dS ))Constructor for an UnexpectedMethodError.zReceived unexpected call %sN)superrB   r   )r   ZmethodId	__class__r
   r   r      s    
zUnexpectedMethodError.__init__)N)r   r   r   r	   r2   r3   r   __classcell__r
   r
   rF   r   rB      s   rB   c                       s    e Zd ZdZ fddZ  ZS )UnexpectedBodyErrorz<Exception raised by RequestMockBuilder on unexpected bodies.c                    s   t t| d||f  dS )rD   zExpected: [%s] - Provided: [%s]N)rE   rI   r   )r   expectedprovidedrF   r
   r   r      s    

zUnexpectedBodyError.__init__)r   r   r   r	   r   rH   r
   r
   rF   r   rI      s   rI   )r	   
__future__r   
__author__r&   Zgoogleapiclientr   r2   	Exceptionr   r   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   rB   rI   r
   r
   r
   r   <module>   s$   H