%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/module_utils/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/module_utils/__pycache__/urls.cpython-39.pyc

a

�)g
M�@s�dZddlmZmZmZeZddlZddlZddl	Z
ddlZ
ddlZ
ddl
Z
ddlZ
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZzddlZdZdZWn"e y�dZe�!�Ze"Z#Yn0ej#Z#zddl$Z
Wne �y&ddl%Z
Yn0zddl&Z&Wn e �yTddl'm(Z&Yn0ddl)m*m+m,Z-ddl.m*m/m0m1Z2ddl3m*m/m0m4m5Z6ddl7m8Z8m9Z9ddl:m;Z;m<Z<m=Z=dd	l>m?Z?dd
l@mAZAmBZBddlCmDZDmEZEmFZFz ddlGmHZIddlGmJZJmKZKWn,e �yPddlLZIddlLmJZJmKZKYn0eIjMjNeIjM_Ozdd
lPmQZQmRZRmSZSdZTWneU�y�dZTYn0zddlVZVdZWWneU�y�dZWYn0zddlVmXZXmYZYdZZWne �y�dZZYn0dZ[dZ\eZ�s�z:zddl]m^Z^Wn eU�y0ddl_m^Z^Yn0dZ[WndeU�y�z:zddl]m`Z`Wn eU�yzddl_m`Z`Yn0dZ\WneU�y�Yn0Yn0eW�r�eVjaZbeZ�s4eW�r4zddlcZcddldZcWne �y�YnV0ecje�fd�Zgec�heg�ZidD]6ZjzeiejeVjkZbW�q2Wnel�y,Yn0�q�[iddd�Zmen�ZodZpzddlVmqZqmrZrWnBe �y�zddlsmqZqmrZrWne �y�dZpYn0Yn0dZtz4ddlumvZvddlwmxZxddlymzZzddl{m|Z|Wne �y�dZtYn0zddl}Z}dZ~Wne �ydZ~Yn0dZzddl�Z�Gdd�deK�Z�Wn e �y\e�!�ZdZ�Yn0ep�s�zddl�m�Z�e�ZrWn$e �y�Gdd�de��ZrYn0d d!�Z�d"d#�Z�d$d%�Z�d&d'�ZqdZpd(Z�ej�d)ej�ej�Bd*�Z�Gd+d,�d,eU�Z�Gd-d.�d.e��Z�Gd/d0�d0e��Z�Gd1d2�d2e��Z�Gd3d4�d4eU�Z�dZ�dZ�dZ�dZ�e�e&d5��r�e�eId6��r�Gd7d8�d8e&j��Z�Gd9d:�d:eIj��Z�Gd;d<�d<eIj��Z�ed=d>��Z�Gd?d@�d@e&j��Z�GdAdB�dBe&j��Z�GdCdD�dDeIj��Z�GdEdF�dFe��Z�dGdH�Z�dIdJ�Z�dKdL�Z�dMdN�Z�GdOdP�dPe#�Z�GdQdR�dReIj��Z�ddSdT�Z�d�dUdV�Z�dWdX�Z�d�dYdZ�Z�d�d[d\�Z�Gd]d^�d^eIjK�Z�d�d_d`�Z�d�dadb�Z�dcdd�Z�d�dfdg�Z�Gdhdi�di�Z�d�dldm�Z�dndo�Z�dpdq�Z�drds�Z�d�dtdu�Z�dvdw�Z�d�d{d|�Z�d�d}d~�Z�dS)�a�
The **urls** utils module offers a replacement for the urllib2 python library.

urllib2 is the python stdlib way to retrieve files from the Internet but it
lacks some security features (around verifying SSL certificates) that users
should care about in most situations. Using the functions in this module corrects
deficiencies in the urllib2 module wherever possible.

There are also third-party libraries (for instance, requests) which can be used
to replace urllib2 with a more secure library. However, all third party libraries
require that the library be installed on the managed machine. That is an extra step
for users making use of a module. If possible, avoid third party libraries by using
this code instead.
�)�absolute_import�division�print_functionN)�contextmanagerTF)�Mapping�is_sequence)�PY2�PY3�string_types)�	cStringIO)�get_distribution�missing_required_lib)�to_bytes�	to_native�to_text)�AbstractHTTPHandler�BaseHandler)�urlparse�
urlunparse�unquote)�create_default_context�
SSLContext)�PyOpenSSLContext)�ssl_wrap_socket�ssl)ZTLSv1_1_methodZTLSv1_2_methodzbackports.ssl_match_hostnamez3.7.0.1)Z	pypi_name�version)�match_hostname�CertificateError)�x509)�default_backend)�hashes)�UnsupportedAlgorithmc@s<eZdZdZe�dej�ZdZddd�Z	dd�Z
d	d
�ZdS)�HTTPGSSAPIAuthHandlerz@ Handles Negotiate/Kerberos support through the gssapi library. z)(?:.*)\s*(Negotiate|Kerberos)\s*([^,]*),?i�NcCs||_||_d|_dS�N)�username�password�_context)�selfr$r%�r(�=/usr/lib/python3.9/site-packages/ansible/module_utils/urls.py�__init__�szHTTPGSSAPIAuthHandler.__init__cCs6|j�|�dd��}|r2|�d�t�|�d��fSdS)Nzwww-authenticate���)�AUTH_HEADER_PATTERN�search�get�group�base64Z	b64decode)r'�headersZ
auth_matchr(r(r)�get_auth_value�sz$HTTPGSSAPIAuthHandler.get_auth_valuecCs�|jr
dStt|����}|�|�}|s,dS|\}}	d}
|jrRtj|jtjj	d�}
|
r�|j
r�ttjd�spt
d��t|j
dd�}tjj|
|dd�j}ntj|
dd�}d}
t|d	�}|r�t��d
kr�t|�}|r�tjjd|d�}
t�d
|dtjj�}tjd|||
d�|_d}|jj�s~|j�|	�}|�s.�q~d|tt�|��f}|�d|�|j� |�}|�|j!�}|�sr�q~|d}	�q|S)N)Z	name_type�acquire_cred_with_passwordz�Platform GSSAPI library does not support gss_acquire_cred_with_password, cannot acquire GSSAPI credential with explicit username and password.�surrogate_or_strict��errorsZinitiate)�usage)�namer9T�Darwinstls-server-end-point:)Zapplication_datazHTTP@%s�hostname)r9r:�credsZchannel_bindingsz%s %s�
Authorizationr,)"r&�generic_urlparser�get_full_urlr4r$�gssapi�NameZNameType�userr%�hasattr�raw�NotImplementedErrorrr5r=ZCredentials�getpeercert�platform�system�get_channel_binding_cert_hashZChannelBindingsZhostbased_serviceZSecurityContextZcomplete�steprr2�	b64encode�add_unredirected_header�parent�openr3)r'�req�fp�code�msgr3�parsedZauth_headerZ
auth_protocolZin_tokenr$Z
b_passwordZcredZcbt�certZ	cert_hash�targetZrespZ	out_tokenr(r(r)�http_error_401�sJ



z$HTTPGSSAPIAuthHandler.http_error_401)NN)�__name__�
__module__�__qualname__�__doc__�re�compile�Ir.Z
handler_orderr*r4rWr(r(r(r)r"�s
r")�SSLCertVerificationErrorc@seZdZdS)rN)rXrYrZr(r(r(r)r*srcCs�|sdS|�d�}|s&|��|��kS|dkr>tdt|���|�d�\}}}d|vrftdt|���|sztdt|���|dkr�tdt|���|�d�\}}}|r�|s�dS|��|��kS)	a�Matching according to RFC 6125, section 6.4.3

        - Hostnames are compared lower case.
        - For IDNA, both dn and hostname must be encoded as IDN A-label (ACE).
        - Partial wildcards like 'www*.example.org', multiple wildcards, sole
          wildcard or wildcards in labels other then the left-most label are not
          supported and a CertificateError is raised.
        - A wildcard must match at least one character.
        F�*r,z.too many wildcards in certificate DNS name: %s�.z7wildcard can only be present in the leftmost label: %s.z<sole wildcard without additional labels are not support: %s.z:partial wildcards in leftmost label are not supported: %s.)�count�lowerr�repr�	partition)Zdnr<Z	wildcardsZdn_leftmost�sepZdn_remainderZhostname_leftmostZhostname_remainderr(r(r)�_dnsname_match-s@


�������rgc
Cs�zt|dd�}Wn"ty2tdt|���Yn0tjdkrD|}n|}|�d�dkr~zt�|�WSt	tj
tfy|Yn0zt�tj
|�WSt	tj
tfy�tdt|���Ynty�Yn0tdt|���d	S)
z�Try to convert an IP address to packed binary form

        Supports IPv4 addresses on all platforms and IPv6 on platforms with IPv6
        support.
        �strictr7z%s must be an all-ascii string.)�rariz)%s is neither an IPv4 nor an IP6 address.z%s is not an IPv4 address.N)r�UnicodeError�
