
ˀX                 @   sW   d  Z  d d l Z d d l Z d d l j Z d d l m Z Gd d   d e  Z	 d S)z*Module containing the SessionThread class.    N   )queuec               @   sX   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d S)SessionThreadc             C   s2   | |  _  | |  _ |  j   | |  _ | |  _ d  S)N)_session_jobs_create_worker
_responses_exceptions)selfZinitialized_sessionZ	job_queueZresponse_queueZexception_queue r   C/usr/lib/python3/dist-packages/requests_toolbelt/threaded/thread.py__init__   s
    		
	zSessionThread.__init__c             C   sM   t  j d |  j d t j    |  _ d |  j _ d |  j _ |  j j   d  S)NtargetnameTr   )		threadingZThread_make_requestuuidZuuid4_workerZdaemonZ_statestart)r
   r   r   r   r      s    		zSessionThread._create_workerc             C   s   zq y |  j  j |   } Wn> t j k
 rY } z |  j j | | f  WYd  d  } ~ Xn X|  j j | | f  Wd  |  j j   Xd  S)N)	r   ZrequestexcZRequestExceptionr	   Zputr   r   Z	task_done)r
   kwargsZresponseer   r   r   _handle_request   s    )zSessionThread._handle_requestc             C   sD   x= y |  j  j   } Wn t j k
 r. PYn X|  j |  q Wd  S)N)r   Z
get_nowaitr   ZEmptyr   )r
   r   r   r   r   r   &   s    zSessionThread._make_requestc             C   s   |  j  j   S)z*Proxy to the thread's ``is_alive`` method.)r   is_alive)r
   r   r   r   r   /   s    zSessionThread.is_alivec             C   s   |  j  j   d S)z&Join this thread to the master thread.N)r   join)r
   r   r   r   r   3   s    zSessionThread.joinN)	__name__
__module____qualname__r   r   r   r   r   r   r   r   r   r   r   
   s   	
	r   )
__doc__r   r   Zrequests.exceptions
exceptionsr   Z_compatr   objectr   r   r   r   r   <module>   s
   