
#A]dc           @  s$  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z d  d l Z d  d l Z d  d l Z d  d l 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 d  d l m Z d  d l m Z e e d d  Z e d	 j    Z  y d  d
 l! m! Z! d   Z" Wn e# k
 ryd   Z" n Xy d  d l$ m% Z% Wn& e# k
 rd   Z& d d  Z% n Xd d d  Z( d   Z) e* d  Z+ d   Z, e j- j. d  re* d  Z/ d   Z0 n	 e j1 Z0 d   Z1 d   Z2 d d  Z3 d   Z4 d   Z5 d   Z6 y d  d  l m7 Z7 Wn e# k
 rd!   Z7 n Xd"   Z8 e* d#  Z9 e* d$  Z: d%   Z; d&   Z< d'   Z= d d(  Z> d)   Z? e* d*  Z@ d+   ZA d,   ZB d- d.  ZC d/   ZD d0   ZE d1   ZF d2   ZG d S(3   i(   t   print_functionN(   t   _compat(   t   AppImportError(   t	   text_type(   t   SUPPORTED_WORKERSt   devnulls	   /dev/nulls   
    connection keep-alive proxy-authenticate proxy-authorization
    te trailers transfer-encoding upgrade
    server date
    (   t   setproctitlec         C  s   t  d |   d  S(   Ns   gunicorn: %s(   R   (   t   title(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   _setproctitle2   s    c         C  s   d  S(   N(    (   R   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyR   5   s    (   t   import_modulec         C  s   t  | d  s t d   n  t |  } xY t | d d  D]E } y | j d d |  } Wq= t k
 r d } t |   q= Xq= Wd | |  |  f S(	   s6   Return the absolute name of the module to be imported.t   rindexs   'package' not set to a stringi   it   .i    s2   attempted relative import beyond top-level packages   %s.%s(   t   hasattrt
   ValueErrort   lent   rangeR
   (   t   namet   packaget   levelt   dott   _t   msg(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   _resolve_name<   s    c         C  s   |  j  d  rn | s$ t d   n  d } x( |  D]  } | d k rG Pn  | d 7} q1 Wt |  | | |  }  n  t |   t j |  S(   s   Import a module.

The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.

R   s/   relative imports require the 'package' argumenti    i   (   t
   startswitht	   TypeErrorR   t
   __import__t   syst   modules(   R   R   R   t	   character(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyR	   I   s    
s    gunicorn.workers.sync.SyncWorkers   gunicorn.workersc         C  s  t  j |   r |  S|  j d  r |  j d  d } y | j d d  \ } } Wn t k
 rp | } | } n Xy t j | | |  SWqt j	   } d } t
 | |  | f   qXn |  j d  } t |  d k rvx t rr|  j d  r|  d }  n  |  t k r&t |  j d  } Pn  y t j d | |   SWq t j	   } d } t
 | |  | f   q Xq Wn  | j d  }	 y t d j |   }
 Wn/ t j	   } d } t
 | |  | f   n Xt |
 |	  Sd  S(   Ns   egg:i   t   #s)   class uri %r invalid or not found: 

[%s]R   t   gunicorni(   t   inspectt   isclassR   t   splitt   rsplitR   t   pkg_resourcest   load_entry_pointt	   tracebackt
   format_exct   RuntimeErrorR   t   TrueR   t   popR	   t   joint   getattr(   t   urit   defaultt   sectiont	   entry_strt   distR   t   excR   t
   componentst   klasst   mod(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt
   load_class^   sL    
		!c         C  s   t  j |   j S(   s    get the username for a user id(   t   pwdt   getpwuidt   pw_name(   t   uid(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   get_username   s    c         C  s   | r |  r9 y t  |   } Wq9 t k
 r5 t } q9 Xn  t |  d @} | rb t j | |  q | t j   k r t j |  q n  |  r t j |   n  d S(   s)    set user and group of workers processes iN(	   R:   t   KeyErrort   Falset   abst   ost
   initgroupst   getgidt   setgidt   setuid(   R9   t   gidR?   t   username(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   set_owner_process   s    c         C  s'   t  |  d @} t j |  | |  d  S(   Ni(   R=   R>   t   chown(   t   pathR9   RC   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyRF      s    t   winc         C  s   |  |  | r | } n$ t  j j |  \ } } | p: d } d } xS | d k  r t  j |  } | rn | n	 | | k r~ d  St j |  | d 9} qF Wt j d | t d d d  S(   NR   gMbP?g      ?i   s)   tests may fail, delete still pending for t
   stackleveli   (	   R>   RG   R!   t   listdirt   timet   sleept   warningst   warnt   RuntimeWarning(   t   funct   pathnamet   waitallt   dirnameR   t   timeoutt   L(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   _waitfor   s    
	c         C  s   t  t j |   d  S(   N(   RV   R>   t   unlink(   t   filename(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   _unlink   s    c         C  sI   y t  |   Wn4 t k
 rD } | j t j t j f k rE   qE n Xd  S(   N(   RY   t   OSErrort   errnot   ENOENTt   ENOTDIR(   RX   t   error(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyRW      s
    c         C  sD   y t  j t  j |   Wn& t  j k
 r. t St k
 r? t SXt S(   N(   t   sockett	   inet_ptont   AF_INET6R^   R<   R   R(   (   t   addr(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   is_ipv6   s    i@  c         C  s?  t  j d |   r& t  j d |   d S|  j d  rK |  j d  d }  n  d |  k r d |  k r |  j d  d d j   } nI d |  k r |  j d  d j   } n! |  d	 k r d
 } n |  j   } |  j d  d }  d |  k r/|  j d d  d } | j   s t d |   n  t |  } n | } | | f S(   Ns
   unix:(//)?is   tcp://i   t   [t   ]i    t   :t    s   0.0.0.0s   %r is not a valid port number.(   t   ret   matchR!   R   t   lowert   isdigitR'   t   int(   t   netloct   default_portt   hostt   port(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   parse_address   s&     	c         C  s<   t  j  |  t  j  } | t  j O} t  j  |  t  j |  d  S(   N(   t   fcntlt   F_GETFDt
   FD_CLOEXECt   F_SETFD(   t   fdt   flags(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   close_on_exec  s    c         C  s6   t  j  |  t  j  t j B} t  j  |  t  j |  d  S(   N(   Rr   t   F_GETFLR>   t
   O_NONBLOCKt   F_SETFL(   Rv   Rw   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   set_non_blocking  s    c         C  s)   y |  j    Wn t j k
 r$ n Xd  S(   N(   t   closeR_   R^   (   t   sock(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyR}     s    (   t
   closerangec         C  sC   x< t  |  |  D]+ } y t j |  Wq t k
 r: q Xq Wd  S(   N(   R   R>   R}   RZ   (   t   fd_lowt   fd_highRv   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyR     s
    c         C  sc   t  | t  r! | j d  } n  d t |  } d j | j d  | d g  } |  j |  d  S(   Ns   utf-8s   %X
Rg   s   
(   t
   isinstanceR   t   encodeR   R*   t   sendall(   R~   t   datat
   chunk_sizet   chunk(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   write_chunk%  s
    !c         C  s$   | r t  |  |  S|  j |  d  S(   N(   R   R   (   R~   R   t   chunked(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   write-  s    c         C  sa   |  j    } | d k rM z! |  j d  t |  | |  SWd  |  j d  Xn t |  | |  Sd  S(   Ng        i    i   (   t
   gettimeoutt   setblockingR   (   R~   R   R   RT   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   write_nonblock3  s    c         C  so   t  j d  i | d 6t j |  d 6} t  j d  t |  | t |  | f } t |  | j d   d  S(   Ns       <html>
      <head>
        <title>%(reason)s</title>
      </head>
      <body>
        <h1><p>%(reason)s</p></h1>
        %(mesg)s
      </body>
    </html>
    t   reasont   mesgsl       HTTP/1.1 %s %s
    Connection: close
    Content-Type: text/html
    Content-Length: %d
    
    %st   latin1(   t   textwrapt   dedentR   t   html_escapet   strR   R   R   (   R~   t
   status_intR   R   t   htmlt   http(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   write_error?  s
    
$%c         C  s}  |  j  d d  } t |  d k r4 |  d }  } n | d | d }  } y t |   Wnd t k
 r |  j d  r t j j |   r d } t | |  j d d  d | f   q   n Xt	 j
 |  } t j j t j k } y t | t |   } WnC t k
 r>| r%t j t	 j     n  t d | |  f   n X| d  k r^t d	 |   n  t |  syt d
   n  | S(   NRf   i   t   applicationi    s   .pys1   Failed to find application, did you mean '%s:%s'?R   s*   Failed to find application object %r in %rs%   Failed to find application object: %rs$   Application object must be callable.(   R!   R   R   t   ImportErrort   endswithR>   RG   t   existsR"   R   R   t   loggingt   rootR   t   DEBUGt   evalt   varst	   NameErrorR%   t   print_exceptiont   exc_infoR   t   Nonet   callable(   t   modulet   partst   objR   R4   t   is_debugt   app(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt
   import_appV  s0    !)c          C  s   yo t  j t  j d  }  t  j t  j    } |  j | j k rb |  j | j k rb t  j d } n t  j   } Wn t  j   } n X| S(   Nt   PWD(   R>   t   statt   environt   getcwdt   st_inot   st_dev(   t   at   bt   cwd(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyR   x  s    $c         C  s=   |  d k r t j   }  n  t j j |  d t d t } | S(   s@   Return the current date and time formatted for a message header.t	   localtimet   usegmtN(   R   RK   t   emailt   utilst
   formatdateR<   R(   (   t	   timestampt   s(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt	   http_date  s    c         C  s   |  j    j   t k S(   N(   Rj   t   stript   hop_headers(   t   header(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt
   is_hoppish  s    c           s?  d t  j k r;t  j   r+ t  j d  n  t  j   t  j   rQ t  j d  n  t  j d  |  s t d d  t  j t t  j	      d k r t  j
   d  n  t  j
   d  t  j
   d  q;t  j t t  j	      d k r	t  j d  t  j
   d  n    f d   } | t j d  | t j d  n  d S(	   s~       Standard daemonization of a process.
    http://www.svbug.com/documentation/comp.unix.programmer-FAQ/faq_2.html#SEC16
    t   GUNICORN_FDi    i   i   i   i   c           s`   yH |  j    } | | k rG |  j   rG t j |  t j   |  n  Wn t k
 r[ n Xd  S(   N(   t   filenot   isattyR>   R}   t   dup2t   AttributeError(   t   streamt	   fd_expectRv   (   t   fd_null(    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   redirect  s    N(   R>   R   t   forkt   _exitt   setsidt   umaskR   t   opent   REDIRECT_TOt   O_RDWRR   R}   R   t   stdoutt   stderr(   t   enable_stdio_inheritanceR   (    (   R   s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt	   daemonize  s*    
	c           C  sU   y t  j t j d   Wn4 t k
 rP t  j d t j   t j   f  n Xd  S(   Ni@   s   %s.%s(   t   randomt   seedR>   t   urandomt   NotImplementedErrorRK   t   getpid(    (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyR     s    c         C  sM   y t  |  d  } Wn) t k
 r> } t d |  | f   n X| j   d  S(   NR   s   Error: '%s' isn't writable [%r](   R   t   IOErrorR'   R}   (   RG   t   ft   e(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   check_is_writeable  s
    t   utf8c         C  sB   t  |  t  r |  St  |  t  s5 t d |    n  |  j |  S(   s+   Converts a string argument to a byte strings   %r is not a string(   R   t   bytesR   R   R   (   t   valuet   encoding(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   to_bytestring  s
    c         C  sF   t  |  d  s t Sy |  j   Wn t t t j f k
 rA t SXt S(   NR   (   R   R<   R   R   R   t   iot   UnsupportedOperationR(   (   R   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt
   has_fileno  s    c         C  s   t  d d t j |  j   } xJ t |  D]< \ } } | d k rQ d | } n  t  d | d t j q, Wt  d d t j t j j   d  S(   Ns   !!!t   filei    s   WARNING: %ss   !!! %ss   !!!
(   t   printR   R   t
   splitlinest	   enumeratet   flush(   R   t   linest   it   line(    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyRN   
  s    c           s   t         f d   } | S(   Nc           s,   | d d d t  t     f g    g S(   Ns   500 Internal Server Errors   Content-Types
   text/plains   Content-Length(   s   Content-Types
   text/plain(   R   R   (   R   t   start_response(   R   (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyR     s    (   R   (   R   R   (    (   R   s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   make_fail_app  s    c         C  sF   |  j  d  r9 t j d |   } | j d | j d  St j |   S(   Ns   //R   RG   i   (   R   R   t   urlsplitt   _replaceRG   (   R,   R   (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   split_request_uri$  s    (H   t
   __future__R    t   email.utilsR   Rr   R   R>   R#   R6   R   R_   R   R   RK   R%   R   R[   RM   R   Rh   R   R   t   gunicorn.errorsR   t   gunicorn.sixR   t   gunicorn.workersR   R+   R   t   setR!   R   R   R   R   t	   importlibR	   R   R   R5   R:   R<   RE   RF   t   platformR   RV   RY   RW   Rc   Rq   Rx   R|   R}   R   R   R   R   R   R   R   R   R   R   R   R   R   R   RN   R   R   (    (    (    s[   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/gunicorn/util.pyt   <module>   s   
	0		!				
							"		S						