ó
sÁìVc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l Z d e j j _ d  d l m Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l m Z d  d l m Z m Z i d d 6d d	 6d
 d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6Z e d. d d/ e d0 i i d1 d2 6d3 g d4 6d5 6i d1 d2 6d3 g d4 6e d6 6d7 d8 6d7 6d4 i i d9 d: 6d; d< 6d= d> 6d3 6d? i i d@ dA 6dB dC 6dD d: 6d; 6ƒ Z dE „  Z dF e f dG „  ƒ  YZ dH „  Z dI e f dJ „  ƒ  YZ d S(K   iÿÿÿÿNi   (   t
   fileConfig(   t   util(   t   PY3t   string_typesi   t   authi
   t   authprivi	   t   croni   t   daemoni   t   ftpi    t   kerni   t   lpri   t   maili   t   newst   securityi   t   syslogt   useri   t   uucpi   t   local0i   t   local1i   t   local2i   t   local3i   t   local4i   t   local5i   t   local6i   t   local7t   versiont   disable_existing_loggerst   loggerst   INFOt   levelt   consolet   handlerst   roott	   propagates   gunicorn.errort   qualnames   logging.StreamHandlert   classt   generict	   formatters
   sys.stdoutt   streamt
   formatterss5   %(asctime)s [%(process)d] [%(levelname)s] %(message)st   formats   [%Y-%m-%d %H:%M:%S %z]t   datefmts   logging.Formatterc          C   s;   t  j }  |  j j j ƒ  } g  | D] } t  j | ƒ ^ q" S(   s    get list of all loggers (   t   loggingR    t   managert
   loggerDictt   keyst	   getLogger(   R    t   existingt   name(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR   M   s    	t	   SafeAtomsc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s`   t  j |  ƒ xL | j ƒ  D]> \ } } t | t ƒ rN | j d d ƒ |  | <q | |  | <q Wd  S(   Nt   "s   \"(   t   dictt   __init__t   itemst
   isinstanceR   t   replace(   t   selft   atomst   keyt   value(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR4   V   s
    c         C   sn   | j  d ƒ rD | j ƒ  } | |  k r= t t |  ƒ j | ƒ Sd Sn  | |  k rf t t |  ƒ j | ƒ Sd Sd  S(   Nt   {t   -(   t
   startswitht   lowert   superR1   t   __getitem__(   R8   t   kt   kl(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyRA   ^   s    (   t   __name__t
   __module__R4   RA   (    (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR1   T   s   	c         C   sÞ  |  j  d ƒ r| t j } |  j d d ƒ } t | ƒ d k re | d }  | d d k re t j } qe n  | |  j d ƒ d f S|  j  d ƒ rª |  j d ƒ d }  t j } n: |  j  d ƒ rØ |  j d ƒ d }  t j } n t d	 ƒ ‚ d
 |  k rd |  k r|  j d ƒ d d j ƒ  } nI d |  k rD|  j d ƒ d j ƒ  } n! |  d k rYd } n |  j ƒ  } |  j d ƒ d }  d |  k rÈ|  j d d ƒ d } | j ƒ  s¹t d | ƒ ‚ n  t	 | ƒ } n d } | | | f f S(   Ns   unix://t   #i   i   i    t   dgrams   udp://s   tcp://s   invalid syslog addresst   [t   ]t   :t    t	   localhostiÿÿÿÿs   %r is not a valid port number.i  (
   R>   t   sockett   SOCK_STREAMt   splitt   lent
   SOCK_DGRAMt   RuntimeErrorR?   t   isdigitt   int(   t   addrt	   sock_typet   partst   socktypet   hostt   port(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyt   parse_syslog_addressk   s<    	
 	t   Loggerc           B   s	  e  Z i e j d  6e j d 6e j d 6e j d 6e j d 6Z e j Z	 d Z
 d Z d Z d Z e Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! RS(   t   criticalt   errort   warningt   infot   debugs5   %(asctime)s [%(process)d] [%(levelname)s] %(message)ss   [%Y-%m-%d %H:%M:%S %z]s   %(message)ss   [%(process)d] %(message)sc         C   sh   t  j d ƒ |  _ t |  j _ t  j d ƒ |  _ t |  j _ g  |  _ g  |  _ | |  _ |  j	 | ƒ d  S(   Ns   gunicorn.errors   gunicorn.access(
   R*   R.   t	   error_logt   FalseR!   t
   access_logt   error_handlerst   access_handlerst   cfgt   setup(   R8   Rg   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR4   ª   s    			c         C   s  |  j  j | j j ƒ  t j ƒ |  _ |  j j |  j ƒ |  j j t j ƒ |  j	 |  j | j
 t j |  j |  j ƒ ƒ | j d  k	 r¯ |  j	 |  j | j d t j |  j ƒ ƒn  | j ró |  j |  j | |  j d ƒ |  j |  j | |  j d ƒ n  | j r{t j j | j ƒ r_t j ƒ  } | j | d <t j j | j ƒ | d <t | j d | d t ƒq{d } t | | j ƒ ‚ n  d  S(	   Nt   fmtR^   t   accesst   __file__t   heret   defaultsR   s    Error: log config '%s' not found(   t
   LOG_LEVELSt   gett   loglevelR?   R*   R   Rb   t   setLevelRd   t   _set_handlert   errorlogt	   Formattert	   error_fmtR)   t	   accesslogt   Nonet
   access_fmtR   t   _set_syslog_handlert
   syslog_fmtt	   logconfigt   ost   patht   existst   CONFIG_DEFAULTSt   copyt   dirnameR    Rc   RR   (   R8   Rg   Rm   t   msg(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyRh   ´   s,    $		
c         O   s   |  j  j | | | Ž d  S(   N(   Rb   R]   (   R8   R‚   t   argst   kwargs(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR]   Ö   s    c         O   s   |  j  j | | | Ž d  S(   N(   Rb   R^   (   R8   R‚   Rƒ   R„   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR^   Ù   s    c         O   s   |  j  j | | | Ž d  S(   N(   Rb   R_   (   R8   R‚   Rƒ   R„   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR_   Ü   s    c         O   s   |  j  j | | | Ž d  S(   N(   Rb   R`   (   R8   R‚   Rƒ   R„   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR`   ß   s    c         O   s   |  j  j | | | Ž d  S(   N(   Rb   Ra   (   R8   R‚   Rƒ   R„   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyRa   â   s    c         O   s   |  j  j | | | Ž d  S(   N(   Rb   t	   exception(   R8   R‚   Rƒ   R„   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR…   å   s    c         O   sM   t  | t ƒ r0 |  j j | j ƒ  t j ƒ } n  |  j j | | | | Ž d  S(   N(	   R6   R   Rn   Ro   R?   R*   R   Rb   t   log(   R8   t   lvlR‚   Rƒ   R„   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR†   è   s    !c   
   	   C   sù  | j  j d% d ƒ d } i | j d d ƒ d 6d d 6|  j | ƒ pH d d 6|  j ƒ  d 6d	 | d
 | d | d f d 6| d 6| j d
 ƒ d 6| j d ƒ d 6| j d ƒ d 6| j d ƒ d 6| j rØ t | j ƒ pÛ d d 6| j d 6| j d d ƒ d 6| j d d ƒ d 6| j d 6| j d | j	 d 6d | j | j	 f d 6d  t
 j ƒ  d! 6} t | d" ƒ rt| j } n | } | j t g  | D]" \ } }	 d# | j ƒ  |	 f ^ qŠƒ ƒ | j t g  | j D]" \ } }	 d$ | j ƒ  |	 f ^ qÉƒ ƒ | S(&   s'    Gets atoms for log formating.
        i   i    t   REMOTE_ADDRR=   t   ht   lt   ut   ts   %s %s %st   REQUEST_METHODt   RAW_URIt   SERVER_PROTOCOLt   rt   st   mt	   PATH_INFOt   Ut   QUERY_STRINGt   qt   Ht   bt   Bt   HTTP_REFERERt   ft   HTTP_USER_AGENTt   at   Ti@B t   Ds   %d.%06dt   Ls   <%s>t   pt   headerss   {%s}is   {%s}oN(   t   statusRO   Rw   Ro   t	   _get_usert   nowt   sentt   strt   secondst   microsecondsR|   t   getpidt   hasattrR¢   t   updateR3   R?   (
   R8   t   respt   reqt   environt   request_timeR£   R9   t   req_headersRB   t   v(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR9   í   s6    


<?c         C   sˆ   |  j  j p! |  j  j p! |  j  j s( d S|  j |  j | | | | ƒ ƒ } y |  j j |  j  j | ƒ Wn |  j	 t
 j ƒ  ƒ n Xd S(   s\    See http://httpd.apache.org/docs/2.0/logs.html#combined
        for format details
        N(   Rg   Rv   R{   R   t   atoms_wrapper_classR9   Rd   R`   t   access_log_formatR^   t	   tracebackt
   format_exc(   R8   R­   R®   R¯   R°   t
   safe_atoms(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyRj     s    $c         C   s   t  j d ƒ S(   s)    return date in Apache Common Log Format s   [%d/%b/%Y:%H:%M:%S %z](   t   timet   strftime(   R8   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR¥   '  s    c         C   sŽ   x‡ t  ƒ  D]| } xs | j D]h } t | t j ƒ r | j ƒ  z5 | j rp | j j ƒ  t | j	 | j
 ƒ | _ n  Wd  | j ƒ  Xq q Wq
 Wd  S(   N(   R   R   R6   R*   t   FileHandlert   acquireR&   t   closet   opent   baseFilenamet   modet   release(   R8   R†   t   handler(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyt   reopen_files+  s    
		c         C   s   xx t  ƒ  D]m } xd | j D]Y } t | t j ƒ r | j ƒ  z& | j ra t j | j j	 ƒ  ƒ n  Wd  | j
 ƒ  Xq q Wq
 Wd  S(   N(   R   R   R6   R*   Rº   R»   R&   R   t   close_on_exect   filenoRÀ   (   R8   R†   RÁ   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyRÃ   8  s    
	c         C   s.   x' | j  D] } t | d t ƒ r
 | Sq
 Wd  S(   Nt	   _gunicorn(   R   t   getattrRc   (   R8   R†   R‰   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyt   _get_gunicorn_handlerC  s    c         C   sÏ   |  j  | ƒ } | r( | j j | ƒ n  | d  k	 rË | d k rO t j ƒ  } nV t j | ƒ t j | ƒ } y& t	 j
 | j |  j j |  j j ƒ Wn t k
 r¤ n X| j | ƒ t | _ | j | ƒ n  d  S(   NR=   (   RÇ   R   t   removeRw   R*   t   StreamHandlerR   t   check_is_writeableRº   R|   t   chownR¾   Rg   R   t   groupt   OSErrort   setFormattert   TrueRÅ   t
   addHandler(   R8   R†   t   outputRi   R‰   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyRr   H  s    &	c   
      C   s  | j  s! | j j d d ƒ } n	 | j  } d | | f } t j d | | f ƒ } y t | j j ƒ  } Wn t k
 r‰ t	 d ƒ ‚ n Xt
 | j ƒ \ } } t j d k rÒ t j j d | d	 | d
 | ƒ }	 n t j j d | d	 | ƒ }	 |	 j | ƒ t |	 _ | j |	 ƒ d  S(   NRJ   t   .s   gunicorn.%s.%ss   %s: %ss   unknown facility namei   i   t   addresst   facilityRX   (   i   i   (   t   syslog_prefixt	   proc_nameR7   R*   Rt   t   SYSLOG_FACILITIESt   syslog_facilityR?   t   KeyErrorRR   R[   t   syslog_addrt   syst   version_infoR   t   SysLogHandlerRÎ   RÏ   RÅ   RÐ   (
   R8   R†   Rg   Ri   R0   t   prefixRÔ   RX   RU   R‰   (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyRy   `  s$    				c         C   s  d  } | j d ƒ } | r| j d ƒ r| j d d ƒ } t | ƒ d k ryP t j | d j ƒ  j d ƒ ƒ } t	 r‹ | j
 d ƒ } n  | j d d ƒ } WnJ t k
 rÄ } |  j d | ƒ | St j k
 rê } |  j d | ƒ | SXt | ƒ d k r| d	 } qqn  | S(
   Nt   HTTP_AUTHORIZATIONt   Basict    i   i   s   utf-8RJ   s   Couldn't get username: %si    (   Rw   Ro   R>   RO   RP   t   base64t	   b64decodet   stript   encodeR   t   decodet	   TypeErrorRa   t   binasciit   Error(   R8   R¯   R   t	   http_authR   t   exc(    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR¤   ƒ  s&    "("   RD   RE   R*   t   CRITICALt   ERRORt   WARNINGR   t   DEBUGRn   Rp   Ru   R)   Rx   Rz   R1   R³   R4   Rh   R]   R^   R_   R`   Ra   R…   R†   R9   Rj   R¥   RÂ   RÃ   RÇ   Rr   Ry   R¤   (    (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyR\   —   s<   



		
	"								'							#(   Râ   Rè   R¸   R*   R\   R+   t   emittedNoHandlerWarningt   logging.configR    R|   RM   RÛ   Rµ   t   gunicornR   t   gunicorn.sixR   R   R×   R3   Rc   RÏ   R   R   R1   R[   t   object(    (    (    sa   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/glogging.pyt   <module>   sr   

		,