
    h                     |    d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZmZ d Zd	Z G d
 de      Zy)aY  
requests_futures
~~~~~~~~~~~~~~~~

This module provides a small add-on for the requests http library. It makes use
of python 3.3's concurrent.futures or the futures backport for previous
releases of python.

    from requests_futures.sessions import FuturesSession

    session = FuturesSession()
    # request is run in the background
    future = session.get('http://httpbin.org/get')
    # ... do other stuff ...
    # wait for the request to complete, if it hasn't already
    response = future.result()
    print('response status: {0}'.format(response.status_code))
    print(response.content)

    )ProcessPoolExecutorThreadPoolExecutor)partial)	getLogger)PickleErrordumps)Session)DEFAULT_POOLSIZEHTTPAdapterc                 ,     ||i |} || |      xs |S )z6A global top-level is required for ProcessPoolExecutor )selfsupbackground_callbackargs_kwargs_resps         c/var/www/betterdocs.net/sherlock_api/venv/lib/python3.12/site-packages/requests_futures/sessions.pywrapr      s#    !!DtT*2d2    zsCannot pickle function. Refer to documentation: https://github.com/ross/requests-futures/#using-processpoolexecutorc                        e Zd Z	 	 	 	 d fd	Zd Z fdZ fdZ fdZ fdZd fd	Z	d fd	Z
d fd		Z fd
Z xZS )FuturesSessionc                 N   i }t        t        | 
  |i | |du | _        |)t	        |      }|t
        kD  r|j                  ||d       |j                  |xs i        |r6| j                  dt        di |       | j                  dt        di |       || _	        || _
        y)a*  Creates a FuturesSession

        Notes
        ~~~~~
        * `ProcessPoolExecutor` may be used with Python > 3.4;
          see README for more information.

        * If you provide both `executor` and `max_workers`, the latter is
          ignored and provided executor is used as is.
        N)max_workers)pool_connectionspool_maxsizezhttps://zhttp://r   )superr   __init___owned_executorr   r
   updatemountr   executorsession)	r   r"   r   r#   adapter_kwargsargskwargs_adapter_kwargs	__class__s	           r   r   zFuturesSession.__init__,   s    & nd,d=f='4/)kBH--&&,7(3 	~34JJz;#A#ABJJy+"@"@A r   c                    | j                   r| j                   j                  }nt        t        j                  |       }|j	                  dd      }|rBt        | j                  j                        }|j                  d       t        t        | ||      }t        | j                  t              r	 t        |        | j                  j$                  |g|i |S # t        t        f$ r t!        t"              w xY w)ap  Maintains the existing api for Session.request.

        Used by all of the higher level methods, e.g. Session.get.

        The background_callback param allows you to do some processing on the
        response in the background, e.g. call resp.json() so that json parsing
        happens in the background thread.

        :rtype : concurrent.futures.Future
        r   NzS`background_callback` is deprecated and will be removed in 1.0, use `hooks` instead)r#   requestr   r	   popr   r(   __name__warningr   
isinstancer"   r   r   	TypeErrorr   RuntimeErrorPICKLE_ERRORsubmit)r   r%   r&   funcr   loggers         r   r*   zFuturesSession.requestV   s     <<<<''D 7??D1D$jj)>Et~~667FNN6 4t-@ADdmm%891d $t}}##D:4:6:: {+ 1"<001s   /C C9c                 x    t         t        |           | j                  r| j                  j                          y y N)r   r   closer   r"   shutdown)r   r(   s    r   r7   zFuturesSession.closey   s.    nd)+MM""$  r   c                 ,    t        t        | 
  |fi |S )z
        Sends a GET request. Returns :class:`Future` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype : concurrent.futures.Future
        )r   r   getr   urlr&   r(   s      r   r:   zFuturesSession.get~   s     ^T.s=f==r   c                 ,    t        t        | 
  |fi |S )zSends a OPTIONS request. Returns :class:`Future` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype : concurrent.futures.Future
        )r   r   optionsr;   s      r   r>   zFuturesSession.options   s     ^T23A&AAr   c                 ,    t        t        | 
  |fi |S )zSends a HEAD request. Returns :class:`Future` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype : concurrent.futures.Future
        )r   r   headr;   s      r   r@   zFuturesSession.head   s     ^T/>v>>r   c                 2    t        t        | 
  |f||d|S )a  Sends a POST request. Returns :class:`Future` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param json: (optional) json to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype : concurrent.futures.Future
        )datajson)r   r   post)r   r<   rB   rC   r&   r(   s        r   rD   zFuturesSession.post   s.     ^T/

)/
 	
r   c                 0    t        t        | 
  |fd|i|S )a|  Sends a PUT request. Returns :class:`Future` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype : concurrent.futures.Future
        rB   )r   r   putr   r<   rB   r&   r(   s       r   rF   zFuturesSession.put   s!     ^T.sHHHHr   c                 0    t        t        | 
  |fd|i|S )a~  Sends a PATCH request. Returns :class:`Future` object.

        :param url: URL for the new :class:`Request` object.
        :param data: (optional) Dictionary, list of tuples, bytes, or file-like
            object to send in the body of the :class:`Request`.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype : concurrent.futures.Future
        rB   )r   r   patchrG   s       r   rI   zFuturesSession.patch   s!     ^T0J4J6JJr   c                 ,    t        t        | 
  |fi |S )zSends a DELETE request. Returns :class:`Future` object.

        :param url: URL for the new :class:`Request` object.
        :param \*\*kwargs: Optional arguments that ``request`` takes.
        :rtype : concurrent.futures.Future
        )r   r   deleter;   s      r   rK   zFuturesSession.delete   s     ^T1#@@@r   )N   NN)NNr6   )r,   
__module____qualname__r   r*   r7   r:   r>   r@   rD   rF   rI   rK   __classcell__)r(   s   @r   r   r   +   sO     (T!;F%
>B?
	I	KA Ar   r   N)__doc__concurrent.futuresr   r   	functoolsr   loggingr   pickler   r   requestsr	   requests.adaptersr
   r   r   r1   r   r   r   r   <module>rW      s?   ( G   %  ;3B ZAW ZAr   