3 Uf| @sZddlZddlZddlZddlmZddlmZmZddlm Z ddl m Z y ddl Z ddl mZmZmZWn*ek rddljZ eZeZeZYnXdZdZGd d d eZGd d d e jZGd ddeZGdddeZGdddeZGdddZd%ddZ d&ddZ!GdddZ"GdddZ#d'dd Z$d(d!d"Z%e#Z&Gd#d$d$Z'dS))N) connections)sstrbstr)SmartIO) UserDictCase)IntType StringTypeListTypezI2.8.62.8.6-8.module_el8.10.0+6858+3ddf28328.module_el8.10.0+6858+3ddf2832c@s eZdZdS) NotProcessedN)__name__ __module__ __qualname__rr /usr/lib/python3.6/transports.pyr $sr c@seZdZdeZd'ddZd(ddZd d Zd d Zd dZ d)ddZ ddZ ddZ ddZ ddZddZddZd*ddZdd Zd!d"Zd#d$Zd%d&ZdS)+ Transportzrhn.rpclib.py/%srNcCszd|_ddd|_|j||dt|_d|_d|_d|_d|_||_ ||_ d|_ d|_ d|_ d|_d|_||_||_dS)NFr)transferencodingPOSTi@)Z_use_builtin_types_transport_flagsset_transport_flagsr_headersverbose connectionmethod_langrefreshCallbackprogressCallback bufferSize headers_inresponse_statusresponse_reason _redirectedZ _use_datetimetimeout)selfrrrrZ use_datetimer#rrr__init__*s" zTransport.__init__@cCs||_||_dS)N)rr)r$rrrrrset_progress_callback?szTransport.set_progress_callbackcCs ||_dS)N)r)r$rrrrset_refresh_callbackDszTransport.set_refresh_callbackcCs|dkr d}||_dS)Ni@)r)r$rrrrset_buffer_sizeJszTransport.set_buffer_sizecCs|dkrtd|||_dS)NGETrzUnknown request method %s)r*r)IOErrorr)r$rrrr set_methodRs zTransport.set_methodcKs<|jj||dk r||jd<|dk r0||jd<|jdS)Nrr)rupdatevalidate_transport_flags)r$rrkwargsrrrrXs    zTransport.set_transport_flagscCs |jjS)N)rcopy)r$rrrget_transport_flagscszTransport.get_transport_flagscCsH|jjd}t|dd}||jd<|jjd}t|dd}||jd<dS)Nr)strictr)rgetlookupTransferlookupEncoding)r$rrrrrr.fs      z"Transport.validate_transport_flagscCs@t|tgtfgkr.dd|D|j|<nt||j|<dS)NcSsg|] }t|qSr)str).0arrr tsz(Transport.set_header..)typerr7)r$nameargrrr set_headerqszTransport.set_headercCsF||jkr&|j|}t|ts4|g}ng}|j|<|jt|dS)N)r isinstancer appendr7)r$r<r=Zvlistrrr add_headerxs    zTransport.add_headercCs|jjdS)N)rclear)r$rrr clear_headersszTransport.clear_headerscCs8|jrtd|f|jr*tj||jdStj|SdS)NzConnecting via http to %s)r#)rprintr#rHTTPConnection)r$hostrrrget_connections zTransport.get_connectioncCsX||_|j|\}}}|sg}|j|}|j|j|jrJ|j|jdt||jd}|jf|j |j d|jx*t |j j |D]\} } |j | | qW|j dd|j|xd D]} |j| qW|j||\} } |jrtdx$| j D]\} } td | | fqW| jdkr6| d |_| j|_dS| |_| j|_| j|_|j| |S)Nr2)rrz User-Agentz Content-Typeztext/xmlContent-LengthHostzIncoming headers:z %s : %s-.ZLocation)rHrI)rJrK)r get_host_inforGZset_user_agent user_agentZset_debuglevelOutputrrrr>listritemsprocess clear_header send_httprDstatusr"r rreasonr!_process_response)r$rFhandlerZ request_bodyr extra_headersx509rZreqheadervaluehheadersfdrrrrequests<       zTransport.requestcCsbt|j|j|jd}|j|}t|trPt|j|j |j |j|jd}|j |_ |S|j |j |S)N)rr)rr) Inputrrrdecoder? InputStreamFiler^lengthr<closeparse_response)r$r^rZrespfrrrrVs     zTransport._process_responsecCs|jS)N)r")r$rrr redirectedszTransport.redirectedcCsf|j\}}x@|jd}|sP|jr,|j|jr@tdt||j|qW|j|j|jS)Nizbody:)Z getparserreadrrrDreprZfeedre)r$rgpuresponserrrrfs  zTransport.parse_responsecCs ||_dS)N)r)r$langrrrsetlangszTransport.setlang)rrNNNN)r&)NN)r)r r r __version__rMr%r'r(r)r,rr1r.r>rArCrGr_rVrhrfrorrrrr's&      8rc@s&eZdZd ddZddZddZdS) SafeTransportrNcCs<tj||||||dg|_x|p$gD]}|j|q&WdS)N)rrr#)rr% trusted_certsadd_trusted_cert)r$rrrrrrr#certfilerrrr%s  zSafeTransport.__init__cCs*tj|tjstd||jj|dS)Nz%Certificate file %s is not accessible)osaccessR_OK ValueErrorrrr@)r$rtrrrrss zSafeTransport.add_trusted_certcCsR|j|\}}}|jr$td|f|jr>tj||j|jdStj||jdSdS)NzConnecting via https to %s)rrr#)rr)rLrrDr#rZHTTPSConnectionrr)r$rFrXrYrrrrG szSafeTransport.get_connection)rrNNNN)r r rr%rsrGrrrrrqs rqc@seZdZdddZddZdS)ProxyTransportNrc Cs,tj||||||d||_||_||_dS)N)rrr#)rr%_proxy_proxy_username_proxy_password) r$proxy proxyUsername proxyPasswordrrrrr#rrrr%s  zProxyTransport.__init__cCs^|jr td||j|j|jf|jrBtj|j||j|j|jdStj|j||j|jdSdS)Nz8Connecting via http to %s proxy %s, username %s, pass %s)usernamepasswordr#)rr)rrDrzr{r|r#rZHTTPProxyConnection)r$rFrrrrG#s   zProxyTransport.get_connection)NNrrNNN)r r rr%rGrrrrrys ryc@s&eZdZd ddZddZddZdS) SafeProxyTransportNrc CsBtj||||||||| d g|_x|p*gD]} |j| q,WdS)N)r~rrrrrr#)ryr%rrrs) r$r}r~rrrrrrrr#rtrrrr%0szSafeProxyTransport.__init__cCs*tj|tjstd||jj|dS)Nz%Certificate file %s is not accessible)rurvrwrxrrr@)r$rtrrrrs=s z#SafeProxyTransport.add_trusted_certcCsf|jr td||j|j|jf|jrFtj|j||j|j|j|jdStj|j||j|j|jdSdS)Nz9Connecting via https to %s proxy %s, username %s, pass %s)rrrrr#)rrrr) rrDrzr{r|r#rZHTTPSProxyConnectionrr)r$rFrrrrGBs  z!SafeProxyTransport.get_connection)NNrrNNNN)r r rr%rsrGrrrrr/s  rc@s:eZdZd ddZejfddZejfdd Zd d ZdS) r`N@c Csd|_d|_d|_d|_d|_d|_||_||_||_|sdt j krTt j dj |_dt j krnt j dj |_dt j krt j dj |_dt j krt t j d|_dt j krt j d|_d t j krt j d |_nx|j D]}||}|j }|d kr&yt ||_Wntk r"d|_YnXq|d kr<|j |_q|d krR|j |_q|d krh|j |_q|dkr~|j |_q|dkr||_qWd|_dS)NrCZHTTP_CONTENT_TRANSFER_ENCODINGZHTTP_CONTENT_ENCODINGz CONTENT-TYPEZCONTENT_LENGTHZHTTP_ACCEPT_LANGUAGEZHTTP_X_PACKAGE_FILENAMEzcontent-lengthzcontent-transfer-encodingzcontent-encodingz content-typezaccept-languagezx-package-filename)rrr;rdrnr<rr max_mem_sizeruenvironlowerintkeysrxio)r$r]rrrrZr[r\rrrr%hsR                 zInput.__init__cCs|jdkrdS|jr2t||j|j|j|jd|_n t||_|j sN|jdkrRdS|jdkrddl }|j}|j ddt |jd|_|j ||jn t |jdS)Nzapplication/octet-stream)rrrbinarybase64r)r)r;rd _smart_readrrrr_smart_total_readrrseekrraNotImplementedError)r$r^rZold_iorrrris"    z Input.readcCs^|jdkr t||j|j|jdS|js0|j|t|drB|j|j sT|jdkrVn|jdkrddl }|j }|jj dd|j |jj|j }~t||_t|jd|_|jj|n|jdkr ddl}|jj dd|jd t|jd }|j}t||_t|jd|_|jj|n*|jd kr         z Input.decodecCs|jS)N)rn)r$rrrgetlangsz Input.getlang)NNrr) r r rr%sysstdinrirarrrrrr`gs  70r`@cCs.t|d}x|j|}|sP|j|q W|S)z Tries to read data from the supplied stream, and puts the results into a StmartIO object. The data will be in memory or in a temporary file, depending on how much it's been read Returns a SmartIO object )r)rrir)r^rrrchunkrrrrs  rcCstj}|}t|d}|}x|dkrtj} t||} |j| } t| } | sNP|| }|j| |dkrjq| |dks~|dkr| }t||} | | |d} |dkrd}n|| }|| || |qW|jdd|S)N)rrr2gư>)timerminrirrfloatr)r^amtrrrZ startTimeZlastTimebufZorigsizeZcurTimelrZ bytesReadZspeedZsecsrrrrs2       rc@seZdZdddZddZdS)rb NcCs ||_t||_||_||_dS)N)r^rrdr<re)r$r^rdr<rerrrr%=s zInputStream.__init__cCsd|j|jfS)Nz0Input data is a stream of %d bytes for file %s. )rdr<)r$rrr__repr__CszInputStream.__repr__)rN)r r rr%rrrrrrb<s rbc@seZdZdZdZdZdZdZdZdZ ddgddgd d gd ggZ dd d gZ d ddZ ddZ ddZddZd!ddZd"ddZddZddZdS)# BaseOutputrr2Nrzx-gziprzx-zlibrzx-gpgrrrcCs|rt|tjstd||_||_d|_t|_d|_ d|_ i|_ d|_ d|_ d|_d|_d|_d|_|j||dd|_dS)Nz&Expected an HTTPConnection type objectr)rr)r?rrE Exceptionr _connectionrrr]rrtransport_flagsrr_hostZ_handlerZ _http_typeZ _protocolr_BaseOutput__processed)r$rrrrrrrr%cs$ zBaseOutput.__init__cCsBt|tgtfgkr0djtt||j|<nt||j|<dS)N,)r;joinmapr7r])r$r<r=rrrr>s zBaseOutput.set_headercCs||jkr|j|=dS)N)r])r$r<rrrrRs zBaseOutput.clear_headerc Cs||_|j|jkrddl}|j|jd}|jd|tdd}|jdt|d}t j ddkrn|j t |n|j t ||j|j|_|jn|j|jkrddl}|j|jd}|jd||jt}|j||j|_n8|j|jkr t|j|j|j|jd}|jd||j|jkrT|j|j}|jd||jd d nH|j|jkrddl} |j|j}|jd||jd d | j|j|_|jd t|jt} ttjdkrtjd} |jd d| d|_ dS)NrzContent-Encodingr2)Z force_memwb)rrrrzContent-Transfer-Encodingz Content-Typezapplication/binaryz text/base64zContent-LengthzX-Transport-Infoz=Extended Capabilities Transport (C) Red Hat, Inc (version %s))!rr ENCODE_GZIPr encodingsr>rrrr version_inforrrregetvalue ENCODE_ZLIBrZ compressobjcompressr ENCODE_GPGrrTRANSFER_BINARY transfersTRANSFER_BASE64rZ encodestringrrpsplitr) r$rrZ encoding_namergrrrZ transfer_namerZ rpc_versionrrrrQsT               zBaseOutput.processcKs||_||_|jj|dS)N)rrrr-)r$rrr/rrrrszBaseOutput.set_transport_flags/RPC2cCs|js t||_|jdkr"td|jj|jj|j|t|j |j d|jj }|j |s~t jd|j|f|j|j|j|j|fS)NzNo connection object found)Zbodyr]z%s %s)rr rrrZconnectr_rrrr]Z getresponseresponse_acceptable xmlrpclibZ ProtocolErrorrTrUmsg)r$rFrWrmrrrrSs     zBaseOutput.send_httpcCsP|jdkrdS|jd krdS|jdkr*dS|jjds:dS|jdd krLdSdS) z*Returns true if the response is acceptabler2-.rZallow_partial_contentz Content-Typezapplication/octet-stream)rr)rTrr4r)r$rmrrrrs    zBaseOutput.response_acceptablecCs|jr|jjd|_dS)N)rre)r$rrrres zBaseOutput.close)rrNr)rr)r)r r rZ ENCODE_NONErrrZ TRANSFER_NONErrrrr%r>rRrQrrSrrerrrrrIs, 8  rcCs|dkr dSt|tr8d|ko.ttjknr8|St|trpx,tttjD]}tj||jkrR|SqRW|rtd|dS)zTGiven a string or numeric representation of a transfer, return the transfer codeNrzUnsupported transfer %s) r?rrrNrrrangerrx)rr3irrrr5s(  r5cCs|dkr dSt|tr8d|ko.ttjknr8|St|trpx,tttjD]}|jtj|krR|SqRW|rtd|dS)zUGiven a string or numeric representation of an encoding, return the encoding codeNrzUnsupported encoding %s) r?rrrNrrrrrx)rr3rrrrr6s(  r6c@s@eZdZdddZddZddd Zd d Zd d ZddZdS)rcrN@cCsF||_||_|j|_||_d|_|r<||jddd|_||_dS)Nr/r2)rdfile_objrerr<rfindr)r$rrdr<rrrrrr%&sz File.__init__cCs|jS)N)rd)r$rrr__len__1sz File.__len__cCs$|dkr|j}|jS|jj|S)N) _get_filerir)r$rr^rrrri4sz File.readcCsP|j}xB|j|j}|sPtjddkr:|jt|q |jt|q W|S)zHCopies the contents of this File object into another file objectrr)rrirrrrrr)r$filer^rrrr read_to_file<s zFile.read_to_filecCsL|jr,t|j|j|j|jd}|jddnt|j|jd}|jdd|S)zRead everything into a temporary file and call the progress callbacks if the file length is defined, or just reads till EOF)rrr)r)rdrrrrrr)r$rrrrrJs   zFile._get_filecCs|jr|jd|_dS)N)re)r$rrr__del__Xsz File.__del__)rNNr)N) r r rr%rrirrrrrrrrc%s  rc)rr)rNr)r)r)(rurrZrhnrZrhn.i18nrrZ rhn.SmartIOrZrhn.UserDictCaserrtypesrrr ImportErrorZ xmlrpc.clientZclientrbytesrOrprrr rrqryrr`rrrbrr5r6rNrcrrrr sD     V8  ; 8