
    wcR                        d Z ddlmZ ddlmZ ddlmZmZmZm	Z	m
Z
 ddlZddlmZmZmZ ddlmZ dd	lmZmZ  ee          Zd
dddddddef	dedededeeef         dee         ded         dedede
e         fdZd Zed             Zed             Zde	e         fdZdefdZd  Z d#defd!Z!efde
e         fd"Z"dS )$a  Utilities for patching ``requests``.

.. warning:: These functions are not thread-safe. Use :py:class:`.CachedSession` if you want to use
    caching in a multi-threaded environment.

.. automodsumm:: requests_cache.patcher
   :functions-only:
   :nosignatures:
    )contextmanager)	getLogger)CallableDictIterableOptionalTypeN   )BackendSpecifier	BaseCacheinit_backend)ExpirationTime)CachedSessionOriginalSession
http_cache)   )GETHEADF
cache_namebackendexpire_afterurls_expire_afterallowable_codesallowable_methodsstr	filter_fnstale_if_errorsession_factoryc	                     	 t           fi 	 G  	f	dd|          }
t          |
           dS )a  
    Install the cache for all ``requests`` functions by monkey-patching :py:class:`requests.Session`

    Example:

        >>> requests_cache.install_cache('demo_cache')

    Accepts all the same parameters as :py:class:`.CachedSession`. Additional parameters:

    Args:
        session_factory: Session class to use. It must inherit from either
            :py:class:`.CachedSession` or :py:class:`.CacheMixin`
    c            
       2   	  e Zd Z 	f
dZ xZS )/install_cache.<locals>._ConfiguredCachedSessionc                 L   
  t                      j        d
	d d S )N)r   r   r   r   r   r   r   r    )super__init__)self	__class__r   r   r   r   r   r   kwargsr   r   s    8/usr/lib/python3/dist-packages/requests_cache/patcher.pyr&   z8install_cache.<locals>._ConfiguredCachedSession.__init__3   sT    EGG 
%)"3 /"3#-
 
 
 
 
 
 
    )__name__
__module____qualname__r&   __classcell__)
r(   r   r   r   r   r   r   r)   r   r   s
   @r*   _ConfiguredCachedSessionr"   2   sf        	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r+   r0   N)r   _patch_session_factory)r   r   r   r   r   r   r   r   r   r)   r0   s   ```````` ` r*   install_cacher2      s    2 :w99&99G              ?    344444r+   c                  .    t          t                     dS )zHDisable the cache by restoring the original :py:class:`requests.Session`N)r1   r   r$   r+   r*   uninstall_cacher4   C   s    ?+++++r+   c               #      K   t           j        } t                       	 dV  t          |            dS # t          |            w xY w)z
    Context manager for temporarily disabling caching for all ``requests`` functions

    Example:

        >>> with requests_cache.disabled():
        ...     requests.get('http://httpbin.org/get')

    N)requestsSessionr4   r1   )previouss    r*   disabledr9   H   sS       H)x(((((x((((s	   3 Ac               /   n   K   t          | i | 	 dV  t                       dS # t                       w xY w)a  
    Context manager for temporarily enabling caching for all ``requests`` functions

    Accepts the same arguments as :py:func:`.install_cache`.

    Example:

        >>> with requests_cache.enabled('cache_db'):
        ...     requests.get('http://httpbin.org/get')

    N)r2   r4   )argsr)   s     r*   enabledr<   [   sM       4"6"""s   $ 4returnc                  F    t          t          j                    dd          S )zUGet the internal cache object from the currently installed ``CachedSession`` (if any)cacheN)getattrr6   r7   r$   r+   r*   	get_cacherA   o   s    8#%%w555r+   c                  N    t          t          j                    t                    S )z=Indicate whether or not requests-cache is currently installed)
isinstancer6   r7   r   r$   r+   r*   is_installedrD   t   s    h&((-888r+   c                  f    t                      r"t                                                       dS dS )z,Clear the currently installed cache (if any)N)rA   clearr$   r+   r*   rF   rF   y   s4    {{  r+   c                     t          j                    }t          |t                    r|                    |            dS dS )zRemove expired responses from the cache, optionally with revalidation

    Args:
        expire_after: A new expiration time used to revalidate the cache
    N)r6   r7   rC   r   remove_expired_responses)r   sessions     r*   rH   rH      sH       G'=)) 7((666667 7r+   c                     t                               d| j                    | xt          _        t          j        _        d S )Nz&Patching requests.Session with class: )loggerdebugr,   r6   r7   sessions)r   s    r*   r1   r1      s9    
LLT/:RTTUUU3BBHx(000r+   )N)#__doc__
contextlibr   loggingr   typingr   r   r   r   r	   r6   backendsr   r   r   policyr   rI   r   r   r,   rK   r   intboolr2   r4   r9   r<   rA   rD   rF   rH   r1   r$   r+   r*   <module>rV      sP    & % % % % %       ; ; ; ; ; ; ; ; ; ; ; ; ; ;  ? ? ? ? ? ? ? ? ? ? " " " " " " 3 3 3 3 3 3 3 3	8		 # $#%37%+)8 -:)5 )5)5)5 !)5 C/0	)5
 c])5  )5 )5 )5 /*)5 )5 )5 )5X, , ,
 ) ) )$   &68I& 6 6 6 6
9d 9 9 9 9
  7 7> 7 7 7 7 ER C CD,A C C C C C Cr+   