ó
ÐH/\c           @@  sX  d  d l  m Z d d d d d g Z d d d	 d
 d d g Z e e 7Z d d d d g Z d d d d d d d d d d d d d d d d  d! d" d# g Z d$ d% d& d' d( d) d* d+ d, g	 Z e j e ƒ d  d- l Z d  d- l	 Z	 d  d. l
 m Z d  d/ l m Z m Z m Z d  d0 l m Z e	 j d1 k Z e	 j d2 k Z e r§d  d3 l m Z d  d4 l m Z d  d5 l m Z d  d6 l m Z d  d7 l m Z  d  d8 l! m" Z# e Z$ np d  d9 l m Z d  d: l m Z d  d; l m Z d  d< l m Z d  d= l m$ Z$ d  d> l m  Z  d  d? l% m# Z# y d  d@ l m& Z& Wn e' k
 rDdA Z& n Xe f Z( e rtd  dB l m) Z) e( e) f 7Z( n  d  d- l* Z* e* j+ Z, d  d- l+ Z- d- Z/ Z0 e e- e1 ƒ  dC e dD e2 ƒZ xR e- j3 D]G Z/ e4 e- e/ ƒ Z0 e5 e0 e e f ƒ rÇe0 e1 ƒ  e/ <e j6 e/ ƒ qÇqÇW[/ [0 e7 Z8 d  dE l9 m: Z: e: j; e8 ƒ e: j< Z= e: j> Z> e: j? Z? e: j@ Z@ dF eA f dG „  ƒ  YZB eB dH „ ZC dI „  ZD dJ „  ZE d  d  d  d  dK „ ZF e räeF jG ZH d  d  d  d  dL „ ZF eH eF _G [H dM „  ZI n  dN „  ZJ dO „  ZK dP dQ „ ZL e8 dR „ ZM e- jN e- jO dS „ ZP e- jQ f ZR e- jS rKeR e- jT f 7ZR n  dT „  ZU d- S(U   i    (   t   absolute_importt   create_connectiont   sockett
   SocketTypet   fromfdt
   socketpairt   getaddrinfot   gethostbynamet   gethostbyname_ext   gethostbyaddrt   getnameinfot   getfqdnt   cancel_waitt	   wait_readt
   wait_writet   wait_readwritet   errort   gaierrort   herrort   htonlt   htonst   ntohlt   ntohst	   inet_atont	   inet_ntoat	   inet_ptont	   inet_ntopt   timeoutt   gethostnamet   getprotobynamet   getservbynamet   getservbyportt   getdefaulttimeoutt   setdefaulttimeoutt   errorTabt   AddressFamilyt
   SocketKindt   CMSG_LENt
   CMSG_SPACEt   dupt   if_indextonamet   if_nameindext   if_nametoindext   sethostnameN(   t   get_hub_noargs(   t   string_typest   integer_typest   PY3(   t   copy_globalst   win32t   darwin(   t	   WSAEINVAL(   t   WSAEWOULDBLOCK(   t   WSAEINPROGRESS(   t   WSAEALREADY(   t
   WSAEISCONN(   t   formatError(   t   EINVAL(   t   EWOULDBLOCK(   t   EINPROGRESS(   t   EALREADY(   t   EAGAIN(   t   EISCONN(   t   strerror(   t   EBADFi	   (   t
   EPROTOTYPEt
   only_namest   ignore_missing_names(   t   _hub_primitivest   cancel_wait_exc           B@  s   e  Z d  „  Z RS(   c         C@  s   t  t |  ƒ j t d ƒ d  S(   Ns.   File descriptor was closed in another greenlet(   t   superRE   t   __init__R@   (   t   self(    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyRG      s    (   t   __name__t
   __module__RG   (    (    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyRE      s   c         C@  s   t  ƒ  j |  | ƒ d S(   s&   See :meth:`gevent.hub.Hub.cancel_wait`N(   t   get_hubR   (   t   watcherR   (    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyR   –   s    c         C@  s   t  ƒ  j j |  ƒ S(   s–   
    gethostbyname(host) -> address

    Return the IP address (a string of the form '255.255.255.255') for a host.

    .. seealso:: :doc:`/dns`
    (   RK   t   resolverR   (   t   hostname(    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyR   ›   s    c         C@  s   t  ƒ  j j |  ƒ S(   s<  
    gethostbyname_ex(host) -> (name, aliaslist, addresslist)

    Return the true host name, a list of aliases, and a list of IP addresses,
    for a host.  The host argument is a string giving a host name or IP number.
    Resolve host and port into list of address info entries.

    .. seealso:: :doc:`/dns`
    (   RK   RM   R   (   RN   (    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyR   ¦   s    
c         C@  s"   t  ƒ  j j |  | | | | | ƒ S(   sÝ  
    Resolve host and port into list of address info entries.

    Translate the host/port argument into a sequence of 5-tuples that contain
    all the necessary arguments for creating a socket connected to that service.
    host is a domain name, a string representation of an IPv4/v6 address or
    None. port is a string service name such as 'http', a numeric port number or
    None. By passing None as the value of host and port, you can pass NULL to
    the underlying C API.

    The family, type and proto arguments can be optionally specified in order to
    narrow the list of addresses returned. Passing zero as a value for each of
    these arguments selects the full range of results.

    .. seealso:: :doc:`/dns`
    (   RK   RM   R   (   t   hostt   portt   familyt   socktypet   protot   flags(    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyR   ³   s    c         C@  sq   t  ƒ  j j |  | | | | | ƒ } g  | D]< \ } } } }	 }
 t | t ƒ t | t ƒ | |	 |
 f ^ q+ } | S(   N(   RK   RM   R   t   _intenum_converterR#   R$   (   RO   RP   RQ   t   typeRS   RT   t   addrlistt   afRR   t	   canonnamet   sat   result(    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyR   Ï   s    $Fc         C@  s'   y | |  ƒ SWn t  k
 r" |  SXd  S(   N(   t
   ValueError(   t   valuet
   enum_klass(    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyRU   á   s    c         C@  s   t  ƒ  j j |  ƒ S(   s  
    gethostbyaddr(ip_address) -> (name, aliaslist, addresslist)

    Return the true host name, a list of aliases, and a list of IP addresses,
    for a host.  The host argument is a string giving a host name or IP number.

    .. seealso:: :doc:`/dns`
    (   RK   RM   R	   (   t
   ip_address(    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyR	   è   s    	c         C@  s   t  ƒ  j j |  | ƒ S(   s{   
    getnameinfo(sockaddr, flags) -> (host, port)

    Get host and port for a sockaddr.

    .. seealso:: :doc:`/dns`
    (   RK   RM   R
   (   t   sockaddrRT   (    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyR
   ô   s    t    c         C@  sµ   |  j  ƒ  }  |  s |  d k r+ t ƒ  }  n  y t |  ƒ \ } } } Wn t k
 rW nZ X| j d | ƒ xF | D]8 }  t |  t ƒ r— d |  k r§ Pq§ qo d |  k ro Pqo qo W| }  |  S(   s  Get fully qualified domain name from name.

    An empty argument is interpreted as meaning the local host.

    First the hostname returned by gethostbyaddr() is checked, then
    possibly existing aliases. In case no FQDN is available, hostname
    from gethostname() is returned.
    s   0.0.0.0i    t   .(   t   stripR   R	   R   t   insertt
   isinstancet   bytes(   t   nameRN   t   aliasest   _(    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyR   ÿ   s     
c   
      C@  s±   d } t  | ƒ } d } x’ | | k  r¬ | | }	 | d k rV | |  j |	 | ƒ 7} q | rw | d k rw | d ƒ ‚ q d } | |  j |	 | d | ƒ7} | t j ƒ  } q W| S(   sö  
    Send the complete contents of ``data_memory`` before returning.
    This is the core loop around :meth:`send`.

    :param timeleft: Either ``None`` if there is no timeout involved,
       or a float indicating the timeout to use.
    :param end: Either ``None`` if there is no timeout involved, or
       a float giving the absolute end time.
    :return: An updated value for ``timeleft`` (or None)
    :raises timeout: If ``timeleft`` was given and elapsed while
       sending this chunk.
    i    s	   timed outi   R   N(   t   lent   Nonet   sendt   time(
   R   t   data_memoryRT   t   timeleftt   endR   t	   data_sentt   len_data_memoryt   started_timert   chunk(    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyt   __send_chunk  s    
c         C@  sÍ   t  | ƒ } | s d St |  j | | ƒ d ƒ } d } d } d }	 |  j d k	 rn |  j }	 t j ƒ  |	 } n  xX | | k  rÈ t | | | ƒ }
 | | |
 !} t |  | | |	 | ƒ }	 | t  | ƒ 7} qq Wd S(   sw   
    Send the *data_memory* (which should be a memoryview)
    using the gevent *socket*, performing well on PyPy.
    i    i   Ni   (   Rj   t   maxt
   getsockoptRk   R   Rm   t   minRu   (   R   Rn   RT   t
   SOL_SOCKETt	   SO_SNDBUFRr   t
   chunk_sizeRq   Rp   Ro   t	   chunk_endRt   (    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyt   _sendall?  s    #	c         C@  s   |  j  t k s t | t ƒ r# | S| d  \ } } t | d  |  j  ƒ } | d d } t | ƒ d k r{ | d | f } n | d | | d | d f } | S(   Ni   i    iÿÿÿÿi   (   RQ   t   _RESOLVABLE_FAMILIESRe   t   tupleR   Rk   Rj   (   t   sockt   addressRO   RP   t   r(    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyt   _resolve_addr~  s    (V   t
   __future__R    t   _implementst   __dns__t   __extensions__t   __imports__t   __py3_imports__t   extendRm   t   syst   gevent._hub_localR,   RK   t   gevent._compatR-   R.   R/   t   gevent._utilR0   t   platformt
   is_windowst   is_macost   errnoR3   R9   R4   R:   R5   R;   R6   R<   R7   R>   t   gevent.win32utilR8   R?   R=   t   osR@   t   ImportErrort
   GSENDAGAINRA   t   _socketR   t   _realsockett
   __socket__Rk   t   _namet   _valuet   globalst   Truet   __all__t   getattrRe   t   appendR   t   _timeout_errort   geventRD   t   set_default_timeout_errort   wait_on_watchert   waitR   R   R   R   RE   R   R   R   R   t   __doc__t   dRU   R	   R
   R   Ru   Ry   Rz   R}   t   AF_INETR~   t   has_ipv6t   AF_INET6Rƒ   (    (    (    s3   lib/python2.7/site-packages/gevent/_socketcommon.pyt   <module>   sè   		
				
		
											$9	