o âÄd%ã@s†ddlmZddlZddlmZddlmZddlmZddl m Z m Z d d „Z ej ddfd d „Zd d„Zdd„Zdd„ZedƒZdS)é)Úabsolute_importNé)Ú_appengine_environ)ÚLocationParseError)Úsixé)ÚNoWayToWaitForSocketErrorÚ wait_for_readcCsHt|ddƒ}|dur dS|durdSzt|dd�WSty#YdSw)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úr/private/var/folders/v1/_jykv66s6qd26_69j1njbrl80000gr/T/pip-target-p1gutpg6/lib/python/urllib3/util/connection.pyÚis_connection_dropped s  ÿrc Cs(|\}}| d¡r| d¡}d}tƒ}z| d¡Wnty-t td|ƒd¡YSwt  |||tj ¡D]Q}|\} } } } } d}z't | | | ¡}t ||ƒ|tj urY|  |¡|r`| |¡| | ¡|WStjyˆ}z|}|dur~| ¡d}WYd}~q7d}~ww|dur�|‚t d¡‚)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%sD    ÿÿ      €ü r1cCs$|durdS|D]}|j|ŽqdS)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)rrrrlsrcCs`d}d}t ¡r dStjr(zt tj¡}| |df¡d}Wn ty'Ynw|r.| ¡|S)z4Returns True if the system can bind an IPv6 address.NFrT)rÚis_appengine_sandboxrÚhas_ipv6ÚAF_INET6rÚ Exceptionr")r&r r9rrrÚ _has_ipv6ws  ÿr<z::1)Ú __future__rrÚcontribrÚ exceptionsrÚpackagesrÚwaitrr rrr1rrr<r6rrrrÚs     ü?