ValueErrorrd�sys�version_inforb�socketZ	inet_aton�OSError�error�	TypeErrorZ	inet_ptonZAF_INET6�AttributeError)�ipnameZb_ipnameZn_ipnamer(r(r)�_inet_patonas*
�
rtcCst|���}||kS)z�Exact matching of IP addresses.

        RFC 6125 explicitly doesn't define an algorithm for this
        (section 1.7.2 - "Out of Scope").
        )rt�rstrip)rs�host_ip�ipr(r(r)�_ipaddress_match�srxcCsf|std��ztt|dd��}Wn*ty6d}YntyJd}Yn0g}|�dd�}|D]^\}}|dkr�|dur�t||�r�dS|�|�q`|dkr`|dur�t||�r�dS|�|�q`|�s
|�d	d�D]6}|D],\}}|d
kr�t||�r�dS|�|�q�q�t|�dk�r6t	d|d
�
tt|��f��n,t|�dk�rZt	d||df��nt	d��dS)aVerify that *cert* (in decoded format as returned by
        SSLSocket.getpeercert()) matches the *hostname*.  RFC 2818 and RFC 6125
        rules are followed.

        The function matches IP addresses rather than dNSNames if hostname is a
        valid ipaddress string. IPv4 addresses are supported on all platforms.
        IPv6 addresses are supported on platforms with IPv6 support (AF_INET6
        and inet_pton).

        CertificateError is raised on failure. On success, the function
        returns nothing.
        ztempty or no certificate, match_hostname needs a SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIREDrhr7NZsubjectAltNamer(ZDNSz
IP AddressZsubjectZ
commonNamer,z&hostname %r doesn't match either of %s�, zhostname %r doesn't match %rrz=no appropriate commonName or subjectAltName fields were found)
rkrtrrjr0rg�appendrx�lenr�join�maprd)rUr<rvZdnsnamesZsan�key�value�subr(r(r)r�s>


rs�-----BEGIN CERTIFICATE-----
MIICvDCCAiWgAwIBAgIJAO8E12S7/qEpMA0GCSqGSIb3DQEBBQUAMEkxCzAJBgNV
BAYTAlVTMRcwFQYDVQQIEw5Ob3J0aCBDYXJvbGluYTEPMA0GA1UEBxMGRHVyaGFt
MRAwDgYDVQQKEwdBbnNpYmxlMB4XDTE0MDMxODIyMDAyMloXDTI0MDMxNTIyMDAy
MlowSTELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMQ8wDQYD
VQQHEwZEdXJoYW0xEDAOBgNVBAoTB0Fuc2libGUwgZ8wDQYJKoZIhvcNAQEBBQAD
gY0AMIGJAoGBANtvpPq3IlNlRbCHhZAcP6WCzhc5RbsDqyh1zrkmLi0GwcQ3z/r9
gaWfQBYhHpobK2Tiq11TfraHeNB3/VfNImjZcGpN8Fl3MWwu7LfVkJy3gNNnxkA1
4Go0/LmIvRFHhbzgfuo9NFgjPmmab9eqXJceqZIlz2C8xA7EeG7ku0+vAgMBAAGj
gaswgagwHQYDVR0OBBYEFPnN1nPRqNDXGlCqCvdZchRNi/FaMHkGA1UdIwRyMHCA
FPnN1nPRqNDXGlCqCvdZchRNi/FaoU2kSzBJMQswCQYDVQQGEwJVUzEXMBUGA1UE
CBMOTm9ydGggQ2Fyb2xpbmExDzANBgNVBAcTBkR1cmhhbTEQMA4GA1UEChMHQW5z
aWJsZYIJAO8E12S7/qEpMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEA
MUB80IR6knq9K/tY+hvPsZer6eFMzO3JGkRFBh2kn6JdMDnhYGX7AXVHGflrwNQH
qFy+aenWXsC0ZvrikFxbQnX8GVtDADtVznxOi7XzFw7JOxdsVrpXgSN0eh0aMzvV
zKPZsZ2miVGclicJHzm5q080b1p/sZtuKIEZk6vZqEg=
-----END CERTIFICATE-----
s;^-----BEGIN CERTIFICATE-----\n.+?-----END CERTIFICATE-----$)�flagsc@seZdZdZdS)�ConnectionErrorzFailed to connect to the serverN�rXrYrZr[r(r(r(r)r��sr�c@seZdZdZdS)�
ProxyErrorz%Failure to connect because of a proxyNr�r(r(r(r)r��sr�c@seZdZdZdS)�SSLValidationErrorz0Failure to connect due to SSL validation failingNr�r(r(r(r)r�sr�c@seZdZdZdS)�
NoSSLErrorzXNeeded to connect to an HTTPS url but no ssl library available to verify the certificateNr�r(r(r(r)r�sr�cs"eZdZdZd�fdd�	Z�ZS)�MissingModuleErrorz8Failed to import 3rd party module required by the callerNcs tt|��|�||_||_dSr#)�superr�r*�import_traceback�module)r'�messager�r���	__class__r(r)r*szMissingModuleError.__init__)N)rXrYrZr[r*�
__classcell__r(r(r�r)r�
sr��HTTPSConnection�HTTPSHandlerc@seZdZdd�Zdd�ZdS)�CustomHTTPSConnectioncOsdtjj|g|�Ri|��d|_tr.|j|_ntrBtt�|_|_|jr`|j	r`|j�
|j	|j�dSr#)�httplibr�r*�context�HAS_SSLCONTEXTr&�HAS_URLLIB3_PYOPENSSLCONTEXTr�PROTOCOL�	cert_fileZload_cert_chain�key_file�r'�args�kwargsr(r(r)r*s
zCustomHTTPSConnection.__init__cCs�t|d�r&t�|j|jf|j|j�}nt�|j|jf|j�}|j}|jr\||_|�	�|j}t
sdtrx|jj
||d�|_n:tr�t||jtj|jt|d�|_ntj
||j|jtd�|_dS)z(Connect to a host on a given (SSL) port.�source_address��server_hostname)�keyfile�	cert_reqs�certfile�ssl_versionr�)r�r�r�N)rDrn�create_connection�host�port�timeoutr�Z_tunnel_host�sockZ_tunnelr�r�r��wrap_socket�HAS_URLLIB3_SSL_WRAP_SOCKETrr�r�	CERT_NONEr�r�)r'r�r�r(r(r)�connect$s
�
zCustomHTTPSConnection.connectN)rXrYrZr*r�r(r(r(r)r�s
r�c@seZdZdd�ZejZdS)�CustomHTTPSHandlercCs,i}tr|j|d<|�tjtfi|��|�S)Nr�)r�r&�do_open�	functools�partialr�)r'rPr�r(r(r)�
https_open>s
���zCustomHTTPSHandler.https_openN)rXrYrZr�rZdo_request_�
https_requestr(r(r(r)r�<sr�c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�HTTPSClientAuthHandlerz�Handles client authentication via cert/key

        This is a fairly lightweight extension on HTTPSHandler, and can be used
        in place of HTTPSHandler
        NcKs*tjj|fi|��||_||_||_dSr#)�urllib_requestr�r*�client_cert�
client_key�_unix_socket)r'r�r��unix_socketr�r(r(r)r*SszHTTPSClientAuthHandler.__init__cCs|�|j|�Sr#)r��_build_https_connection�r'rPr(r(r)r�Ysz!HTTPSClientAuthHandler.https_opencKsx|�|j|jd��z|j|d<Wnty4Yn0|jrRt|j�|fi|��Stsft|fi|��St	j
|fi|��S)N)r�r�r�)�updater�r�r&rrr��UnixHTTPSConnectionr�r�r�r�)r'r�r�r(r(r)r�\s�z.HTTPSClientAuthHandler._build_https_connection)NNN)rXrYrZr[r*r�r�r(r(r(r)r�Ls
r�ccs$tjj}tjtj_dV|tj_dS)z�Monkey patch ``httplib.HTTPConnection.connect`` to be ``UnixHTTPConnection.connect``
        so that when calling ``super(UnixHTTPSConnection, self).connect()`` we get the
        correct behavior of creating self.sock for the unix socket
        N)r��HTTPConnectionr��UnixHTTPConnection)Z_connectr(r(r)�(unix_socket_patch_httpconnection_connectks
r�cs,eZdZdd�Z�fdd�Zdd�Z�ZS)r�cCs
||_dSr#�r��r'r�r(r(r)r*wszUnixHTTPSConnection.__init__cs8t��tt|���Wd�n1s*0YdSr#)r�r�r�r��r'r�r(r)r�zszUnixHTTPSConnection.connectcOstjj|g|�Ri|��|Sr#)r�r�r*r�r(r(r)�__call__�szUnixHTTPSConnection.__call__)rXrYrZr*r�r�r�r(r(r�r)r�vs
r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r�z+Handles http requests to a unix socket filecCs
||_dSr#r�r�r(r(r)r*�szUnixHTTPConnection.__init__c
Cszt�tjtj�|_z|j�|j�Wn6tyZ}ztd|j|f��WYd}~n
d}~00|jtjurv|j�	|j�dS)NzInvalid Socket File (%s): %s)
rnZAF_UNIXZSOCK_STREAMr�r�r�ror�Z_GLOBAL_DEFAULT_TIMEOUTZ
settimeout)r'�er(r(r)r��s(zUnixHTTPConnection.connectcOstjj|g|�Ri|��|Sr#)r�r�r*r�r(r(r)r��szUnixHTTPConnection.__call__N)rXrYrZr[r*r�r�r(r(r(r)r��s	r�c@s eZdZdZdd�Zdd�ZdS)�UnixHTTPHandlerzHandler for Unix urlscKstjj|fi|��||_dSr#)r��HTTPHandlerr*r�)r'r�r�r(r(r)r*�szUnixHTTPHandler.__init__cCs|�t|j�|�Sr#)r�r�r�r�r(r(r)�	http_open�szUnixHTTPHandler.http_openN)rXrYrZr[r*r�r(r(r(r)r��sr�cs(eZdZdZ�fdd�Zdd�Z�ZS)�ParseResultDottedDictzO
    A dict that acts similarly to the ParseResult named tuple from urllib
    cs tt|�j|i|��||_dSr#)r�r�r*�__dict__r�r�r(r)r*�szParseResultDottedDict.__init__cs�fdd�dD�S)z]
        Generate a list from this dict, that looks like the ParseResult named tuple
        csg|]}��|d��qSr#)r0)�.0�kr�r(r)�
<listcomp>��z1ParseResultDottedDict.as_list.<locals>.<listcomp>)�scheme�netloc�path�params�query�fragmentr(r�r(r�r)�as_list�szParseResultDottedDict.as_list)rXrYrZr[r*r�r�r(r(r�r)r��sr�c
CsDt�}t|d��r"|j|d<|j|d<|j|d<|j|d<|j|d<|j|d<|j|d<|j	|d<|j
}|r�|d	d
kr�d
|jvr�d|jvr�|j�d�d	dd
���}||d<z
|j
}WnZt�y|j�d�d�d�d}d|v�r|�d�d}|�rt|�}nd
}Yn0||d<�n|d	|d<|d|d<|d|d<|d|d<|d|d<|d|d<z�t�d�}|�|d�}|�d�}|�d�}|�d�}|�r�t|dd
��}|�r�|d
d�}|�dd�\}}	nd
}}	||d<|	|d<||d<||d<Wn8t�y>d
|d<d
|d<|d|d<d
|d<Yn0|S)z�
    Returns a dictionary of url parts as parsed by urlparse,
    but accounts for the fact that older versions of that
    library do not support named attributes (ie. .netloc)
    r�r�r�r�r�r�r$r%r�[�]r,Nr<�@����:r�r-ri��z1^((?:\w)+(?::(?:\w)+)?@)?([A-Za-z0-9.-]+)(:\d+)?$)r�rDr�r�r�r�r�r�r$r%r<�splitrcr�rk�intr\r]�matchr1�	Exception)
�partsZ
generic_partsr<r�r�Z	netloc_rer�Zauthr$r%r(r(r)r?�sh







$







r?ccs t�|�D]}|�d�Vq
dS)Nr)�
b_PEM_CERT_RE�finditerr1)�b_datar�r(r(r)�extract_pem_certssr�cCsJ|��}t|�d}tj�|�d��p(d}|r6t|�}|jjddd�pH|S)Nr-�/�filenamezcontent-disposition��header)	�geturlr�osr��basenamerurr3�	get_param)�response�urlr�r�r(r(r)�get_response_filenamesr�cCsjtr|jj}|jj}n|jj}|jj}|�p.d�d�d}|�d�\}}|d�pRd�d�d}||||fS)N�application/octet-stream�,rr��charsetzutf-8)rr3ZgettypeZgetparamZget_content_typer�r�)r�Zget_typer�Zcontent_type�	main_type�sub_typer�r(r(r)�parse_content_types
r�c@s,eZdZdZdd�Zdd�Zedd��ZdS)	�GzipDecodedReaderz�A file-like object to decode a response encoded with the gzip
    method, as described in RFC 1952.

    Largely copied from ``xmlrpclib``/``xmlrpc.client``
    cCs|tst|��td��tr ||_nDt��|_tt	�
|jd�d�D]}|j�|�q>|j�
d�|��tjj|d|jd�dS)N�r��r�r�rb)�modeZfileobj)�HAS_GZIPr��missing_gzip_error�GZIP_IMP_ERRr	�_io�io�BytesIO�iterr�r��read�write�seek�close�gzip�GzipFiler*)r'rQ�blockr(r(r)r*%s
zGzipDecodedReader.__init__cCs,ztj�|�W|j��n|j��0dSr#)rrrr�r�r(r(r)r5szGzipDecodedReader.closecCstddd�S)Nrzito decompress gzip encoded responses. Set "decompress" to False, to prevent attempting auto decompression)�reason)r
r(r(r(r)r�;s�z$GzipDecodedReader.missing_gzip_errorN)rXrYrZr[r*r�staticmethodr�r(r(r(r)r�s
r�c@s"eZdZdZddd�Zdd�ZdS)	�RequestWithMethodz}
    Workaround for using DELETE/PUT/etc with urllib2
    Originally contained in library/net_infrastructure/dnsmadeeasy
    NTcCs0|duri}|��|_tj�||||||�dSr#)�upper�_methodr��Requestr*)r'r��method�datar3�origin_req_host�unverifiabler(r(r)r*Js
zRequestWithMethod.__init__cCs|jr|jStj�|�SdSr#)rr�r
�
get_methodr�r(r(r)rPszRequestWithMethod.get_method)NNNT)rXrYrZr[r*rr(r(r(r)r
Ds
r
cs G����fdd�dtj�}|S)aThis is a class factory that closes over the value of
    ``follow_redirects`` so that the RedirectHandler class has access to
    that value without having to use globals, and potentially cause problems
    where ``open_url`` or ``fetch_url`` are used multiple times in a module.
    cs"eZdZdZ����fdd�ZdS)z/RedirectHandlerFactory.<locals>.RedirectHandleraThis is an implementation of a RedirectHandler to match the
        functionality provided by httplib2. It will utilize the value of
        ``follow_redirects`` that is passed into ``RedirectHandlerFactory``
        to determine how redirects should be handled in urllib2.
        c	s�tttf�s,t|���d�}|r,tj�|��dkrLtj�|||||||�S�dvrft	�
|||||��|��}�dvr�|dks�|dkr�t	�
|��||||��nN�dkr�|dks�|dks�|dvr�t	�
|��||||��nt	�
|��||||��z|�
�}	|��}
Wn t�y |j}	|j}
Yn0|�d	d
�}|dv�r@|j}ndd}	tdd
�|j��D��}|dk�rt|dk�rtd}|dk�r�|dk�r�d}|dk�r�|dk�r�d}t||||	|
dd�S)N��ca_path�ciphers�urllib2)�noZnoneF)�allZyesTi,i��safe)�GET�HEAD� z%20)i3i4css&|]\}}|��dvr||fVqdS))zcontent-length�content-typeztransfer-encodingN�rc�r�r��vr(r(r)�	<genexpr>�s
�zSRedirectHandlerFactory.<locals>.RedirectHandler.redirect_request.<locals>.<genexpr>i/rri.i-�POSTT)rr3rrr)�anyr�r��maybe_add_ssl_handlerr��_openerZadd_handler�HTTPRedirectHandler�redirect_request�urllib_error�	HTTPErrorrr@�get_dataZget_origin_req_hostrrrr�replacer3�dict�itemsr
)r'rPrQrRrSZhdrsZnewurlZhandlerrrrr3�rr�follow_redirects�validate_certsr(r)r'esP
�z@RedirectHandlerFactory.<locals>.RedirectHandler.redirect_requestN)rXrYrZr[r'r(r.r(r)�RedirectHandler^sr1)r�r&)r/r0rrr1r(r.r)�RedirectHandlerFactoryWsLr2cCs�dg}tsP|�d�|�dtjd�tj���f�tsFtsF|�d�|�d�|�d�|rp|�dt	|��t
d	�|�||d
�|�f��dS)z_Inteligently build out the SSLValidationError based on what support
    you have installed
    zwFailed to validate the SSL certificate for %s:%s. Make sure your managed systems have a valid CA certificate installed.zXIf the website serving the url uses SNI you need python >= 2.7.9 on your managed machinez1 (the python executable used (%s) is version: %s)r+z]or you can install the `urllib3`, `pyOpenSSL`, `ndg-httpsclient`, and `pyasn1` python modulesz-to perform SNI verification in python >= 2.6.z�You can use validate_certs=False if you do not need to confirm the servers identity but this is unsafe and not recommended. Paths checked for this platform: %s.zThe exception msg was: %s.rryN)r�rzrl�
executabler|r�
splitlinesr�r�rr�)r<r��paths�excrSr(r(r)�build_ssl_validation_error�s�
�


r7cCs2tj�|�r.zt�|�Wnty,Yn0dSr#)r�r��exists�unlinkr�)r�r(r(r)�atexit_remove_file�s
r:cCs�|durg}t|�s$td|jj��tr4t|d�}ntrBtt�}nt	d��|s�t
jrd|jt
jO_|jt
j
O_d|_t
j|_|r�t||f�r�|j||d�|r�|�d�tt|���|S)NzCiphers must be a list. Got %s.)�cafilez<Host libraries are too old to support creating an sslcontextF)r;�cadatar�)rrqr�rXr�rr�rr�rFrZOP_NO_SSLv2�optionsZOP_NO_SSLv3Zcheck_hostnamer�Zverify_moder#Zload_verify_locationsZset_ciphersr|r}r)r;r<rr0r�r(r(r)�make_context�s(
r>cCst�}g}|r~|g}tt|dd�d��>}trVt|���D]}|�t�t	|dd���q8Wd�n1sj0Y|||fSts�|�
d�tt�
�dd�}|dkr�|�
d�|�
d�|�
d�nr|d	kr�|�
d
�n^|dkr�|�
d�nJ|d
k�r|�
d�n4|dk�r|�
d�n|dk�r6|�
d�|�
d�|�
d�d}t�sbt��\}}t�t|�|dk�r�t�r�|�t�t	tdd���nt�|t�|�
d�|D�]&}tj�|��s��q�t�|�}	|	D]�}tj�||�}
tj�|
��r�tj�|�ddv�r�z�|
tv�r�t|
d��}|��}Wd�n1�s80Yt�r�z,t|�D]}|�t�t	|dd����qRWnt�y�YW�q�Yn0nt�||�t�|d�Wnttf�y�Yn0�q̐q�t�r�t� �}
|
j!g|dd�<n
t�"|�|||fS)Nr6r7r�z/etc/ssl/certsZLinuxz/etc/pki/ca-trust/extracted/pemz/etc/pki/tls/certsz%/usr/share/ca-certificates/cacert.orgZFreeBSDz/usr/local/share/certsZOpenBSDz/etc/sslZNetBSDz/etc/openssl/certsZSunOSz/opt/local/etc/openssl/certsZAIXz/var/ssl/certsz/opt/freeware/etc/ssl/certsz/etc/ansibler;z/usr/local/etc/opensslr,)z.crtz.pem�
r)#�	bytearrayrOrr�r�r�extendrZPEM_cert_to_DER_certrrzrrHrI�tempfileZmkstemp�atexit�registerr:�b_DUMMY_CA_CERTr�rr��isdir�listdirr|�isfile�splitext�LOADED_VERIFY_LOCATIONSr�ro�IOErrorZget_default_verify_pathsZcapathr)r;r<�
paths_checked�fZb_pemrIZtmp_pathZtmp_fdr�Zdir_contents�	full_pathr�Zb_certZdefault_verify_pathsr(r(r)�get_ca_certs�s�
��$











��


$
(
��
rOc@sNeZdZdZdZddd�Zdd�Zdd	d
�Zdd�Zdd
d�Z	dd�Z
e
ZdS)�SSLValidationHandlerz�
    A custom handler class for SSL validation.

    Based on:
    http://stackoverflow.com/questions/1087227/validate-ssl-certificates-with-python
    http://techknack.net/python-urllib2-handlers/
    zCONNECT %s:%s HTTP/1.0
NTcCs"||_||_||_||_||_dSr#)r<r�rrr0)r'r<r�rrr0r(r(r)r*es
zSSLValidationHandler.__init__cCs
t|j�Sr#)rOrr�r(r(r)rOlsz!SSLValidationHandler.get_ca_certscCs\|durdgn|}z*t�d|���\}}}t|�|vr:t�WntyVtd��Yn0dS)zC
        make sure we get back a valid code from the proxy
        N��s(HTTP/\d\.\d) (\d\d\d) (.*)zConnection to proxy failed)r\r��groupsr�r�r�)r'r�Zvalid_codesZhttp_versionZ	resp_coderSr(r(r)�validate_proxy_responseosz,SSLValidationHandler.validate_proxy_responsecCsVtj�d�}|rR|�d�}t|�j}|D](}|�|�sJ|�d�d�|�r(dSq(dS)za
        Detect if the 'no_proxy' environment variable is set and honor those locations.
        Zno_proxyr�r�rFT)r��environr0r�rr��endswith)r'r�Zenv_no_proxyr�r�r(r(r)�detect_no_proxy|s

z$SSLValidationHandler.detect_no_proxycCs.|jp|}|jrd}n|pd}t||||d�S)N�r;r<rr0)rr>)r'r;r<rr0r(r(r)r>�s

z!SSLValidationHandler.make_contextc
Cs�|��\}}}|�|���}tj�d�}d}z|j|||j|jd�}Wnt	yXYn0�z|�r�|�r�t
t|��}|�d�p�d}	|�dd�}
|
dus�|�d�dkr�td��t
�|
|	f�}|�d�d	k�r�|�t|j|j|jfd
d��|�d��r4d
|�dd�|�dd�f}|�dt�t|d
d�����|�d�d}
|
�d�dk�rz|
|�d�7}
t|
�dk�rBtd���qB|�|
�|�r�|j||jd�}nBt�r�t||tjt |jd�}n$tj||tjt d�}t!|�"�|j�ntd|�d���nlt
�|j|jf�}|�r|j||jd�}nBt�r<t||tjt |jd�}n$tj||tjt d�}t!|�"�|j�|�#�Wn~tj$t%f�y�}zt&|j|j||�WYd}~nJd}~0t
j'�y�}z&t(d|j|jt)|�f��WYd}~n
d}~00|S)N�https_proxy)rr0r��r<r�r+z�Failed to parse https_proxy environment variable. Please make sure you export https proxy as 'https_proxy=<SCHEME>://<IP_ADDRESS>:<PORT>'�httpr6r7r$�%s:%sr%sProxy-Authorization: Basic %s
s
r��

riiz4Proxy sent too verbose headers. Only 128KiB allowed.r�)�ca_certsr�r�r�)r]r�r�zKUnsupported proxy scheme: %s. Currently ansible only supports HTTP proxies.z&Failed to connect to %s at port %s: %s)*rOrVr@r�rTr0r>rr0rFr?rr�rnr�Zsendallr�CONNECT_COMMANDr<r�r2rL�strip�findZrecvr{rSr�r�rrZ
CERT_REQUIREDr�rrGrZSSLErrorrr7rpr�r)r'rPZtmp_ca_cert_pathr<rL�	use_proxyrXr�Zproxy_partsr�Zproxy_hostname�s�credentialsZconnect_resultZssl_sr�r(r(r)�http_request�s`  

