U
    b                     @   s   d dl Z d dlm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lmZ dd	lmZ e eZdeeeef  eeee dddZeeeee dddZdS )    N)ThreadPoolExecutor)SequenceTupleOptional   )Spinner)CondaSession   )cached_response)ChannelNoticeResponseF
   )url_and_namessilentmax_workersreturnc              
   C   sT   t |d}td| d2 ttddd |dd | D W  5 Q R  S Q R X dS )	aK  
    Provided a list of channel notification url/name tuples, return a sequence of
    ChannelNoticeResponse objects.

    Args:
        silent: turn off "loading animation" (defaults to False)
        max_workers: increase worker number in thread executor (defaults to 10)
    Returns:
        Sequence[ChannelNoticeResponse]
    )r   zRetrieving notices)enabledNc                 s   s   | ]
}|V  qd S N ).0Zchn_infor   r   1lib/python3.8/site-packages/conda/notices/http.py	<genexpr>'   s   z'get_notice_responses.<locals>.<genexpr>c                 S   s   t |  S r   )get_channel_notice_response)argsr   r   r   <lambda>*       z&get_notice_responses.<locals>.<lambda>)r   r   tuplefiltermap)r   r   r   Zexecutorr   r   r   get_notice_responses   s    
 r   )urlnamer   c              	   C   s   t  }z|j| ddd}W n0 tjjk
rJ   td| d|   Y dS X z:|jdk rlt| ||	 dW S td	|j d
|   W n2 t
k
r   td|   t| |dd Y S X dS )z
    Return a channel response object. We use this to wrap the response with
    additional channel information to use. If the response was invalid we suppress/log
    and error message.
    F   )Zallow_redirectsZtimeoutzRequest timed out for channel: z url: Ni,  )Z	json_dataz	Received z when trying to GET zUnable to parse JSON data for )r   getrequests
exceptionsZTimeoutloggerinfoZstatus_coder   Zjson
ValueError)r   r    ZsessionZrespr   r   r   r   1   s    
r   )Fr   )ZloggingZconcurrent.futuresr   typingr   r   r   r#   Z	common.ior   Zgateways.connection.sessionr   cacher
   typesr   Z	getLogger__name__r%   strboolintr   r   r   r   r   r   <module>   s$   
     