๓
lz]c           @` sศ  d  d l  m Z m Z m Z m Z d  d l m Z d  d l Z d  d l m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z d  d l 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
 Z e e e e f Z e j d  d k rd   Z n	 d   Z d e
 f d     YZ  d e f d     YZ! e d    Z" d   Z# e	 d  Z$ e d  Z% e d  Z& d   Z' d   Z( e j) e d  e( e j* _( e j* j+ e j* _, d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literals(   t   partialN(   t   DEBUGt   ERRORt   Filtert	   Formattert   INFOt   StreamHandlert   WARNt	   getLoggeri   (   t
   CondaError(   t   memoize(   t   attach_stderr_handler(   t   string_typesi   c         C` s3   t  |  t  r/ t  |  t  r/ t |  d d S|  S(   Nt   encodingu   utf-8(   t
   isinstancet
   basestringt   unicode(   t   val(    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyt   another_to_unicode   s    c         C` s   |  S(   N(    (   R   (    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyR      s    t   TokenURLFilterc           B` s2   e  Z e j d   Z e e j d  Z d   Z RS(   u   (|https?://)(|\s|(?:(?:\d{1,3}\.){3}\d{1,3})|(?:(?:[a-zA-Z0-9-]{1,20}\.){0,10}(?:[a-zA-Z]{2}[a-zA-Z0-9-]{0,18})))(|:\d{1,5})?/t/[a-z0-9A-Z-]+/u   \1\2\3/t/<TOKEN>/c         ` sc   t    j | j   | _ | j r_ t   f d   | j D  } | j | | _ d | _ n  t S(   u>  
        Since Python 2's getMessage() is incapable of handling any
        strings that are not unicode when it interpolates the message
        with the arguments, we fix that here by doing it ourselves.

        At the same time we replace tokens in the arguments which was
        not happening until now.
        c         3` s9   |  ]/ } t  | t  r-   j t |   n | Vq d  S(   N(   R   R   t   TOKEN_REPLACER   (   t   .0t   arg(   t   self(    s5   lib/python2.7/site-packages/conda/gateways/logging.pys	   <genexpr>9   s   N(   R   R   t   msgt   argst   tuplet   Nonet   True(   R   t   recordt   new_args(    (   R   s5   lib/python2.7/site-packages/conda/gateways/logging.pyt   filter-   s    
	(	   t   __name__t
   __module__t   ret   compilet   TOKEN_URL_PATTERNR   t   subR   R#   (    (    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyR      s   	
t   StdStreamHandlerc           B` s/   e  Z d  Z d Z d   Z d   Z d   Z RS(   u?   Log StreamHandler that always writes to the current sys stream.u   
c         C` s2   t  t |   j t t |   | |  _ |  ` d S(   ur   
        Args:
            sys_stream: stream name, either "stdout" or "stderr" (attribute of module sys)
        N(   t   superR*   t   __init__t   getattrt   syst
   sys_streamt   stream(   R   R/   (    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyR,   F   s    	c         C` s2   | d k r t  t |  j  St t |   j |  S(   Nu   stream(   R-   R.   R/   R+   R*   t   __getattribute__(   R   t   attr(    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyt   __getattr__O   s    c         C` sh  y t  t } Wn t k
 r' t } n Xy|  j |  } |  j } d } | sc | j | |  nณ y t | t   rึ t | d d  rึ d } y | j | |  Wq็ t
 k
 rา | j | | j | j   q็ Xn | j | |  Wn+ t k
 r| j | | j d   n Xt | d |  j  } | j |  |  j   Wn t k
 rc|  j |  n Xd S(   uซ  
        Emit a record.

        If a formatter is specified, it is used to format the record.
        The record is then written to the stream with a trailing newline.  If
        exception information is present, it is formatted using
        traceback.print_exception and appended to the stream.  If the stream
        has an 'encoding' attribute, it is used to determine how to do the
        output to the stream.
        u   %su   encodingu   UTF-8u
   terminatorN(   R   R    t	   NameErrort   Falset   formatR0   t   writeR   R-   R   t   UnicodeEncodeErrort   encodeR   t   UnicodeErrort
   terminatort   flusht	   Exceptiont   handleError(   R   R!   t   _unicodeR   R0   t   fst   ufsR;   (    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyt   emith   s6    

	$(   R$   R%   t   __doc__R;   R,   R3   RB   (    (    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyR*   A   s
   			c           C` s   t    t   t   d  S(   N(   t   initialize_root_loggert   set_conda_log_levelt   initialize_std_loggers(    (    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyt   initialize_loggingก   s    c          C` s\  t  d  }  x๋ d D]ใ } t d |  } g  | _ | j t  t |  } | j t  | j |   | j |  | j t	    t
 | _ t d |  } g  | _ | j t  t |  } d | _ | j t  | j |   | j |  t
 | _ q Wt d  } g  | _ | j t  t d  } | j t  | j |   | j |  t
 | _ d  S(	   Nu   %(message)su   stdoutu   stderru   conda.%su   conda.%slogu    u   conda.stdout.verbose(   u   stdoutu   stderr(   R   R   t   handlerst   setLevelR	   R*   t   setFormattert
   addHandlert	   addFilterR   R5   t	   propagateR   R;   (   t	   formatterR0   t   loggert   handlert   stdlog_loggert   stdlog_handlert   verbose_loggert   verbose_handler(    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyRF   ฉ   s8    					c         C` s   t  |   d  S(   N(   R   (   t   level(    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyRD   อ   s    c         C` s&   t  d  } | j |   t | _ d  S(   Nu   conda(   R   RI   R    RM   (   RU   t   conda_logger(    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyRE   ั   s    c         C` sV   |  t  k r t d  n d  } t |  d | t |   t |  d  t |  d  d  S(   Nu   %(message)s
RN   u   requestsu   requests.packages.urllib3(   R	   R   R   R   RE   (   RU   RN   (    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyt   set_all_logger_levelื   s
    
c         C` sL   y t  t |   Wn# t k
 r7 t d d |   n Xt j d |   d  S(   Nu,   Invalid verbosity level: %(verbosity_level)st   verbosity_levelu   verbosity set to %s(   RW   t   VERBOSITY_LEVELSt
   IndexErrorR   t   logt   debug(   RX   (    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyt   set_verbosityแ   s    	c         O` s,   |  j  t  r( |  j t | | |  n  d  S(   N(   t   isEnabledFort   TRACEt   _log(   R   t   messageR   t   kwargs(    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyt   trace๊   s    u   TRACE(-   t
   __future__R    R   R   R   t	   functoolsR   t   loggingR   R   R   R   R	   R
   R   R   R&   R.   t    R   t   _vendor.auxlib.decoratorsR   t	   common.ioR   t   common.compatR   R$   R[   R_   RY   t   version_infoR   R   R*   RG   RF   RD   RE   RW   R]   Rc   t   addLevelNamet   Loggert   warningt   warn(    (    (    s5   lib/python2.7/site-packages/conda/gateways/logging.pyt   <module>   s6   ":	"`	$
			