
    .Ph                         d Z ddlZddlZddlmZ ddlmZ  G d de          Z G d	 d
e          Z	 G d de	          Z
 G d de	          Zd Zg dZdS )zEModule implementing the Pool for :mod:``requests_toolbelt.threaded``.    N   )thread   )queuec                   ~    e Zd ZdZdddej        fdZd Zed             Z	edd            Z
d Zd Zd	 Zd
 Zd ZdS )Poola>  Pool that manages the threads containing sessions.

    :param queue:
        The queue you're expected to use to which you should add items.
    :type queue: queue.Queue
    :param initializer:
        Function used to initialize an instance of ``session``.
    :type initializer: collections.Callable
    :param auth_generator:
        Function used to generate new auth credentials for the session.
    :type auth_generator: collections.Callable
    :param int num_process:
        Number of threads to create.
    :param session:
    :type session: requests.Session
    Nc                 l    |t          j                    pd}|dk     rt          d          | _        t	          j                     _        t	          j                     _        | _        |pt           _
        |pt           _        | _         fdt           j                  D              _        d S )Nr   z)Number of processes should at least be 1.c                     g | ]:}t          j                                        j        j        j                  ;S  )r   SessionThread_new_session
_job_queue_response_queue
_exc_queue).0_selfs     _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/requests_toolbelt/threaded/pool.py
<listcomp>z!Pool.__init__.<locals>.<listcomp>*   sV     
 
 
   !2!2!4!4do!%!5tH H
 
 
    )multiprocessing	cpu_count
ValueErrorr   r   Queuer   r   
_processes	_identity_initializer_auth_sessionrange_pool)r   	job_queueinitializerauth_generatornum_processessessions   `     r   __init__zPool.__init__   s     +577<1M1HIII#${}}+--''49#0y

 
 
 
 4?++
 
 



r   c                 v    |                      |                     |                                                     S N)r   r   r   )r   s    r   r   zPool._new_session0   s*    zz$++DMMOO<<===r   c                 z    t          j                    }|D ]}|                    |j                    | dd|i|S )a2  Create a :class:`~Pool` from an :class:`~ThreadException`\ s.

        Provided an iterable that provides :class:`~ThreadException` objects,
        this classmethod will generate a new pool to retry the requests that
        caused the exceptions.

        :param exceptions:
            Iterable that returns :class:`~ThreadException`
        :type exceptions: iterable
        :param kwargs:
            Keyword arguments passed to the :class:`~Pool` initializer.
        :returns: An initialized :class:`~Pool` object.
        :rtype: :class:`~Pool`
        r"   r   )r   r   putrequest_kwargs)cls
exceptionskwargsr"   excs        r   from_exceptionszPool.from_exceptions3   sQ      KMM	 	. 	.CMM#,----s11Y1&111r   c                     ddi}|                     |pi            t          j                    }|D ]B}|                                }|                     d|i           |                    |           C | dd|i|S )a  Create a :class:`~Pool` from an iterable of URLs.

        :param urls:
            Iterable that returns URLs with which we create a pool.
        :type urls: iterable
        :param dict request_kwargs:
            Dictionary of other keyword arguments to provide to the request
            method.
        :param kwargs:
            Keyword arguments passed to the :class:`~Pool` initializer.
        :returns: An initialized :class:`~Pool` object.
        :rtype: :class:`~Pool`
        methodGETurlr"   r   )updater   r   copyr+   )r-   urlsr,   r/   request_dictr"   r5   jobs           r   	from_urlszPool.from_urlsI   s     !%(N0b111KMM	 	 	C##%%CJJs|$$$MM#s11Y1&111r   c              #   B   K   	 |                                  }|dS |V  )zoIterate over all the exceptions in the pool.

        :returns: Generator of :class:`~ThreadException`
        TN)get_exception)r   r0   s     r   r.   zPool.exceptionsb   s4      
	$$&&C{III		r   c                     	 | j                                         \  }}t          ||          S # t          j        $ r Y dS w xY w)zSGet an exception from the pool.

        :rtype: :class:`~ThreadException`
        N)r   
get_nowaitThreadExceptionr   Empty)r   requestr0   s      r   r=   zPool.get_exceptionm   sV    
	1!_7799NWc #7C000 { 	 	 	44	   . A Ac                     	 | j                                         \  }}t          ||          S # t          j        $ r Y dS w xY w)zPGet a response from the pool.

        :rtype: :class:`~ThreadResponse`
        N)r   r?   ThreadResponser   rA   )r   rB   responses      r   get_responsezPool.get_responsey   sX    
	5"&"6"A"A"C"CWh "'8444 { 	 	 	44	rC   c              #   B   K   	 |                                  }|dS |V  )zmIterate over all the responses in the pool.

        :returns: Generator of :class:`~ThreadResponse`
        TN)rG   )r   resps     r   	responseszPool.responses   s4      
	$$&&D|JJJ		r   c                 B    | j         D ]}|                                 dS )z*Join all the threads to the master thread.N)r!   join)r   session_threads     r   join_allzPool.join_all   s2    "j 	" 	"N!!!!	" 	"r   r)   )__name__
__module____qualname____doc__requestsSessionr'   r   classmethodr1   r;   r.   r=   rG   rJ   rN   r   r   r   r   r   	   s         " /34#X-=
 
 
 
*> > > 2 2 [2* 2 2 2 [20	 	 	
1 
1 
1
5 
5 
5	 	 	" " " " "r   r   c                       e Zd ZdZd ZdS )ThreadProxyNc                     t           j        }|| j        vr! || | j                  }t	          ||          S  || |          S )z/Proxy attribute accesses to the proxied object.)object__getattribute__attrsproxied_attrgetattr)r   attrgetrF   s       r   __getattr__zThreadProxy.__getattr__   sK    %tz!!s4!233H8T***3tT??"r   )rO   rP   rQ   r\   r`   r   r   r   rW   rW      s(        L# # # # #r   rW   c                   6    e Zd ZdZdZ eddg          Zd ZdS )rE   a>  A wrapper around a requests Response object.

    This will proxy most attribute access actions to the Response object. For
    example, if you wanted the parsed JSON from the response, you might do:

    .. code-block:: python

        thread_response = pool.get_response()
        json = thread_response.json()

    rF   r,   c                 "    || _         || _        d S r)   )r,   rF   )r   r,   rF   s      r   r'   zThreadResponse.__init__   s    , r   NrO   rP   rQ   rR   r\   	frozensetr[   r'   r   r   r   rE   rE      sI        
 
 LI'455E! ! ! ! !r   rE   c                   6    e Zd ZdZdZ eddg          Zd ZdS )r@   a=  A wrapper around an exception raised during a request.

    This will proxy most attribute access actions to the exception object. For
    example, if you wanted the message from the exception, you might do:

    .. code-block:: python

        thread_exc = pool.get_exception()
        msg = thread_exc.message

    	exceptionr,   c                 "    || _         || _        d S r)   )r,   rf   )r   r,   rf   s      r   r'   zThreadException.__init__   s    ,"r   Nrc   r   r   r   r@   r@      sI        
 
 LI'566E# # # # #r   r@   c                     | S r)   r   )session_objs    r   r   r      s    r   )r@   rE   r   )rR   r   rS    r   _compatr   rY   r   rW   rE   r@   r   __all__r   r   r   <module>rm      s   K K                 J" J" J" J" J"6 J" J" J"Z
# 
# 
# 
# 
#& 
# 
# 
#! ! ! ! ![ ! ! !,# # # # #k # # #,   8
7
7r   