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|jt|_|jr|jn||_|S)z!Get the response from the server.Nr)Z_HTTPConnection__responseZisclosedZ_HTTPConnection__staterrZ debuglevelresponse_classsockr r rrrrbeginr will_closeclose)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)r2r0r1rr,r3r4)r rrrr,s zHTTPProxyConnection.connectrcCsN|j}|j|jkr$|dt|j}d||f}tj||||d|jdS)N:z http://%s%s) skip_host)r3r4 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) r5r6base64Z encodestringrbstrreplace putheaderZsstr)r ZuserpassZ enc_userpassrrrr?s $z&HTTPProxyConnection._add_proxy_headerscCs|j||\|_|_dS)N)Z _get_hostportr"r#)r r"r#rrrr2sz!HTTPProxyConnection._set_hostport)r) rrrrr.rr,r>r?r2rrrrr/xs   r/c@s2eZdZeZejjZddej fddZ ddZ dS)HTTPSConnectionNcCs$tj||||d|pg}||_dS)N)r)rr trusted_certs)r r"r#rJrrrrrszHTTPSConnection.__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 SSLSocketrJr&init_ssl) r resultsrZafZsocktypeprotoZ canonnameZsar&rrrr,s*    zHTTPSConnection.connect) rrrr r%rrIr<rr.rr,rrrrrIs rIc@seZdZddZdS)HTTPSProxyResponsecCstj|d|_dS)Nr)r r'r()r rrrr's zHTTPSProxyResponse.beginN)rrrr'rrrrrRsrRc@sBeZdZejZddddejfddZddZd ddZ d d Z dS) HTTPSProxyConnectionNc Cs*tj|||||||d|pg}||_dS)N)r)r/rrJ)r r7r"r#r8r9rJrrrrrs 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)r/r,r3r4rr>r?Z endheadersr%rRr+r)Zstatus xmlrpclibZ ProtocolErrorreasonmsgrrMr&rJrN)r r"r%r*rrrr,s     zHTTPSProxyConnection.connectrcCstj||||dS)N)r;)rr>)r r@rAr;rrrr>szHTTPSProxyConnection.putrequestcCstj||jd|jdS)Nz User-Agent)r/r?rHr!)r rrrr?s z'HTTPSProxyConnection._add_proxy_headers)r) rrrrIr<rr.rr,r>r?rrrrrSs  rScCs$|dkr dStj|}|jdSdS)zJ Convert Internationalized domain name from Punycode (RFC3492) to Unicode Nidna)rrFdecode)rBrrridn_puny_to_unicodes rZcCs*|dkr dStj|}tj|jdSdS)zZ Convert domain name to Punycode (RFC3492). Hostname can be instance of string or Unicode NrX)rZustrencode)rBrrridn_ascii_to_punys r\)rEZencodings.idnaZ encodingsrKplatformrZrhnrrrrrrrrU ImportErrorZ http.clientZclientZ xmlrpc.clientr rr/rIrRrSrZr\rrrr s,      S,&.