&0z!SSLValidationHandler.http_request)NNT)N)NT)rXrYrZr[r^r*rOrSrVr>rdr�r(r(r(r)rP[s



	ArPcCsDtt|��}|jdkr@|r@ts&td��t|j|jp4d|||d�SdS)N�httpsz�SSL validation is not available in your version of python. You can use validate_certs=False, however this is unsafe and not recommendedrY)rrr0)r?rr��HAS_SSLr�rPr<r�)r�r0rrrTr(r(r)r$�s
r$cCs@tr|jjj}n|jjjj}z|�|�WSty:Yn0dS)zC Attempt to get the peer certificate of the response from urlopen. N)r	rQrEZ_sockrGrr)r�Zbinary_formrnr(r(r)rG�srGcCsntsdSt�|t��}d}z
|j}Wnty6Yn0|rF|jdvrNt��}t�	|t��}|�
|�|��S)zM Gets the channel binding app data for a TLS connection using the peer cert. N)Zmd5Zsha1)�HAS_CRYPTOGRAPHYrZload_der_x509_certificaterZsignature_hash_algorithmr!r:r ZSHA256ZHashr��finalize)Zcertificate_derrUZhash_algorithmZdigestr(r(r)rJ�s

rJ�-0000c	CsHdgd�|d|dgd�|dd|d|d|d	|d
|fS)z�Accepts a timetuple and optional zone which defaults to ``-0000``
    and returns a date string as specified by RFC 2822, e.g.:

    Fri, 09 Nov 2001 01:08:47 -0000

    Copied from email.utils.formatdate and modified for separate use
    z"%s, %02d %s %04d %02d:%02d:%02d %s)ZMonZTueZWedZThuZFriZSatZSun�r-)ZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecr,rrir�r�r()�	timetuple�zoner(r(r)�rfc2822_date_string	s
