U
    Òøïc6  ã                   @   sd   d dl Z d dlmZmZmZ d dlZddlmZ ddlm	Z	 ddgZ
G dd„ dƒZG d	d„ dƒZdS )
é    N)ÚAnyÚDictÚUnioné   )ÚDEFAULT_USER_AGENT)Úqueue_fetch_taskÚLazySessionÚAIOHttpMixinc                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )r   c                 C   s
   d | _ d S ©N)Ú_session©Úself© r   úX/tmp/pip-unpacked-wheel-rwcmptg8/pyhanko_certvalidator/fetchers/aiohttp_fetchers/util.pyÚ__init__   s    zLazySession.__init__c                 Ã   s    | j }|d krt ¡  | _ }|S r
   )r   ÚaiohttpÚClientSession©r   Úsessionr   r   r   Úget_session   s    zLazySession.get_sessionc                 Ã   s    | j }|d k	r| ¡ I d H  d S r
   )r   Úcloser   r   r   r   r      s    zLazySession.closeN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r      s   c                       s^   e Zd Zdeejef dœ‡ fdd„Zejdœdd„Zd	d
„ Z	dd„ Z
dd„ Zdd„ Z‡  ZS )r	   Né
   )r   c                    s0   || _ |pt| _|| _i | _i | _tƒ  ¡  d S r
   )r   r   Ú
user_agentÚper_request_timeoutÚ_AIOHttpMixin__resultsÚ_AIOHttpMixin__result_eventsÚsuperr   )r   r   r   r   ©Ú	__class__r   r   r      s    
zAIOHttpMixin.__init__)Úreturnc                 Ã   s&   | j }t|tƒr| ¡ I d H S |S d S r
   )r   Ú
isinstancer   r   r   r   r   r   r   *   s    
zAIOHttpMixin.get_sessionc                 C   s   dd„ | j  ¡ D ƒS )Nc                 S   s   h | ]}t |tƒs|’qS r   )r#   Ú	Exception)Ú.0Úvr   r   r   Ú	<setcomp>2   s    
 z+AIOHttpMixin.get_results.<locals>.<setcomp>)r   Úvaluesr   r   r   r   Úget_results1   s    ÿzAIOHttpMixin.get_resultsc                 C   s   | j | }t|tƒrt‚d S r
   )r   r#   r$   ÚKeyError)r   ÚtagÚresultr   r   r   Úget_results_for_tag6   s    

z AIOHttpMixin.get_results_for_tagc                 c   s,   | j  ¡ D ]\}}t|tƒs
||fV  q
d S r
   )r   Úitemsr#   r$   )r   Úkr&   r   r   r   Ú_iter_results;   s    
zAIOHttpMixin._iter_resultsc                 Ã   s   t | j| j||ƒI d H S r
   )r   r   r   )r   r+   Z	async_funr   r   r   Ú_post_fetch_task@   s       ÿzAIOHttpMixin._post_fetch_task)Nr   )r   r   r   r   r   r   r   r   r   r)   r-   r0   r1   Ú__classcell__r   r   r    r   r	      s     üþ)ZasyncioÚtypingr   r   r   r   Úapir   Zcommon_utilsr   Ú__all__r   r	   r   r   r   r   Ú<module>   s   