ó
Ý²k^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   ":	"`	$
			