U
    Td	                     @   s`   d Z ddlmZ ddlZddlZeeZdZej	
ej	ej	edZdd Zdd	 ZdS )
z+Caching utility for the discovery document.    )absolute_importNiQ Z	documentsc                  C   sr   dt jkr4zddlm}  | jW S  tk
r2   Y nX zddlm} |jW S  tk
rl   tjddd Y dS X dS )	zDetects an appropriate cache module and returns it.

    Returns:
      googleapiclient.discovery_cache.base.Cache, a cache object which
      is auto detected, or None if no cache object is available.
    ZGAE_ENV   )appengine_memcache)
file_cachez4file_cache is only supported with oauth2client<4.0.0F)exc_infoN)	osenviron r   cache	Exceptionr   LOGGERinfo)r   r    r   L/tmp/pip-unpacked-wheel-huf2bctx/googleapiclient/discovery_cache/__init__.py
autodetect   s    
 r   c              	   C   sV   d}d | |}z,ttjt|d}| }W 5 Q R X W n tk
rP   Y nX |S )a  Retrieves the discovery document from the directory defined in
    DISCOVERY_DOC_DIR corresponding to the serviceName and version provided.

    Args:
        serviceName: string, name of the service.
        version: string, the version of the service.

    Returns:
        A string containing the contents of the JSON discovery document,
        otherwise None if the JSON discovery document was not found.
    Nz
{}.{}.jsonr)formatopenr   pathjoinDISCOVERY_DOC_DIRreadFileNotFoundError)ZserviceNameversioncontentZdoc_namefr   r   r   get_static_doc7   s    r   )__doc__
__future__r   loggingr   	getLogger__name__r   ZDISCOVERY_DOC_MAX_AGEr   r   dirnamerealpath__file__r   r   r   r   r   r   r   <module>   s   
 