ó
ĐH/\c        
   @   s  d  Z  d d l m Z d d l m Z d d l m Z e rO d d l m Z n d d l m	 Z d Z
 Z Z Z Z d e f d     YZ d	   Z e e e   d
 d d e d d l m Z e e e   d e j y e j Z Wn e k
 re   Z n Xe d d  Z e e _ d S(   s  Cooperative low-level networking interface.

This module provides socket operations and some related functions.
The API of the functions and classes matches the API of the corresponding
items in the standard :mod:`socket` module exactly, but the synchronous functions
in this module only block the current greenlet and let the others run.

For convenience, exceptions (like :class:`error <socket.error>` and :class:`timeout <socket.timeout>`)
as well as the constants from the :mod:`socket` module are imported into this module.
i˙˙˙˙(   t   PY3(   t	   exc_clear(   t   copy_globals(   t   _socket3(   t   _socket2t   errorc           B   s   e  Z d  Z RS(   N(   t   __name__t
   __module__t   Nonet   errno(    (    (    s,   lib/python2.7/site-packages/gevent/socket.pyR      s   c          G   s   t     d  S(   N(   t   NotImplementedError(   t   args(    (    s,   lib/python2.7/site-packages/gevent/socket.pyt   getfqdn#   s    t   dunder_names_to_keept   __implements__t   __dns__t   __all__t   __extensions__t   __imports__t
   __socket__t   cleanup_globs(   t   _socketcommont
   only_namesc         C   sU  |  \ } } t  t | | d t   } | s< t d   n  x| D]
} | \ } } }	 }
 } d } yU t | | |	  } | t k	 r | j |  n  | rŤ | j |  n  | j	 |  Wn t k
 r| d k	 râ | j
   n  d } | | d k rţ   n  t   qC t k
 r:| d k	 r.| j
   n  d }   qC Xz | SWd d } XqC Wd S(   sĐ  
    create_connection(address, timeout=None, source_address=None) -> socket

    Connect to *address* and return the :class:`gevent.socket.socket`
    object.

    Convenience function. Connect to *address* (a 2-tuple ``(host,
    port)``) and return the socket object. Passing the optional
    *timeout* parameter will set the timeout on the socket instance
    before attempting to connect. If no *timeout* is supplied, the
    global default timeout setting returned by
    :func:`getdefaulttimeout` is used. If *source_address* is set it
    must be a tuple of (host, port) for the socket to bind as a source
    address before making the connection. A host of '' or port 0 tells
    the OS to use the default.
    i    s!   getaddrinfo returns an empty listi˙˙˙˙N(   t   listt   getaddrinfot   SOCK_STREAMR   R   t   sockett   _GLOBAL_DEFAULT_TIMEOUTt
   settimeoutt   bindt   connectt   closeR   t   BaseException(   t   addresst   timeoutt   source_addresst   hostt   portt   addrst   rest   aft   socktypet   protot   _t   sat   sock(    (    s,   lib/python2.7/site-packages/gevent/socket.pyt   create_connection>   s:    
N(    (   R   R   R   R   R   R   (   t   __doc__t   gevent._compatR    R   t   gevent._utilR   t   geventR   t   _sourceR   R   R   R   R   R   t	   ExceptionR   R   t   globalst   FalseR   R   R   t   AttributeErrort   objectR   R.   (    (    (    s,   lib/python2.7/site-packages/gevent/socket.pyt   <module>   s,   	 

C