3

Z'íc%ã@s†ddlmZddlZddlmZddlmZddlmZddl	m
Z
mZd	d
„Zej
ddfdd„Zd
d„Zdd„Zdd„ZedƒZdS)é)Úabsolute_importNé)Ú_appengine_environ)ÚLocationParseError)Úsixé)ÚNoWayToWaitForSocketErrorÚ
wait_for_readcCsJt|ddƒ}|dkrdS|dkr$dSyt|ddStk
rDdSXdS)a$
    Returns True if the connection is dropped and should be closed.

    :param conn:
        :class:`http.client.HTTPConnection` object.

    Note: For platforms like AppEngine, this will always return ``False`` to
    let the platform handle connection recycling transparently for us.
    ÚsockFNTg)Útimeout)Úgetattrr	r)Úconnr
©rú:/tmp/pip-build-gk9425m9/urllib3/urllib3/util/connection.pyÚis_connection_droppeds
rcCs.|\}}|jdƒr|jdƒ}d}tƒ}y|jdƒWn$tk
rXtjtd|ƒdƒSXx¶tj	|||tj
ƒD] }|\}	}
}}}
d}yHtj|	|
|ƒ}t||ƒ|tjk	r²|j
|ƒ|rÀ|j|ƒ|j|
ƒ|Stjk
r}z |}|dk	rü|jƒd}WYdd}~XqnXqnW|dk	r |‚tjdƒ‚dS)akConnect to *address* and return the 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:`socket.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.
    An host of '' or port 0 tells the OS to use the default.
    ú[z[]NÚidnaz'%s', label empty or too longz!getaddrinfo returns an empty list)Ú
startswithÚstripÚallowed_gai_familyÚencodeÚUnicodeErrorrÚ
raise_fromrÚsocketÚgetaddrinfoÚSOCK_STREAMÚ_set_socket_optionsÚ_GLOBAL_DEFAULT_TIMEOUTÚ
settimeoutÚbindÚconnectÚerrorÚclose)ÚaddressrÚsource_addressÚsocket_optionsÚhostÚportÚerrÚfamilyÚresÚafÚsocktypeÚprotoÚ	canonnameÚsar
ÚerrrÚcreate_connection%s<








r1cCs(|dkrdSx|D]}|j|ŽqWdS)N)Ú
setsockopt)r
ÚoptionsÚoptrrrrds
rcCstj}trtj}|S)z³This function is designed to work in the context of
    getaddrinfo, where family=socket.AF_UNSPEC is the default and
    will perform a DNS search for both IPv6 and IPv4 records.)rÚAF_INETÚHAS_IPV6Ú	AF_UNSPEC)r)rrrrlsrcCsbd}d}tjƒrdStjrRy"tjtjƒ}|j|dfƒd}Wntk
rPYnX|r^|jƒ|S)z4Returns True if the system can bind an IPv6 address.NFrT)rZis_appengine_sandboxrÚhas_ipv6ÚAF_INET6rÚ	Exceptionr")r&r
r8rrrÚ	_has_ipv6wsr;z::1)Ú
__future__rrÚcontribrÚ
exceptionsrÚpackagesrÚwaitrr	rrr1rrr;r6rrrrÚ<module>s;