ó
sÁìVc           @   sÜ   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 Z
 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d S(   iÿÿÿÿN(   t   util(   t   string_typesi   t
   BaseSocketc           B   sD   e  Z d d  „ Z d „  Z d „  Z e d „ Z d „  Z d „  Z	 RS(   c         C   s   | |  _  | |  _ | |  _ | d  k rB t j |  j t j ƒ } n t j | |  j t j ƒ } |  j | d | d  k	 ƒ|  _	 d  S(   Nt   bound(
   t   logt   conft   cfg_addrt   Nonet   sockett   FAMILYt   SOCK_STREAMt   fromfdt   set_optionst   sock(   t   selft   addressR   R   t   fdR   (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyt   __init__   s    			c         C   s   d |  j  j ƒ  S(   Ns   <socket %d>(   R   t   fileno(   R   t   name(    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyt   __str__!   s    c         C   s   t  |  j | ƒ S(   N(   t   getattrR   (   R   R   (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyt   __getattr__$   s    c         C   sr   | j  t j t j d ƒ | s/ |  j | ƒ n  | j d ƒ t | d ƒ r[ | j t ƒ n  | j	 |  j
 j ƒ | S(   Ni   i    t   set_inheritable(   t
   setsockoptR   t
   SOL_SOCKETt   SO_REUSEADDRt   bindt   setblockingt   hasattrR   t   Truet   listenR   t   backlog(   R   R   R   (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR   '   s    c         C   s   | j  |  j ƒ d  S(   N(   R   R   (   R   R   (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR   4   s    c         C   sM   y |  j  j ƒ  Wn/ t j k
 rB } |  j j d t | ƒ ƒ n X|  `  d  S(   Ns   Error while closing socket %s(   R   t   closeR   t   errorR   t   infot   str(   R   t   e(    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR!   7   s
    N(
   t   __name__t
   __module__R   R   R   R   t   FalseR   R   R!   (    (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR      s   			t	   TCPSocketc           B   s&   e  Z e j Z d  „  Z e d „ Z RS(   c         C   sC   |  j  j r d } n d } |  j j ƒ  } d | | d | d f S(   Nt   httpst   https
   %s://%s:%di    i   (   R   t   is_sslR   t   getsockname(   R   t   schemet   addr(    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR   C   s
    	c         C   s5   | j  t j t j d ƒ t t |  ƒ j | d | ƒS(   Ni   R   (   R   R   t   IPPROTO_TCPt   TCP_NODELAYt   superR)   R   (   R   R   R   (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR   L   s    (   R&   R'   R   t   AF_INETR	   R   R(   R   (    (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR)   ?   s   			t
   TCP6Socketc           B   s   e  Z e j Z d  „  Z RS(   c         C   s)   |  j  j ƒ  \ } } } } d | | f S(   Ns   http://[%s]:%d(   R   R-   (   R   t   hostt   portt   flt   sc(    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR   U   s    (   R&   R'   R   t   AF_INET6R	   R   (    (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR4   Q   s   	t
   UnixSocketc           B   s8   e  Z e j Z d d  „ Z d „  Z d „  Z d „  Z	 RS(   c         C   s»   | d  k r† y t j | ƒ } Wn/ t k
 rP } | j d t j k rƒ ‚  qƒ q† Xt j | j ƒ rs t j	 | ƒ q† t
 d | ƒ ‚ n  t j ƒ  |  _ t t |  ƒ j | | | d | ƒd  S(   Ni    s   %r is not a socketR   (   R   t   ost   statt   OSErrort   argst   errnot   ENOENTt   S_ISSOCKt   st_modet   removet
   ValueErrort   getpidt   parentR2   R:   R   (   R   R/   R   R   R   t   stR%   (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR   ^   s    
c         C   s   d |  j  S(   Ns   unix:%s(   R   (   R   (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR   m   s    c         C   sX   t  j |  j j ƒ } | j |  j ƒ t j |  j |  j j |  j j ƒ t  j | ƒ d  S(   N(	   R;   t   umaskR   R   R   R    t   chownt   uidt   gid(   R   R   t	   old_umask(    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR   p   s    "c         C   s?   t  t |  ƒ j ƒ  |  j t j ƒ  k r; t j |  j ƒ n  d  S(   N(   R2   R:   R!   RF   R;   RE   t   unlinkR   (   R   (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR!   w   s    N(
   R&   R'   R   t   AF_UNIXR	   R   R   R   R   R!   (    (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyR:   Z   s
   			c         C   s`   t  |  t ƒ r4 t j |  d ƒ r+ t } q\ t } n( t  |  t ƒ rL t } n t d |  ƒ ‚ | S(   Ni    s    Unable to create socket from: %r(	   t
   isinstancet   tupleR    t   is_ipv6R4   R)   R   R:   t	   TypeError(   R/   t	   sock_type(    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyt
   _sock_type}   s    			c         C   sQ  g  } d t  j k rØt t  j j d ƒ ƒ t  j ƒ  k rØxIt t t  j j d d ƒ ƒ ƒ D]&} | t } yÿ t j | t j	 t j
 ƒ } | j ƒ  } t | t ƒ rÕ | j d ƒ rÕ | j t | |  | d | ƒƒ n” t | ƒ d k rd | d k r| j t d | |  | d | ƒƒ nL t | ƒ d	 k rid
 | d k ri| j t d | d  |  | d | ƒƒ n  Wq[ t j k
 r€q[ Xq[ Wt  j d =t  j d =| rØ| j d d j g  | D] } t | ƒ ^ qµƒ ƒ | Sn  |  j } |  j rt  j j |  j ƒ rt d |  j ƒ ‚ n  |  j rKt  j j |  j ƒ rKt d |  j ƒ ‚ n  d t  j k rt  j j d ƒ j d ƒ }	 x¡ t |	 ƒ D]“ \ } } t | ƒ } | | }
 t  |
 ƒ } y# | j | |
 |  | d | ƒƒ Wq‚t j k
 r} | j! d t" j# k r| j d ƒ q‚  q‚Xq‚W| Sx-| D]%}
 t  |
 ƒ } d } xË t d ƒ D]½ } y | |
 |  | ƒ } Wn t j k
 r} | j! d t" j% k r©| j d t |
 ƒ ƒ n  | j! d t" j& k rØ| j d t |
 ƒ ƒ n  | d k  r| j d ƒ t' j( d ƒ qqIXPqIW| d k r<| j d t |
 ƒ ƒ t) j* d ƒ n  | j | ƒ q$W| S(   sÂ   
    Create a new socket for the given address. If the
    address is a tuple, a TCP socket is created. If it
    is a string, a Unix socket is created. Otherwise
    a TypeError is raised.
    t
   LISTEN_PIDt
   LISTEN_FDSi    t   /R   i   t   .s   %s:%si   t   :s   [%s]:%ss   Socket activation sockets: %st   ,s   certfile "%s" does not exists   keyfile "%s" does not existt   GUNICORN_FDs+   GUNICORN_FD should refer to an open socket.i   s   Connection in use: %ss   Invalid address: %ss   Retrying in 1 second.i   s   Can't connect to %sN(+   R;   t   environt   intt   getRE   t   ranget   SD_LISTEN_FDS_STARTR   R   RN   R
   R-   RO   R$   t
   startswitht   appendR:   t   lenR)   R4   R"   t   debugt   joinR   t   certfilet   patht   existsRD   t   keyfilet   popt   splitt	   enumerateRT   R>   R?   t   ENOTCONNR   t
   EADDRINUSEt   EADDRNOTAVAILt   timet   sleept   syst   exit(   R   R   t	   listenerst   iR   R   t   socknamet   lt   laddrt   fdsR/   RS   R%   (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyt   create_socketsŠ   sz    $(
"""	)	
#(   R?   R;   R   R<   Rr   Rp   t   gunicornR    t   gunicorn.sixR   R`   t   objectR   R)   R4   R:   RT   Rz   (    (    (    s]   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/gunicorn-19.4.5-py2.7.egg/gunicorn/sock.pyt   <module>   s   ,	#	