�
�gn � � � d dl mZ d dlZd dlZddlmZ ddlmZmZ ej ej eeej ee
f f Zej rddlmZ dd�Zeddf dd �Z dd
�Zdd�Zdd�Z ed
� Zy)� )�annotationsN� )�LocationParseError� )�_DEFAULT_TIMEOUT�
_TYPE_TIMEOUT)�BaseHTTPConnectionc � � | j S )z�
Returns True if the connection is dropped and should be closed.
:param conn: :class:`urllib3.connection.HTTPConnection` object.
)�is_connected)�conns �9/usr/lib/python3/dist-packages/urllib3/util/connection.py�is_connection_droppedr s � �
� � � � � c �~ � | \ }}|j d� r|j d� }d}t � } |j d� t
j |||t j � D ]r }|\ } }
}}}
d} t
j | |
|� }t ||� |t ur|j |� |r|j |� |j |
� d}|c S |� |�t d� �# t $ r t d|� d�� d�w xY w# t $ r}|}|�|j � Y d}~��d}~ww xY w# d}w xY w)ak Connect 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�idna�'z', label empty or too longz!getaddrinfo returns an empty list)�
startswith�strip�allowed_gai_family�encode�UnicodeErrorr �socket�getaddrinfo�SOCK_STREAM�_set_socket_optionsr �
settimeout�bind�connect�OSError�close)�address�timeout�source_address�socket_options�host�port�err�family�res�af�socktype�proto� canonname�sa�sock�_s r
�create_connectionr2 sZ � �$ �J�D�$����s���z�z�$���
�C�
�
!�F�Q����F�� �!�!�$��f�f�6H�6H�I� ��-0�*��H�e�Y���� ��=�=��X�u�5�D�
��n�5��.�.�����(��� � �.�)��L�L����C��K�!�. �� ��I�
�9�:�:��C � Q� �1�T�F�*D�!E�F�D�P�Q��* � ��C����
�
���� �� �C�s0 �C1 �:A#D�$D8 �1D� D5�D0�0D5�8D<c �6 � |�y |D ] } | j |� � y )N)�
setsockopt)r0 �options�opts r
r r ] s) � � ���� ��������r c �R � t j } t rt j } | 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) s r
r r g s � �
�^�^�F���!�!���Mr c �� � d}d}t j r9 t j t j � }|j | df� d}|r|j � |S # t $ r Y �w xY w)z4Returns True if the system can bind an IPv6 address.NFr T)r �has_ipv6�AF_INET6r � Exceptionr! )r& |