B
    |bT                 @   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	   Y/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/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}yy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>B   s   z(HttpError._get_reason.<locals>.<genexpr>)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   s2    


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   r/   __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.N)r   r   r   r   r	   r	   r	   r
   r4   k   s   r4   c               @   s   e Zd ZdZdS )UnknownFileTypez File type unknown or unexpected.N)r   r   r   r   r	   r	   r	   r
   r5   q   s   r5   c               @   s   e Zd ZdZdS )UnknownLinkTypez Link type unknown or unexpected.N)r   r   r   r   r	   r	   r	   r
   r6   w   s   r6   c               @   s   e Zd ZdZdS )UnknownApiNameOrVersionz)No API with that name and version exists.N)r   r   r   r   r	   r	   r	   r
   r7   }   s   r7   c               @   s   e Zd ZdZdS )UnacceptableMimeTypeErrorz4That is an unacceptable mimetype for this operation.N)r   r   r   r   r	   r	   r	   r
   r8      s   r8   c               @   s   e Zd ZdZdS )MediaUploadSizeErrorz+Media is larger than the method can accept.N)r   r   r   r   r	   r	   r	   r
   r9      s   r9   c               @   s   e Zd ZdZdS )ResumableUploadErrorz'Error occurred during resumable upload.N)r   r   r   r   r	   r	   r	   r
   r:      s   r:   c               @   s   e Zd ZdZdS )InvalidChunkSizeErrorz!The given chunksize is not valid.N)r   r   r   r   r	   r	   r	   r
   r;      s   r;   c               @   s   e Zd ZdZdS )InvalidNotificationErrorz$The channel Notification is invalid.N)r   r   r   r   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
   r/      s    
zBatchError.__repr__)NN)	r   r   r   r   r0   r1   r   r/   r3   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 )z)Constructor for an UnexpectedMethodError.zReceived unexpected call %sN)superr@   r   )r   ZmethodId)	__class__r	   r
   r      s    
zUnexpectedMethodError.__init__)N)r   r   r   r   r0   r1   r   __classcell__r	   r	   )rC   r
   r@      s   r@   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 )z)Constructor for an UnexpectedMethodError.zExpected: [%s] - Provided: [%s]N)rB   rE   r   )r   expectedprovided)rC   r	   r
   r      s    
zUnexpectedBodyError.__init__)r   r   r   r   r   rD   r	   r	   )rC   r
   rE      s   rE   )r   
__future__r   
__author__r$   Zgoogleapiclientr   r0   	Exceptionr   r   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r@   rE   r	   r	   r	   r
   <module>   s$   H