��rmc@sfeZdZddd�Zdd	�Zdd
d�Zdd
�Zdd�Zdd�Zddd�Z	ddd�Z
ddd�Zdd�ZdS)r
NTF�
rcCs�|pi|_t|jt�s$td|j��||_||_||_||_||_||_	||_
|	|_|
|_||_
||_||_||_||_||_||_||_t|
tj�r�|
|_n
t��|_dS)a;This class works somewhat similarly to the ``Session`` class of from requests
        by defining a cookiejar that an be used across requests as well as cascaded defaults that
        can apply to repeated requests

        For documentation of params, see ``Request.open``

        >>> from ansible.module_utils.urls import Request
        >>> r = Request()
        >>> r.open('GET', 'http://httpbin.org/cookies/set?k1=v1').read()
        '{
  "cookies": {
    "k1": "v1"
  }
}
'
        >>> r = Request(url_username='user', url_password='passwd')
        >>> r.open('GET', 'http://httpbin.org/basic-auth/user/passwd').read()
        '{
  "authenticated": true, 
  "user": "user"
}
'
        >>> r = Request(headers=dict(foo='bar'))
        >>> r.open('GET', 'http://httpbin.org/get', headers=dict(baz='qux')).read()

        zheaders must be a dict: %rN)r3�
isinstancer,rkra�forcer�r0�url_username�url_password�
http_agent�force_basic_authr/r�r�r�r�unredirected_headers�
decompressr�	use_netrc�	cookiejar�	CookieJar�cookies)r'r3rarpr�r0rqrrrsrtr/r�r�rzr�rrurvrrwr(r(r)r*s.
zRequest.__init__cCs|dur|S|Sr#r()r'r�fallbackr(r(r)�	_fallbackJszRequest._fallbackc4Cs�|��}|duri}nt|t�s(td��t|jfi|��}|�||j�}|�||j�}|�||j�}|�|	|j	�}	|�|
|j
�}
|�||j�}|�||j�}|�|
|j
�}
|�||j�}|�||j�}|�||j�}|�||j�}|�||j�}|�||j�}|�||j�}|�||j�}|�||j�}|�||j�}g}|�rN|�t|��tt|��}|jdk�r�|
}|}|�r||j}nZd|jv�r�|j�dd�\}}d|v�r�|�dd�\}}n|}d}|��}||d<t |�}|�rt!�r�|�t!||��nt"dd	d
d�} t#| t$d��n�|�r^|
�s^t%�&�}!|!�'d|||�t%�(|!�}"t%�)|!�}#|�|"�|�|#�n�|�rz|
�rzt*||�|d
<nl|�r�z"t+�+t,j-�.d��}$|$�/|j0�}%Wnt1�y�d}%Yn0|%�r�|%\}}&}|�r�|�r�t*||�|d
<|�st%�2i�}'|�|'�t3t4t5f��s0t6||	||d�}(|(�rd|�|(�n4t7|�\})}*}+t8|)|*||	d�},|�t9||||,d��|�t:||	||d��|du�r�|�t%�;|��t%j<|�}-t%�=|-�t>|dd�}t?|||�}.|�r�|.�@d|�|�r�|.�@dd�n |�rtA|�B�d�}/|.�@d|/�dd�|�pgD�}|D]6}0|0�C�|v�rB|.�D|0||0�n|.�@|0||0��qt%�E|.d|�}1|�r�|1j�.dd��C�dk�r�tF|1jG�}2tH�r�|2|1_Gd|1_In(|1jJ}3t%�K|2|1�L�|1�M�|1�N��}1|3|1_J|1S)a
        Sends a request via HTTP(S) or FTP using urllib2 (Python2) or urllib (Python3)

        Does not require the module environment

        Returns :class:`HTTPResponse` object.

        :arg method: method for the request
        :arg url: URL to request

        :kwarg data: (optional) bytes, or file-like object to send
            in the body of the request
        :kwarg headers: (optional) Dictionary of HTTP Headers to send with the
            request
        :kwarg use_proxy: (optional) Boolean of whether or not to use proxy
        :kwarg force: (optional) Boolean of whether or not to set `cache-control: no-cache` header
        :kwarg last_mod_time: (optional) Datetime object to use when setting If-Modified-Since header
        :kwarg timeout: (optional) How long to wait for the server to send
            data before giving up, as a float
        :kwarg validate_certs: (optional) Booleani that controls whether we verify
            the server's TLS certificate
        :kwarg url_username: (optional) String of the user to use when authenticating
        :kwarg url_password: (optional) String of the password to use when authenticating
        :kwarg http_agent: (optional) String of the User-Agent to use in the request
        :kwarg force_basic_auth: (optional) Boolean determining if auth header should be sent in the initial request
        :kwarg follow_redirects: (optional) String of urllib2, all/yes, safe, none to determine how redirects are
            followed, see RedirectHandlerFactory for more information
        :kwarg client_cert: (optional) PEM formatted certificate chain file to be used for SSL client authentication.
            This file can also include the key as well, and if the key is included, client_key is not required
        :kwarg client_key: (optional) PEM formatted file that contains your private key to be used for SSL client
            authentication. If client_cert contains both the certificate and key, this option is not required
        :kwarg cookies: (optional) CookieJar object to send with the
            request
        :kwarg use_gssapi: (optional) Use GSSAPI handler of requests.
        :kwarg unix_socket: (optional) String of file system path to unix socket file to use when establishing
            connection to the provided url
        :kwarg ca_path: (optional) String of file system path to CA cert bundle to use
        :kwarg unredirected_headers: (optional) A list of headers to not attach on a redirected request
        :kwarg decompress: (optional) Whether to attempt to decompress gzip content-encoded responses
        :kwarg ciphers: (optional) List of ciphers to use
        :kwarg use_netrc: (optional) Boolean determining whether to use credentials from ~/.netrc file
        :returns: HTTPResponse. Added in Ansible 2.9
        Nzheaders must be a dict�ftpr�r,r�r+rAzfor use_gssapi=Truez https://pypi.org/project/gssapi/)rr�r�r>ZNETRCrrW)r�r�r�r�Zpassthru)Z	nonstringz
