Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/module_utils/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/module_utils/urls.pyc

�
�Udac@s~dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
yddlZWn ek
r�ddljZnXddljjjjZddljjjjjZddljjjjjZddlm Z ddl!m"Z"ddl#m$Z$m%Z%m&Z&y#ddl'jZddl'm(Z(Wn-ek
r�ddl)Zddl)m(Z(nXej*j+ej*_,y ddl-m.Z.m/Z/e0Z1Wne2k
r�e3Z1nXyddl4Z4e0Z5Wne2k
r%e3Z5nXy dd	l4m6Z6m7Z7e0Z8Wnek
r_e3Z8nXyHe3Z9ydd
l:m;Z;Wn!ek
r�dd
l<m;Z;nXe0Z=Wnmek
re3Z=yByddl:m>Z>Wn!ek
r�ddl<m>Z>nXe0Z9Wnek
rnXnXe5r*e4j?Z@ne8o4e5r�yddlAZAddlBZAWnek
rfnfXeAjCjDd�ZEeAjFeE�ZGx>d
dfD]0ZHyeGeHe4jIZ@PWneJk
r�nXq�W[Gnidd6dd6ZKeL�ZMe0ZNyddl4mOZOmPZPWnEek
rSyddlQmOZOmPZPWnek
rOe3ZNnXnXyddlRZRe0ZSWnek
r�e3ZSnXeNr�yddlTmUZUeUZPWn'ek
r�deVfd��YZPnXd�ZWd�ZXd�ZYd�ZOe0ZNndZZde2fd��YZ[de[fd��YZ\d e[fd!��YZ]d"e]fd#��YZ^e_Z`e_Zae_Zbe_Zceded$�o�eded%�rd&ejefd'��YZ`d(ejffd)��YZad*ejffd+��YZbe
d,��Zgd-ejefd.��YZcnd/ejhfd0��YZid1ejjfd2��YZkd3elfd4��YZmd5�Znd6ejofd7��YZpe_e0e_d8�Zqe_d9�Zrd:�Zsd;ejtfd<��YZue_d=�Zvd>d?�Zwd@fdA��YZoe_e_e_e0e3e_dBe0e_e_e_e3dCe_e_e_e3e_e_e_dD�ZxdE�ZydF�Zze_e_e_e0e3e_dBe3e_e_e_dG�Z{e_e_e_e0e3e_dBdH�Z|dS(Is�
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.
i����N(tcontextmanager(tPY3(tget_distribution(tto_bytest	to_nativetto_text(tAbstractHTTPHandler(turlparset
urlunparse(tcreate_default_contextt
SSLContext(tPyOpenSSLContext(tssl_wrap_sockettssltTLSv1_1_methodtTLSv1_2_methodsbackports.ssl_match_hostnamet	pypi_names3.7.0.1tversion(tmatch_hostnametCertificateError(tSSLCertVerificationErrorRcBseZRS((t__name__t
__module__(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR�scCs|s
tS|jd�}|s5|j�|j�kS|dkrZtdt|���n|jd�\}}}d|kr�tdt|���n|s�tdt|���n|dkr�tdt|���n|jd�\}}}|s|rtS|j�|j�kS(s�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.
        t*is.too many wildcards in certificate DNS name: %st.s7wildcard can only be present in the leftmost label: %s.s<sole wildcard without additional labels are not support: %s.s:partial wildcards in leftmost label are not supported: %s.(tFalsetcounttlowerRtreprt	partition(tdnthostnamet	wildcardstdn_leftmosttseptdn_remainderthostname_leftmostthostname_remainder((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt_dnsname_match�s2
cCsyt|dd�}Wn'tk
r?tdt|���nXtjd	krX|}n|}|jd�dkr�ytj|�SWq�t	tj
tfk
r�q�Xnytjtj
|�SWnCt	tj
tfk
r�tdt|���ntk
rnXtdt|���dS(
s�Try to convert an IP address to packed binary form

        Supports IPv4 addresses on all platforms and IPv6 on platforms with IPv6
        support.
        terrorststricts%s must be an all-ascii string.iRs)%s is neither an IPv4 nor an IP6 address.s%s is not an IPv4 address.N(i(RtUnicodeErrort
ValueErrorRtsystversion_infoRtsockett	inet_atontOSErrorterrort	TypeErrort	inet_ptontAF_INET6tAttributeError(tipnametb_ipnametn_ipname((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt_inet_paton�s(
	
cCst|j��}||kS(s�Exact matching of IP addresses.

        RFC 6125 explicitly doesn't define an algorithm for this
        (section 1.7.2 - "Out of Scope").
        (R8trstrip(R5thost_iptip((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt_ipaddress_matchscCs�|std��nytt|dd��}Wn-tk
rJd}ntk
r`d}nXg}|jdd�}x�|D]�\}}|dkr�|dkr�t||�r�dS|j|�q�|dkr�|dk	r�t||�r�dS|j|�q�q�W|srxc|jdd�D]L}xC|D];\}}|d	kr,t||�rWdS|j|�q,q,WqWnt	|�d
kr�t
d|djtt
|��f��n;t	|�d
kr�t
d
||df��nt
d��dS(sVerify 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.
        stempty or no certificate, match_hostname needs a SSL socket or SSL context with either CERT_OPTIONAL or CERT_REQUIREDR'R(tsubjectAltNametDNSNs
IP Addresstsubjectt
commonNameis&hostname %r doesn't match either of %ss, shostname %r doesn't match %ris=no appropriate commonName or subjectAltName fields were found(((R*R8RR)tNonetgetR&tappendR<tlenRtjointmapR(tcertRR:tdnsnamestsantkeytvaluetsub((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRs>

	

+s�-----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-----
tConnectionErrorcBseZdZRS(sFailed to connect to the server(RRt__doc__(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRMwst
ProxyErrorcBseZdZRS(s%Failure to connect because of a proxy(RRRN(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRO|stSSLValidationErrorcBseZdZRS(s0Failure to connect due to SSL validation failing(RRRN(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRP�st
NoSSLErrorcBseZdZRS(sXNeeded to connect to an HTTPS url but no ssl library available to verify the certificate(RRRN(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRQ�stHTTPSConnectiontHTTPSHandlertCustomHTTPSConnectioncBseZd�Zd�ZRS(cOs�tjj|||�d|_tr4|j|_ntrStt	�|_|_n|jr�|j
r�|jj|j
|j�ndS(N(
thttplibRRt__init__RAtcontexttHAS_SSLCONTEXTt_contexttHAS_URLLIB3_PYOPENSSLCONTEXTRtPROTOCOLt	cert_filetload_cert_chaintkey_file(tselftargstkwargs((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRV�s	c
Cs"t|d�r9tj|j|jf|j|j�}n!tj|j|jf|j�}|j}|jr�||_|j	�|j}nt
s�tr�|jj
|d|�|_nitr�t|d|jdtjd|jdtd|�|_n*tj
|d|jd|jdt�|_dS(s(Connect to a host on a given (SSL) port.tsource_addresstserver_hostnametkeyfilet	cert_reqstcertfiletssl_versionN(thasattrR-tcreate_connectionthosttportttimeoutRbt_tunnel_hosttsockt_tunnelRXRZRWtwrap_sockettHAS_URLLIB3_SSL_WRAP_SOCKETRR^R
t	CERT_NONER\R[(R_RnRc((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytconnect�s*!			
*(RRRVRs(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRT�s	
tCustomHTTPSHandlercBseZd�ZejZRS(cCs8i}tr|j|d<n|jtjt|�|�S(NRW(RXRYtdo_opent	functoolstpartialRT(R_treqRa((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt
https_open�s(RRRyRtdo_request_t
https_request(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRt�s	tHTTPSClientAuthHandlercBs2eZdZdddd�Zd�Zd�ZRS(s�Handles client authentication via cert/key

        This is a fairly lightweight extension on HTTPSHandler, and can be used
        in place of HTTPSHandler
        cKs2tjj||�||_||_||_dS(N(turllib_requestRSRVtclient_certt
client_keyt_unix_socket(R_R~Rtunix_socketRa((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRV�s		cCs|j|j|�S(N(Rut_build_https_connection(R_Rx((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRy�scKsu|ji|jd6|jd6�y|j|d<Wntk
rEnX|jret|j�||�Stj||�S(NR\R^RW(	tupdateR~RRYR4R�tUnixHTTPSConnectionRURR(R_RjRa((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR��s	

	N(RRRNRARVRyR�(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR|�s	ccs0tjj}tjtj_dV|tj_dS(s�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(RUtHTTPConnectionRstUnixHTTPConnection(t_connect((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt(unix_socket_patch_httpconnection_connect�sR�cBs#eZd�Zd�Zd�ZRS(cCs
||_dS(N(R�(R_R�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRV�scCs't��tt|�j�WdQXdS(N(R�tsuperR�Rs(R_((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRs�s
cOstjj|||�|S(N(RURRRV(R_R`Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt__call__�s(RRRVRsR�(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR��s		
R�cBs)eZdZd�Zd�Zd�ZRS(s+Handles http requests to a unix socket filecCs
||_dS(N(R�(R_R�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRVscCs�tjtjtj�|_y|jj|j�Wn,tk
r`}td|j|f��nX|jtjk	r�|jj	|j�ndS(NsInvalid Socket File (%s): %s(
R-tAF_UNIXtSOCK_STREAMRnRsR�R/Rlt_GLOBAL_DEFAULT_TIMEOUTt
settimeout(R_te((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRsscOstjj|||�|S(N(RUR�RV(R_R`Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR�s(RRRNRVRsR�(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR�s			tUnixHTTPHandlercBs eZdZd�Zd�ZRS(sHandler for Unix urlscKs tjj||�||_dS(N(R}tHTTPHandlerRVR�(R_R�Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRVscCs|jt|j�|�S(N(RuR�R�(R_Rx((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt	http_opens(RRRNRVR�(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR�s	tParseResultDottedDictcBs eZdZd�Zd�ZRS(sO
    A dict that acts similarly to the ParseResult named tuple from urllib
    cOs&tt|�j||�||_dS(N(R�R�RVt__dict__(R_R`Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRV#scCs#gdD]}|j|d�^qS(	s]
        Generate a list from this dict, that looks like the ParseResult named tuple
        tschemetnetloctpathtparamstquerytfragment(sschemesnetlocspathsparamssquerysfragmentN(RBRA(R_tk((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytas_list's(RRRNRVR�(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR�s	c
Cs�t�}t|d�rx|j|d<|j|d<|j|d<|j|d<|j|d<|j|d<|j|d<|j	|d<|j
}|r�|d	d
kr�d
|jkr�d|jkr�|jjd�d	dj�}n||d
<y
|j
}Wnqtk
rj|jjd�djd�d}d|kra|jd�d}|rgt|�}qgqkd}nX||d<n]|d	|d<|d|d<|d|d<|d|d<|d|d<|d|d<y�tjd�}|j|d�}|jd�}|jd�}|jd�}|r7t|d�}n|rb|d }|jdd�\}}	n
d}}	||d<|	|d<||d
<||d<Wn=tk
r�d|d<d|d<|d|d
<d|d<nX|S(s�
    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�tusernametpasswordit[t]iRt@i����t:Rkiiiis1^((?:\w)+(?::(?:\w)+)?@)?([A-Za-z0-9.-]+)(:\d+)?$N(R�RhR�R�R�R�R�R�R�R�RtsplitRRkR*tintRAtretcompiletmatchtgroupt	Exception(
tpartst
generic_partsRRkR�t	netloc_reR�tauthR�R�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytgeneric_urlparse.sh	







	4#


#









tRequestWithMethodcBs,eZdZddded�Zd�ZRS(s}
    Workaround for using DELETE/PUT/etc with urllib2
    Originally contained in library/net_infrastructure/dnsmadeeasy
    cCsG|dkri}n|j�|_tjj||||||�dS(N(RAtuppert_methodR}tRequestRV(R_turltmethodtdatatheaderstorigin_req_hosttunverifiable((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRVs	cCs$|jr|jStjj|�SdS(N(R�R}R�t
get_method(R_((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR��s	N(RRRNRAtTrueRVR�(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR�yscs)dtjf���fd��Y}|S(sThis 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.
    tRedirectHandlercs#eZdZ���fd�ZRS(sThis 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�ts7t|�d��}|r7tjj|�q7n�dkretjj|||||||�S�ddtgkr�tj	|||||��n|j
�}�ddtgkr�|dks�|dkrptj	|j�||||��qpnx�d	krO|dks(|dks(|dkrptj	|j�||||��qpn!tj	|j�||||��y|j
�}	|j�}
Wn#tk
r�|j}	|j}
nX|jdd
�}|dkr�|j}n�d}	td�|jj�D��}|dkr"|dkr"d
}n|dkrC|dkrCd
}n|dkrd|dkrdd
}nt|d|d|d|	d|
dt�S(Ntca_pathturllib2tnotnonetalltyesi,i�tsafetGETtHEADt s%20i3i4css3|])\}}|j�dkr||fVqdS(scontent-lengthscontent-typestransfer-encodingN(scontent-lengthscontent-typestransfer-encoding(R(t.0R�tv((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pys	<genexpr>�s	i/i.i-tPOSTR�R�R�R�R�(R�R�(i3i4(RXtmaybe_add_ssl_handlerR}t_openertadd_handlertHTTPRedirectHandlertredirect_requestRturllib_errort	HTTPErrorR�R�tget_full_urltget_datatget_origin_req_hostR4R�R�treplaceR�RAtdicttitemsR�(R_RxtfptcodetmsgthdrstnewurlthandlerR�R�R�R�(R�tfollow_redirectstvalidate_certs(s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR��sN"'$'!
	
				(RRRNR�((R�R�R�(s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR��s(R}R�(R�R�R�R�((R�R�R�s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytRedirectHandlerFactory�s%LcCs�dg}tsv|jd�|jdtjdjtjj��f�trftrf|jd�n|jd�n|jd�|r�|jdt	|��nt
d	j|�||d
j|�f��dS(s_Inteligently build out the SSLValidationError based on what support
    you have installed
    swFailed to validate the SSL certificate for %s:%s. Make sure your managed systems have a valid CA certificate installed.sXIf the website serving the url uses SNI you need python >= 2.7.9 on your managed machines1 (the python executable used (%s) is version: %s)ts]or you can install the `urllib3`, `pyOpenSSL`, `ndg-httpsclient`, and `pyasn1` python moduless-to perform SNI verification in python >= 2.6.s�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.sThe exception msg was: %s.R�s, N(RXRCR+t
executableRERt
splitlinesRZRqRRP(RRktpathstexcR�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytbuild_ssl_validation_error�s	
	#
cCs>tjj|�r:ytj|�Wq:tk
r6q:XndS(N(tosR�texiststunlinkR�(tfilename((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytatexit_remove_files

tSSLValidationHandlercBsVeZdZdZdd�Zd�Zdd�Zd�Zd�Z	d�Z
e
ZRS(	s�
    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/
    sCONNECT %s:%s HTTP/1.0
cCs||_||_||_dS(N(RRkR�(R_RRkR�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRVs		cCs�g}t�}g}|jr�|jg}tt|jdd�d��K}tr||jtjt|j	�dd���n|j
|j	��WdQX|||fSts�|j
d�nttj
�dd�}|dkr|j
d�|j
d�|j
d�np|d	kr"|j
d
�nT|dkr>|j
d�n8|d
krZ|j
d�n|dkrv|j
d�n|j
d�d}ts�tj�\}}tjt|�n|dkrtr�|jtjttdd���ntj|t�|j
d�nxR|D]J}tjj|�rtjj|�rtj|�}	x|	D]}tjj||�}
tjj|
�rRtjj|�ddkrRy�|
tkr7t|
d��}|j	�}WdQXtry&|jtjt|dd���Wq4tk
rwRq4Xq7tj||�tj|d�nWqUt t!fk
rQqUXqRqRWqqWtr�tj"�}
|
j#g|d*n|||fS(NR'tsurrogate_or_stricttrbs/etc/ssl/certsuLinuxs/etc/pki/ca-trust/extracted/pems/etc/pki/tls/certss%/usr/share/ca-certificates/cacert.orguFreeBSDs/usr/local/share/certsuOpenBSDs/etc/ssluNetBSDs/etc/openssl/certsuSunOSs/opt/local/etc/openssl/certss/etc/ansibleuDarwins/usr/local/etc/opensslis.crts.pems
i(s.crts.pem($t	bytearrayR�topenRRXtextendR
tPEM_cert_to_DER_certRtreadRCRtplatformtsystemRAttempfiletmkstemptatexittregisterR�tb_DUMMY_CA_CERTR�twriteR�R�tisdirtlistdirREtisfiletsplitexttLOADED_VERIFY_LOCATIONSR�R/tIOErrortget_default_verify_pathstcapath(R_tca_certstcadatat
paths_checkedtfR�ttmp_pathttmp_fdR�tdir_contentst	full_pathR\tb_certtdefault_verify_paths((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytget_ca_certss�		!




$
.

cCs|dkrdgn|}y@tjd|�j�\}}}t|�|krZt�nWntk
rztd��nXdS(sC
        make sure we get back a valid code from the proxy
        i�s(HTTP/\d\.\d) (\d\d\d) (.*)sConnection to proxy failedN(RAR�R�tgroupsR�R�RO(R_tresponsetvalid_codesthttp_versiont	resp_codeR�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytvalidate_proxy_responsezs!

cCs}tjjd�}|ry|jd�}t|�j}x@|D]5}|j|�sn|jd�dj|�r=tSq=WntS(sa
        Detect if the 'no_proxy' environment variable is set and honor those locations.
        tno_proxyt,R�i(	R�tenvironRBR�RR�tendswithRR�(R_R�tenv_no_proxyR�Rj((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytdetect_no_proxy�s
+cCs�|jp|}|jr!d}n|p*d}trEtd|�}n!trZtt�}ntd��|sr|r�|jd|d|�n|S(Ntcafiles<Host libraries are too old to support creating an sslcontextR(	R�RARXR	RZRR[tNotImplementedErrortload_verify_locations(R_RRRW((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytmake_context�s		c
Cs�|j�\}}}|j|j��}tjjd�}d}y|j||�}Wntk
rknXy|r�|r�t	t
|��}|jd�p�d}	|jdd�}
|
dks�|jd�dkr�td��ntj
|
|	f�}|jd�dkr�|jt|j|j|jfd	d
��|jd�r�d|jdd�|jd
d�f}|jdtjt|d	d
��j��n|jd�d}
xM|
jd�dkr|
|jd�7}
t|
�dkr�td��q�q�W|j|
�|r1|j|d|j�}q�trdt|d|dtjdtd|j�}q�tj|d|dtjdt�}t |j!�|j�qftd|jd���n�tj
|j|jf�}|r�|j|d|j�}nmtr,t|d|dtjdtd|j�}n:tj|d|dtjdt�}t |j!�|j�|j"�Wnotj#t$fk
r�}t%|j|j||�n;tj&k
r�}t'd|j|jt(|�f��nX|S(Nthttps_proxyRki�RR�R�s�Failed to parse https_proxy environment variable. Please make sure you export https proxy as 'https_proxy=<SCHEME>://<IP_ADDRESS>:<PORT>'thttpR'R�R�s%s:%sR�sProxy-Authorization: Basic %s
s
s

iiis4Proxy sent too verbose headers. Only 128KiB allowed.RcRReRgsKUnsupported proxy scheme: %s. Currently ansible only supports HTTP proxies.s&Failed to connect to %s at port %s: %s()RRR�R�RRBRARRR�RROR-RitsendallRtCONNECT_COMMANDRRktbase64t	b64encodetstriptfindtrecvRDRRpRqRR
t
CERT_REQUIREDR[RtgetpeercerttclosetSSLErrorRR�R0RMR(R_Rxttmp_ca_cert_pathRRt	use_proxyRRWtproxy_partsRktproxy_hostnametstcredentialstconnect_resulttssl_sR�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pythttp_request�s`
!,(/

-$-$)N(RRRNR RARVRRRRR2R{(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR�s	`
			AcCs_tt|��}|jdkr[|r[ts<td��nt|j|jpQdd|�SdS(Nthttpss�SSL validation is not available in your version of python. You can use validate_certs=False, however this is unsafe and not recommendedi�R�(R�RR�tHAS_SSLRQR�RRk(R�R�R�tparsed((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR��s
s-0000cCs�ddddddddg|d	|d
ddd
dddddddddg|dd|d|d|d|d|fS(s�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
    s"%s, %02d %s %04d %02d:%02d:%02d %stMontTuetWedtThutFritSattSuniitJantFebtMartAprtMaytJuntJultAugtSeptOcttNovtDeciiiii((t	timetupletzone((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytrfc2822_date_string�s !R�cBs�eZdeededddeddddddd�Zd�Zdddddddddddddddedddd�Zd�Zd�Z	d�Z
dd�Zdd	�Zdd
�Z
d�ZRS(
i
R�cCs�|p	i|_t|jt�s7td|j��n||_||_||_||_||_||_	||_
|	|_|
|_||_
||_||_||_t|
tj�r�|
|_ntj�|_dS(s;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()

        sheaders must be a dict: %rN(R�t
isinstanceR�R*R+tforceRlR�turl_usernameturl_passwordt
http_agenttforce_basic_authR�R~RR�R�t	cookiejart	CookieJartcookies(R_R�R+RMRlR�RNRORPRQR�R~RRTR�R�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRVs&													cCs|dkr|S|S(N(RA(R_RKtfallback((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt	_fallback6sc0Cs�|j�}|dkr!i}nt|t�s?td��nt|j|�}|j||j�}|j||j�}|j||j	�}|j|	|j
�}	|j|
|j�}
|j||j�}|j||j
�}|j|
|j�}
|j||j�}|j||j�}|j||j�}|j||j�}|j||j�}|j||j�}g}|r�|jt|��nt||	d|�}|r�tr�|j|�ntr�|r�|jtj��ntt|��}|jdkr�|
}|r,|}|j}n�d|jkr�|jj dd�\}}d|kr}|j dd�\}}n|}d}|j!�}||d<t"|�}n|r|
rt#j$�}|j%d|||�t#j&|�}t#j'|�} |j|�|j| �q�|r:|
r:t(||�|d<q�y1t)j)t*j+j,d	��}!|!j-|j.�}"Wnt/k
r�d}"nX|"r�|"\}}#}|r�|r�t(||�|d<q�q�n|s�t#j0i�}$|j|$�nd}%try|	ryt1t2j3�}%t2j4r'|%j5t2j4O_5n|%j5t2j6O_5t2j7|%_8t9|%_:|jt;d
|d|d|%d
|��n1|s�|r�|jt;d
|d|d
|��n|r�tr�|	r�|j<�\}&}'}(y|j=|&|'�}%Wq�t>k
r�q�Xnt?t@d�rBtArBi})tr,|%|)d<n|jtA|)��n|jtB||	d|��|dk	r�|jt#jC|��nt#jD|�}*t#jE|*�tF|dd�}tG|||�}+|r�|+jHd|�n|r�|+jHdd�n.|r#tI|jJ�d�},|+jHd|,�n|p,g}xE|D]=}-|-|kr_|+jK|-||-�q6|+jH|-||-�q6W|+dg}.tLjMdkr�|.j|�nt#jN|.�}/|/S(s


        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
        :returns: HTTPResponse. Added in Ansible 2.9
        sheaders must be a dictR�tftpR�iR�R�t
AuthorizationtNETRCR~RRWR�Rit	nonstringtpassthrus
User-agents
cache-controlsno-cachetGMTsIf-Modified-SinceiiiN(iii(OR�RARLR�R*R�RVR+RMRlR�RNRORPRQR�R~RRTR�R�RCR�R�RXt
HAS_GSSAPIt
urllib_gssapitHTTPSPNEGOAuthHandlerR�RR�R�R�R�RR}tHTTPPasswordMgrWithDefaultRealmtadd_passwordtHTTPBasicAuthHandlertHTTPDigestAuthHandlertbasic_auth_headertnetrcR�RRBtauthenticatorsRR�tProxyHandlerR
R
tPROTOCOL_SSLv23tOP_NO_SSLv2toptionstOP_NO_SSLv3Rrtverify_modeRtcheck_hostnameR|RRRRhR-RtR�tHTTPCookieProcessortbuild_openertinstall_openerRR�t
add_headerRKRItadd_unredirected_headerR+R,turlopen(0R_R�R�R�R�R+RMt
last_mod_timeRlR�RNRORPRQR�R~RRTt
use_gssapiR�R�tunredirected_headersthandlerstssl_handlerR5R�R�R�R/tparsed_listtpassmantauthhandlertdigest_authhandlertrctlogint_tproxyhandlerRWttmp_ca_pathRRRatopenertrequestttstamptheaderturlopen_argstr((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR�;s�/	






		





cKs|jd||�S(s�Sends a GET request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request
        :kwarg \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        R�(R�(R_R�Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRBscKs|jd||�S(s�Sends a OPTIONS request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request
        :kwarg \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        tOPTIONS(R�(R_R�Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRjscKs|jd||�S(s�Sends a HEAD request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request
        :kwarg \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        R�(R�(R_R�Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pythead%scKs|jd|d||�S(s(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�R�(R�(R_R�R�Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytpost/s	cKs|jd|d||�S(s'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
        tPUTR�(R�(R_R�R�Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytput:s	cKs|jd|d||�S(s)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
        tPATCHR�(R�(R_R�R�Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytpatchEs	cKs|jd||�S(s�Sends a DELETE request. Returns :class:`HTTPResponse` object.

        :arg url: URL to request
        :kwargs \*\*kwargs: Optional arguments that ``open`` takes.
        :returns: HTTPResponse
        tDELETE(R�(R_R�Ra((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytdeletePsN(RRRAR�RRVRVR�RBRjR�R�R�R�R�(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyR�
s$(			�	
	
	
i
R�c*Cs�|p|rdnd}t�j||d|d|d|d|d|d|d	|d
|	d|
d|d
|d|
d|d|d|d|d|d|d|�S(s�
    Sends a request via HTTP(S) or FTP using urllib2 (Python2) or urllib (Python3)

    Does not require the module environment
    R�R�R�R�R+RMRtRlR�RNRORPRQR�R~RRTRuR�R�Rv(R�R�(R�R�R�R�R+RMRtRlR�RNRORPRQR�R~RRTRuR�R�Rv((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pytopen_url[s$cCs'dtjtd||fdd��S(s�Takes a username and password and returns a byte string suitable for
    using as value of an Authorization header to do basic auth.
    sBasic %ss%s:%sR'R�(R!R"R(R�R�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyRdvscCs�tdtdd�dtdddtddgd	td
ddd�g�d
tdddd�dtdddt�dtdddt�dtdd�dtdddt�dtdddt�dtdd�dtdd��
S(sz
    Creates an argument spec that can be used with any module
    that will be requesting content via urllib/urllib2
    R�ttypetstrRMtbooltdefaulttaliasestthirstytdeprecated_aliasestnameRs2.13RPsansible-httpgetR+R�RNROtno_logRQR~R�R(R�RR�(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyturl_argument_spec}s6c
"(Csdts|jdd�ntj}
|jt_|jjdt�}|jjdd�}|jjdd�}|jjdd�}|jjd	d�}|jjd
d�}|jjd�}|jjd
�}t|t	j
�s�t	j�}nd/}t
d|dd�}zAy�t|d|d|d|d|d|d|d|d|d|d|d|d	|d
|d|d
|d|d|	d|
d|�}|jt
d�|j�j�D���tr7i}x_|jj�D]N\}}|j�}||krdj|||f�||<q�|||<q�W|j|�ng}t
�}x7|D]/}|j||j<|j|j|jf�qMWdjd�|D��|d <||d<|jt
dd!|jjd"d#�d|j�d|j��Wnctk
r_}t�}|d/k	r?|j�d$kr?|jdd%t|�|�qL|jdd&t|�|�n�ttfk
r�}|jdt|�|�n�t j!k
r;}y|j"�} Wnt#k
r�d} nXy-|jt
d'�|j�j�D���Wnt$k
rnX|jit|�d6| d(6|jd6�nt j%k
r�}t&t'|d)d��}!|jt
dd*t|�d|!��n�t(j)k
r�}|jt
dd+t|�dd��n�t*j+k
r}|jt
dd,t|j,�dd��nEt$k
rK}|jt
dd-t|�dd�d.t-j.��nXWd/|
t_X||fS(0s
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 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 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

    :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']
    R�surlparse is not installedR�RNR�RORPsansible-httpgetRQR�R�R~RR�tstatusi����R�R�R�R+RMRtRlRTRuR�R�css'|]\}}|j�|fVqdS(N(R(R�R�R�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pys	<genexpr>�ss, s; css|]}d|VqdS(s%s=%sN((R�tc((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pys	<genexpr>�stcookies_strings
OK (%s bytes)sContent-Lengthtunknowntredhats-%s. You can also install python-ssl from EPELs%scss'|]\}}|j�|fVqdS(N(R(R�R�R�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pys	<genexpr>stbodyR�sRequest failed: %ssConnection failure: %ssRConnection failure: connection was closed before a valid response was received: %ssAn unknown error occurred: %st	exceptionN(/tHAS_URLPARSEt	fail_jsonR�ttempdirttmpdirR�RBR�RLRRRStLWPCookieJarRAR�R�R�tinfoR�RR�RRERKR�RCtgeturlR�RQRRRMR*R�R�R�R4R�tURLErrorR�tgetattrR-R0RUt
BadStatusLinetlinet	tracebackt
format_exc("tmoduleR�R�R�R�R+RMRtRlRuR�R�RTtold_tempdirR�R�R�RPRQR�R~RR�R�ttemp_headersR�RKtcookie_listtcookie_dicttcookieR�tdistributionR�R�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt	fetch_url�s�&	) 	

B	  

-
.)),%
c	
Cs?d}	tjjt|jdd�d��\}
}tjd|jd|
d|dt�}|j	|j
�y�t|||||||||�	\}
}|
s�|jdd	||df�n|
j
|	�}x&|r�|j|�|
j
|	�}q�W|j�Wn3tk
r7}|jdd	|t|�f�nX|j
S(
s�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

    :returns: A string, the path to the downloaded file.
    it/itdirtprefixtsuffixR�R�sFailure downloading %s, %s(R�R�R�R�trsplitR�tNamedTemporaryFileR�Rtadd_cleanup_fileR�R�R�R�R�R(R�R(R�R�R�R�R�R+RMRtRltbufsizet	file_nametfile_exttfetch_temp_filetrspR�R�((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt
fetch_files .'*!	
$(}RNR�R!RvReR�R�R�R-R+R�R�t
contextlibRRUtImportErrorthttp.clienttclientt-ansible.module_utils.six.moves.http_cookiejartmodule_utilstsixtmovesthttp_cookiejarRRt-ansible.module_utils.six.moves.urllib.requestturllibR�R}t+ansible.module_utils.six.moves.urllib.errorR0R�tansible.module_utils.sixRtansible.module_utils.basicRtansible.module_utils._textRRRturllib.requestRR�R�thttp_error_307thttp_error_308t+ansible.module_utils.six.moves.urllib.parseRRR�R�R�RR
R4R	R
RXRqturllib3.contrib.pyopensslRt+requests.packages.urllib3.contrib.pyopensslRZRtPROTOCOL_TLSv1R[tctypestctypes.utiltutiltfind_librarytlibssl_nametCDLLtlibsslR�RhR4t_BUNDLED_METADATAtsetR�tHAS_MATCH_HOSTNAMERRtbackports.ssl_match_hostnameR^R]t_sslRR*R&R8R<R�RMRORPRQRARTRtR|R�RhRRRSR�R�R�R�R�R�R�R�R�R�R�R�R�tBaseHandlerR�R�RKR�RdR�R�R�(((s=/usr/lib/python2.7/site-packages/ansible/module_utils/urls.pyt<module>!s&


















	
	






	4	,	
	;	#	KV 		��R						�	

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]