B -<`.ã@s†ddlmZddlZddlmZddlmZddlmZddl m Z m Z d d „Z ej ddfd d „Zd d„Zdd„Zdd„ZedƒZdS)é)Úabsolute_importN)ÚLocationParseErroré)Ú_appengine_environ)Ú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-target-7cdyy134/lib/python/urllib3/util/connection.pyÚis_connection_dropped s  rc Cs.|\}}| d¡r| d¡}d}tƒ}y| d¡Wn$tk rXt td|ƒd¡SXx¶t  |||tj ¡D] }|\} } } } } d}yHt | | | ¡}t ||ƒ|tj k r²|  |¡|rÀ| |¡| | ¡|Stjk �r }z|}|dk �rü| ¡d}Wdd}~XYqnXqnW|dk �r |‚t d¡‚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Úoptrrrres 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)rrrrmsrcCsbd}d}t ¡rdStjrRy"t tj¡}| |df¡d}Wntk rPYnX|r^| ¡|S)z6 Returns True if the system can bind an IPv6 address. NFrT)rÚis_appengine_sandboxrÚhas_ipv6ÚAF_INET6rÚ Exceptionr")r&r r9rrrÚ _has_ipv6xs r<z::1)Ú __future__rrZurllib3.exceptionsrÚcontribrÚpackagesrÚwaitrr rrr1rrr<r6rrrrÚs     ;