User-agentz
cache-controlzno-cacheZGMTzIf-Modified-SincecSsg|]}|���qSr(r)r��hr(r(r)r�r�z Request.open.<locals>.<listcomp>zcontent-encodingr)Orror,rkr3r|rarpr�r0rqrrrsrtr/r�r�rzr�rrurvrrwrzr�r?rr�r�r�r�rr"r
r��GSSAPI_IMP_ERRr�ZHTTPPasswordMgrWithDefaultRealmZadd_passwordZHTTPBasicAuthHandlerZHTTPDigestAuthHandler�basic_auth_header�netrcr�rTr0Zauthenticatorsr<rKZProxyHandlerr#r�r�r$rOr>r�r2ZHTTPCookieProcessorZbuild_openerZinstall_openerrr
�
add_headerrmrkrcrMZurlopenr�rQr	�lengthrSZ
addinfourl�infor�Zgetcode)4r'rr�rr3rarp�
last_mod_timer�r0rqrrrsrtr/r�r�rz�
use_gssapir�rrurvrrw�handlersrTr$r%r�rcZparsed_listZimp_err_msgZpassmanZauthhandlerZdigest_authhandler�rcZlogin�_ZproxyhandlerZssl_handlerZtmp_ca_pathr<rLr��opener�requestZtstampr��rrQrSr(r(r)rOOs�3

�






��



�zRequest.opencKs|jd|fi|��S)z�Sends a GET request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request
        :kwarg \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        r�rO�r'r�r�r(r(r)r0*szRequest.getcKs|jd|fi|��S)z�Sends a OPTIONS request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request
        :kwarg \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        ZOPTIONSr�r�r(r(r)r=4szRequest.optionscKs|jd|fi|��S)z�Sends a HEAD request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request
        :kwarg \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        rr�r�r(r(r)�head>szRequest.headcKs|jd|fd|i|��S)a(Sends a POST request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request.
        :kwarg data: (optional) bytes, or file-like object to send in the body of the request.
        :kwarg \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        r"rr��r'r�rr�r(r(r)�postHs	zRequest.postcKs|jd|fd|i|��S)a'Sends a PUT request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request.
        :kwarg data: (optional) bytes, or file-like object to send in the body of the request.
        :kwarg \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        ZPUTrr�r�r(r(r)�putSs	zRequest.putcKs|jd|fd|i|��S)a)Sends a PATCH request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request.
        :kwarg data: (optional) bytes, or file-like object to send in the body of the request.
        :kwarg \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        ZPATCHrr�r�r(r(r)�patch^s	z
Request.patchcKs|jd|fi|��S)z�Sends a DELETE request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request
        :kwargs \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        ZDELETEr�r�r(r(r)�deleteiszRequest.delete)NTFrnTNNNFrNNNNNNTNT)NNNNNNNNNNNNNNNFNNNNNN)N)N)N)
