
    8i                         S r SSKrSSKrSSKJr  SSKJr   " S S\5      r " S	 S
\5      r	 " S S\	5      r
 " S S\	5      rS r/ SQrg)zEModule implementing the Pool for :mod:``requests_toolbelt.threaded``.    N   )thread   )queuec                       \ rS rSrSrSSS\R                  4S jrS r\	S 5       r
\	SS j5       rS rS	 rS
 rS rS rSrg)Pool	   a  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           	      *   Uc  [         R                  " 5       =(       d    SnUS:  a  [        S5      eXl        [        R
                  " 5       U l        [        R
                  " 5       U l        X@l        U=(       d    [        U l
        U=(       d    [        U l        XPl        [        U R                  5       Vs/ s HH  n[        R                  " U R!                  5       U R                  U R                  U R                  5      PMJ     snU l        g s  snf )Nr   z)Number of processes should at least be 1.)multiprocessing	cpu_count
ValueError
_job_queuer   Queue_response_queue
_exc_queue
_processes	_identity_initializer_auth_sessionranger   SessionThread_new_session_pool)self	job_queueinitializerauth_generatornum_processessession_s          o/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/requests_toolbelt/threaded/pool.py__init__Pool.__init__   s     +557<1M1HII#${{}++-''49#0y
 4??+
 ,   !2!2!4doo!%!5!5tH+

 
s   8ADc                 ^    U R                  U R                  U R                  5       5      5      $ N)r   r   r   )r   s    r"   r   Pool._new_session0   s"    zz$++DMMO<==    c                     [         R                  " 5       nU H  nUR                  UR                  5        M      U " SSU0UD6$ )a  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   putrequest_kwargs)cls
exceptionskwargsr   excs        r"   from_exceptionsPool.from_exceptions3   s@      KKM	CMM#,,-  1Y1&11r(   c                     SS0nUR                  U=(       d    0 5        [        R                  " 5       nU H7  nUR                  5       nUR                  SU05        UR	                  U5        M9     U " SSU0UD6$ )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   r6   jobs           r"   	from_urlsPool.from_urlsI   su     !%(N0b1KKM	C##%CJJs|$MM# 
 1Y1&11r(   c              #   @   #     U R                  5       nUc  gUv   M  7f)z_Iterate over all the exceptions in the pool.

:returns: Generator of :class:`~ThreadException`
N)get_exception)r   r0   s     r"   r.   Pool.exceptionsb   s*     
 $$&C{I	    c                      U R                   R                  5       u  p[        X5      $ ! [        R                   a     gf = f)zCGet an exception from the pool.

:rtype: :class:`~ThreadException`
N)r   
get_nowaitThreadExceptionr   Empty)r   requestr0   s      r"   r?   Pool.get_exceptionm   s@    
	1!__779NW #700 {{ 		   ) A A c                      U R                   R                  5       u  p[        X5      $ ! [        R                   a     gf = f)z@Get a response from the pool.

:rtype: :class:`~ThreadResponse`
N)r   rC   ThreadResponser   rE   )r   rF   responses      r"   get_responsePool.get_responsey   sC    
	5"&"6"6"A"A"CW "'44 {{ 		rH   c              #   @   #     U R                  5       nUc  gUv   M  7f)z]Iterate over all the responses in the pool.

:returns: Generator of :class:`~ThreadResponse`
N)rL   )r   resps     r"   	responsesPool.responses   s*     
 $$&D|J	 rA   c                 J    U R                    H  nUR                  5         M     g)z*Join all the threads to the master thread.N)r   join)r   session_threads     r"   join_allPool.join_all   s    "jjN! )r(   )r   r   r   r   r   r   r   r   r&   )__name__
__module____qualname____firstlineno____doc__requestsSessionr#   r   classmethodr1   r<   r.   r?   rL   rP   rU   __static_attributes__r*   r(   r"   r   r   	   sd    " /34#X-=-=
*> 2 2* 2 20	
1
5	"r(   r   c                       \ rS rSrSrS rSrg)ThreadProxy   Nc                     [         R                  nXR                  ;  a  U" X R                  5      n[	        X15      $ U" X5      $ )z/Proxy attribute accesses to the proxied object.)object__getattribute__attrsproxied_attrgetattr)r   attrgetrK   s       r"   __getattr__ThreadProxy.__getattr__   s<    %%zz!4!2!23H8**t?"r(   r*   )rW   rX   rY   rZ   rg   rk   r_   r*   r(   r"   ra   ra      s    L#r(   ra   c                   6    \ rS rSrSrSr\" SS/5      rS rSr	g)rJ      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()

rK   r,   c                     Xl         X l        g r&   r,   rK   )r   r,   rK   s      r"   r#   ThreadResponse.__init__   s    , r(   rp   N
rW   rX   rY   rZ   r[   rg   	frozensetrf   r#   r_   r*   r(   r"   rJ   rJ      s#    
 L'45E!r(   rJ   c                   6    \ rS rSrSrSr\" SS/5      rS rSr	g)rD      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                     Xl         X l        g r&   )r,   rv   )r   r,   rv   s      r"   r#   ThreadException.__init__   s    ,"r(   )rv   r,   Nrr   r*   r(   r"   rD   rD      s#    
 L'56E#r(   rD   c                     U $ r&   r*   )session_objs    r"   r   r      s    r(   )rD   rJ   r   )r[   r   r\    r   _compatr   rd   r   ra   rJ   rD   r   __all__r*   r(   r"   <module>r~      sS    K    J"6 J"Z
#& 
#![ !,#k #, 8r(   