3 Uf% @s&ddlZddlZddlZddlmZddlmZddlmZddlm Z y(ddl Z ddl m Z m Z m Z ddlZWn<ek rddljZ ddlm Z m Z m Z ddljZYnXGddde jZGd d d e jZGd d d eZGd ddeZGdddeZGdddeZddZddZdS)N)python_version)SSL) nonblocking)i18n) _CS_REQ_SENT_CS_IDLEResponseNotReadyc@seZdZddZdS) HTTPResponsecCs4t|jtjstj|j|_|jj|||||dS)N) isinstancefprZNonBlockingFile set_callback)selfrswsex user_datacallbackr!/usr/lib/python3.6/connections.pyr szHTTPResponse.set_callbackN)__name__ __module__ __qualname__r rrrrr sr c@s@eZdZeZdejfddZddZddZ dd Z d d Z dS) HTTPConnectionNcCs^tdkr tjj||||dntjj|||g|_g|_g|_d|_d|_d|_ ||_ dS)Nz2.6.1)timeoutz#rhn.connections $Revision$ (python)) rhttplibr__init___cb_rs_cb_ws_cb_ex _cb_user_data _cb_callback _user_agentr)r hostportrrrrr(s zHTTPConnection.__init__cCs"||_||_||_||_||_dS)N)rrrrr )r rrrrrrrrr 5s zHTTPConnection.set_callbackcCs ||_dS)N)r!)r Z user_agentrrrset_user_agent=szHTTPConnection.set_user_agentcCs|jr|jjrd|_|jtks&|jr,t|jdkrH|j|j|j}n |j|j}|jrv|j |j |j |j |j |j|j|jtjkstt|_|jr|jn||_|S)z!Get the response from the server.Nr)Z_HTTPConnection__responseZisclosedZ_HTTPConnection__staterrZ debuglevelresponse_classsockr r rrrrbegin will_closerZ_UNKNOWNAssertionErrorrclose)r responserrr getresponseBs"    zHTTPConnection.getresponsecCstjj||jj|jdS)N)rrconnectr& settimeoutr)r rrrr-ss zHTTPConnection.connect) rrrr r%rDEFAULT_TIMEOUTrr r$r,r-rrrrr%s  1rc@sBeZdZdddejfddZddZd ddZd d Zd d Z dS)HTTPProxyConnectionNcCsPtj|||d|j|j|_|_|j|||j|j|_|_||_ ||_ dS)N)r) rrr"r#_HTTPProxyConnection__proxy _HTTPProxyConnection__proxy_port _set_hostport_host_port_HTTPProxyConnection__username_HTTPProxyConnection__password)r proxyr"r#usernamepasswordrrrrrys  zHTTPProxyConnection.__init__cCs.|j|j|jtj||j|j|jdS)N)r3r1r2rr-r4r5)r rrrr-s zHTTPProxyConnection.connectrcCsN|j}|j|jkr$|dt|j}d||f}tj||||d|jdS)N:z http://%s%s) skip_host)r4r5 default_portstrr putrequest_add_proxy_headers)r methodurlr<hostnameZnewurlrrrr?s   zHTTPProxyConnection.putrequestcCsX|js dSd|j|jf}tjtj|jtjdtjd}|jddtj|dS)Nz%s:%s zProxy-AuthorizationzBasic %s) r6r7base64Z encodestringrbstrreplace putheaderZsstr)r ZuserpassZ enc_userpassrrrr@s $z&HTTPProxyConnection._add_proxy_headerscCs|j||\|_|_dS)N)Z _get_hostportr"r#)r r"r#rrrr3sz!HTTPProxyConnection._set_hostport)r) rrrrr/rr-r?r@r3rrrrr0xs   r0c@s2eZdZeZejjZddej fddZ ddZ dS)HTTPSConnectionNcCs$tj||||d|pg}||_dS)N)r)rr trusted_certs)r r"r#rKrrrrrszHTTPSConnection.__init__c Cstj|j|jtjtj}x|D]}|\}}}}}ytj|||}Wntjk r^d}wYnXy"|j|j|jf|j|j Wn$tjk r|j d}wYnXPqW|dkrtjdt j ||j |_|jjdS)z'Connect to a host on a given (SSL) portNz0Unable to connect to the host and port specified)socketZ getaddrinfor"r#Z AF_UNSPECZ SOCK_STREAMerrorr-r.rr*r SSLSocketrKr&init_ssl) r resultsrZafZsocktypeprotoZ canonnameZsar&rrrr-s*    zHTTPSConnection.connect) rrrr r%rrJr=rr/rr-rrrrrJs rJc@seZdZddZdS)HTTPSProxyResponsecCstj|d|_dS)Nr)r r'r()r rrrr's zHTTPSProxyResponse.beginN)rrrr'rrrrrSsrSc@sBeZdZejZddddejfddZddZd ddZ d d Z dS) HTTPSProxyConnectionNc Cs*tj|||||||d|pg}||_dS)N)r)r0rrK)r r8r"r#r9r:rKrrrrrs zHTTPSProxyConnection.__init__cCstj|d|j|jf}tj|d||jtj||j}t |_tj |}||_|j |j dkr|j t j||j |j|jtj|j|j|_|jjdS)Nz%s:%sZCONNECT)r0r-r4r5rr?r@Z endheadersr%rSr,r*Zstatus xmlrpclibZ ProtocolErrorreasonmsgrrNr&rKrO)r r"r%r+rrrr-s     zHTTPSProxyConnection.connectrcCstj||||dS)N)r<)rr?)r rArBr<rrrr?szHTTPSProxyConnection.putrequestcCstj||jd|jdS)Nz User-Agent)r0r@rIr!)r rrrr@s z'HTTPSProxyConnection._add_proxy_headers)r) rrrrJr=rr/rr-r?r@rrrrrTs  rTcCs$|dkr dStj|}|jdSdS)zJ Convert Internationalized domain name from Punycode (RFC3492) to Unicode Nidna)rrGdecode)rCrrridn_puny_to_unicodes r[cCs*|dkr dStj|}tj|jdSdS)zZ Convert domain name to Punycode (RFC3492). Hostname can be instance of string or Unicode NrY)rZustrencode)rCrrridn_ascii_to_punys r])rFZencodings.idnaZ encodingsrLplatformrZrhnrrrrrrrrV ImportErrorZ http.clientZclientZ xmlrpc.clientr rr0rJrSrTr[r]rrrr s,      S,&.