rXrYrZr*r|rOr0r=r�r�r�r�r�r(r(r(r)r
s,�
/�
\





r
rnrcCsL|p|rdnd}t�j||||||||||	|
|||
||||||||||d�S)z�
    Sends a request via HTTP(S) or FTP using urllib2 (Python2) or urllib (Python3)

    Does not require the module environment
    r"r)rr3rarpr�r�r0rqrrrsrtr/r�r�rzr�r�rrurvrrw)r
rO)r�rr3rrarpr�r�r0rqrrrsrtr/r�r�rzr�r�rrurvrrwr(r(r)�open_urlts�r�c	CsZt|t�std|jj��tjj�d�}t	|�
��D�]�\}}t|t�rZd}d}|}d}n�t|t�r�|�d�}|�d�}t
||f�s�td��|�d	�}|s�ztj|p�d
dd�d
p�d}Wnty�d}Yn0|�d�\}}	}ntd|jj��|�s`|�r`tt|dd�d��<}
tjj�|
���}|d=|�dd||f�Wd�n1�sT0Yntjj�||�}|�t|��|�dd�|d=|jd|dd�|�r�|jdttj� |��dd�|�!|�q4t"�r�|j#tj$j%d�}n0t&�}
tj'j(|
d
d�}|�)|�tj*�+|
�,��}~|�d�\}}	}~t"�r>tj-�.�j/}ntj-�0�j1}||�d|fS)aATakes a mapping, and prepares a multipart/form-data body

    :arg fields: Mapping
    :returns: tuple of (content_type, body) where ``content_type`` is
        the ``multipart/form-data`` ``Content-Type`` header including
        ``boundary`` and ``body`` is the prepared bytestring body

    Payload content from a file will be base64 encoded and will include
    the appropriate ``Content-Transfer-Encoding`` and ``Content-Type``
    headers.

    Example:
        {
            "file1": {
                "filename": "/bin/true",
                "mime_type": "application/octet-stream"
            },
            "file2": {
                "content": "text based file content",
                "filename": "fake.txt",
                "mime_type": "text/plain",
            },
            "text_form_field": "value"
        }
    z&Mapping is required, cannot be type %sz	form-data�textZplainNr��contentz4at least one of filename or content must be providedZ	mime_typer+F)rhrr�r�z5value must be a string, or mapping, cannot be type %sr6r7r�zContent-Typez%s/%szContent-DispositionzMIME-Versionr:r�)�policy)Zmaxheaderlenr\r)2rorrqr�rX�email�mimeZ	multipartZ
MIMEMultipart�sortedr-r
r0r#rk�	mimetypesZ
guess_typer�rerOrZapplicationZMIMEApplicationrr�ZnonmultipartZMIMENonMultipartZset_payloadZ	set_paramrr�r�r�Zattachr	Zas_bytesr�ZHTTPr�	generator�	GeneratorZflattenZutilsZfix_eols�getvalue�parserZBytesHeaderParserZ
parsebytesZHeaderParserZparsestr)�fields�mZfieldrr�r�r�r�r�rfrM�partr�rQ�gr3Z	b_contentr�r(r(r)�prepare_multipart�s|

�






�6��

�r�cCs*|durd}dt�td||fdd��S)z�Takes a username and password and returns a byte string suitable for
    using as value of an Authorization header to do basic auth.
    Nr+sBasic %sr[r6r7)r2rLr)r$r%r(r(r)r�sr�cCsnttdd�tddd�tddd�tddd�tddd�tdd�tddd�tddd�td	d�td	d�tddd�d
�S)zz
    Creates an argument spec that can be used with any module
    that will be requesting content via urllib/urllib2
    �str)�type�boolF)r��default�ansible-httpgetT)r�Zno_logr�)r�rprsrar0rqrrrtr�r�r�)r,r(r(r(r)�url_argument_spec	s






�r�c&Cs ts|jdd�ts6|dur6d}|jdt��dd�tj}|jt_|j	�
dd�}|d	urh|j	�
d
d�}|j	�
dd�}|j	�
d
d�}|j	�
dd�}|j	�
dd�}|j	�
dd�}|j	�
d�}|j	�
d�}|j	�
d|	�}	t|tj
�s�t��}d	}t|dd�}�z�z6t||||||||||||||||||	|
||
|||d�}|�tdd�|����D���t�r�i}|j��D]<\}}|��}||v�r�d�|||f�||<n|||<�ql|�|�g}t�} |D]$}!|!j| |!j<|�|!j|!jf��q�d�dd�|D��|d<| |d<|�td |j�
d!d"�|��|jd#��W�n�t�y�}"zft�}#|#d	u�r�|#��d$k�r�|jfd%d&t|"�i|��n|jfd%d't|"�i|��WYd	}"~"�nZd	}"~"0t t!f�y�}"z&|jfd%t|"�i|��WYd	}"~"�nd	}"~"0t"�y0}"z"|jt#|"�|"j$d(�WYd	}"~"�n�d	}"~"0t%j&�y�}"z�|"}z|"j'd	u�rXt(�|"�)�}$Wnt(�yzd}$Yn
0|"�*�z$|�td)d�|"����D���Wnt+�y�Yn0|�t|"�|$|"jd*��WYd	}"~"�n"d	}"~"0t%j,�y<}"z6t-t.|"d+d��}%|�td,t|"�|%d-��WYd	}"~"n�d	}"~"0t/j0�y|}"z&|�td.t|"�dd-��WYd	}"~"n�d	}"~"0t1j2�y�}"z(|�td/t|"j3�dd-��WYd	}"~"nPd	}"~"0t+�y}"z.|jtd0t|"�dd-�t4�5�d1�WYd	}"~"n
d	}"~"00W|t_n|t_0||fS)2a�Sends a request via HTTP(S) or FTP (needs the module as parameter)

    :arg module: The AnsibleModule (used to get username, password etc. (s.b.).
    :arg url:             The url to use.

    :kwarg data:          The data to be sent (in case of POST/PUT).
    :kwarg headers:       A dict with the request headers.
    :kwarg method:        "POST", "PUT", etc.
    :kwarg use_proxy:     (optional) whether or not to use proxy (Default: True)
    :kwarg boolean force: If True: Do not get a cached copy (Default: False)
    :kwarg last_mod_time: Default: None
    :kwarg int timeout:   Default: 10
    :kwarg boolean use_gssapi:   Default: False
    :kwarg unix_socket: (optional) String of file system path to unix socket file to use when establishing
        connection to the provided url
    :kwarg ca_path: (optional) String of file system path to CA cert bundle to use
    :kwarg cookies: (optional) CookieJar object to send with the request
    :kwarg unredirected_headers: (optional) A list of headers to not attach on a redirected request
    :kwarg decompress: (optional) Whether to attempt to decompress gzip content-encoded responses
    :kwarg cipher: (optional) List of ciphers to use
    :kwarg boolean use_netrc: (optional) If False: Ignores login and password in ~/.netrc file (Default: True)

    :returns: A tuple of (**response**, **info**). Use ``response.read()`` to read the data.
        The **info** contains the 'status' and other meta data. When a HttpError (status >= 400)
        occurred then ``info['body']`` contains the error response data::

    Example::

        data={...}
        resp, info = fetch_url(module,
                               "http://example.com",
                               data=module.jsonify(data),
                               headers={'Content-type': 'application/json'},
                               method="POST")
        status_code = info["status"]
        body = resp.read()
        if status_code >= 400 :
            body = info['body']
    zurlparse is not installed�rSTFzE%s. "decompress" has been automatically disabled to prevent a failurez2.16)rr0Nrarqr+rrrsr�rtr/rr�r�r�r�)r��status)rr3rrarpr�r�r0rqrrrsrtr/r�r�rzr�r�rrurvrrwcss|]\}}|��|fVqdSr#rrr(r(r)r!wr�zfetch_url.<locals>.<genexpr>ryz; css|]}d|VqdS)z%s=%sNr()r��cr(r(r)r!�r�Zcookies_stringrzz
OK (%s bytes)zContent-Length�unknown)rSr�r�ZredhatrSz-%s. You can also install python-ssl from EPELz%s)rS�	exceptioncss|]\}}|��|fVqdSr#rrr(r(r)r!�r�)rS�bodyr�rRzRequest failed: %s)rSr�zConnection failure: %szRConnection failure: connection was closed before a valid response was received: %szAn unknown error occurred: %s)r�)6�HAS_URLPARSE�	fail_jsonr�Z	deprecater�r�rBZtempdir�tmpdirr�r0rorxryZLWPCookieJarr,r�r�r�r-r	r3rcr|rr:rzr�rRr�rrr�rkr�rr�r(r)rQrrrrr�ZURLErrorr��getattrrnrpr�Z
BadStatusLine�line�	traceback�
format_exc)&r�r�rr3rrarpr�r�r�r�rrzrurvrrwZold_tempdirr0r$r%rsrtr/r�r�r�r�Ztemp_headersr:rZcookie_listZcookie_dictZcookier�Zdistributionr�rRr(r(r)�	fetch_urls�,
�
�	 

.2.*
$...0�r�cCs4|�d�rgS|�d�}dd�|�d�dd�D�S)z1A list of the final component's suffixes, if any.racSsg|]}d|�qS)rar()r�rbr(r(r)r��r�z_suffixes.<locals>.<listcomp>r,N)rU�lstripr�)r:r(r(r)�	_suffixes�s

r�rir�r-cCsjd}ttt|���D]L\}}||kr(qb|t|�kr@|kr\nnd||f}|�|�}qqbq||fS)a�Split a multi-part extension from a file name.

    Returns '([name minus extension], extension)'.

    Define the valid extension length (including the '.') with 'min' and 'max',
    'count' sets the number of extensions, counting from the end, to evaluate.
    Evaluation stops on the first file extension that is outside the min and max range.

    If no valid extensions are found, the original ``name`` is returned
    and ``extension`` is empty.

    :arg name: File name or path.
    :kwarg min: Minimum length of a valid file extension.
    :kwarg max: Maximum length of a valid file extension.
    :kwarg count: Number of suffixes from the end to evaluate.

    r+z%s%s)�	enumerate�reversedr�r{ru)r:�min�maxrb�	extension�iZsfxr(r(r)�_split_multiext�sr�cCs�d}t|�}
ttj�|
j�dd�\}}tj|j||dd�}|�|j	�zpt
||||||||||	|
|d�\}}|s�|jd||dfd	�|�|�}|r�|�
|�|�|�}q�|��Wn<ty�}z$|jd|t|�fd	�WYd
}~n
d
}~00|j	S)a�Download and save a file via HTTP(S) or FTP (needs the module as parameter).
    This is basically a wrapper around fetch_url().

    :arg module: The AnsibleModule (used to get username, password etc. (s.b.).
    :arg url:             The url to use.

    :kwarg data:          The data to be sent (in case of POST/PUT).
    :kwarg headers:       A dict with the request headers.
    :kwarg method:        "POST", "PUT", etc.
    :kwarg boolean use_proxy:     Default: True
    :kwarg boolean force: If True: Do not get a cached copy (Default: False)
    :kwarg last_mod_time: Default: None
    :kwarg int timeout:   Default: 10
    :kwarg unredirected_headers: (optional) A list of headers to not attach on a redirected request
    :kwarg decompress: (optional) Whether to attempt to decompress gzip content-encoded responses
    :kwarg ciphers: (optional) List of ciphers to use

    :returns: A string, the path to the downloaded file.
    r�r-)rbF)�dir�prefix�suffixr�)rurvrzFailure downloading %s, %srSr�N)rr�r�r�r�rBZNamedTemporaryFiler�Zadd_cleanup_filer:r�r�rrrr�r)r�r�rr3rrarpr�r�rurvr�bufsizer�Zfile_prefixZfile_extZfetch_temp_fileZrspr�r�r(r(r)�
fetch_file�s&�


.r�)NTNN)N)NNNT)N)NN)F)ri)NNNTFNrnTNNNFrNNNFNNNTNT)NNNNFNrnFNNNNTNT)rir�r-)
NNNTFNrnNTN)�r[Z
__future__rrrr�Z
__metaclass__rCr2Zemail.mime.multipartr�Zemail.mime.nonmultipartZemail.mime.applicationZemail.parserZemail.utilsr�r�r�r�r�rHr\rnrlrBr��types�
contextlibrrr�r��ImportErrorr��objectrZemail.policyZemail.generatorr�Zhttp.clientZclientZ"ansible.module_utils.compat.typingZmodule_utils�compat�typing�tZ-ansible.module_utils.six.moves.http_cookiejarZsixZmovesZhttp_cookiejarrxZ+ansible.module_utils.six.moves.urllib.errorZurllibrpr(Z'ansible.module_utils.common.collectionsrrZansible.module_utils.sixrr	r
Zansible.module_utils.six.movesrZansible.module_utils.basicrr
Zansible.module_utils._textrrrZurllib.requestr�r�rrrr&Zhttp_error_307Zhttp_error_308Z+ansible.module_utils.six.moves.urllib.parserrrr�r�rrfrrr�r�r�Zurllib3.contrib.pyopensslrZ+requests.packages.urllib3.contrib.pyopensslrZPROTOCOL_TLSv1r�ZctypesZctypes.util�utilZfind_libraryZlibssl_nameZCDLLZlibsslrZPROTOCOL_SSLv23rrZ_BUNDLED_METADATA�setrJZHAS_MATCH_HOSTNAMErrZbackports.ssl_match_hostnamergZcryptographyrZcryptography.hazmat.backendsrZcryptography.hazmat.primitivesr Zcryptography.exceptionsr!Z
urllib_gssapiZ
HAS_GSSAPIrrAr"Z_sslr_rkrgrtrxrEr]�M�Sr�r�r�r�r�r�r�r�r�r�rDr�r�r�r�r�r�r�r,r�r?r�r�r�r�r
r
r2r7r:r>rOrPr$rGrJrmr�r�r�r�r�r�r�r�r(r(r(r)�<module>s�
$







K
4,
;
�

#

K
%
V
 	

g~


\�
v	�
)
!�

Zerion Mini Shell 1.0