3 Uf^ @s`dZddlZddlZddlZddlmZddlmZddlm Z yd)d*Z d+d,Z!d-d.Z"d/d0Z#d1d2Z$d3d4Z%d?d5d6Z&d7d8Z'd9d:Z(dS)@Servera7uri [,options] -> a logical connection to an XML-RPC server uri is the connection point on the server, given as scheme://host/target. The standard implementation always supports the "http" scheme. If SSL socket support is available (Python 2.0), it also supports "https". If the target part and the slash preceding it are both omitted, "/RPC2" is assumed. The following options can be given as keyword arguments: transport: a transport factory encoding: the request encoding (default is UTF-8) verbose: verbosity level proxy: use an HTTP proxy username: username for authenticated HTTP proxy password: password for authenticated HTTP proxy All 8-bit strings passed to the server proxy are assumed to use the given encoding. Nrc Cs6|dkrZt|\} } } }| dk r.d| | f}n| }| dk rZ|dkrZ| }|dk rZ|dkrZ|}t||_d|_d|_d|_||_||_||_| |_ t t j dkrt j d|_ nt |_ |j|dkrd|_|j|j|||| }nd|_d|_d|_||_g|_d|_||_||_|j||j| d|_t|_dS)Nz%s:%srr)r%r_uri_refreshCallback_progressCallback _bufferSize_proxy _username _password_timeoutr __version__r rpc_version_reset_host_handler_and_type_allow_redirectdefault_transport_type _redirecteduse_handler_path _transport_trusted_cert_files_lang _encoding_verboseset_refresh_callbackset_progress_callback send_handlerr_headers)selfuri transportencodingverboser$usernamepasswordrefreshCallbackprogressCallbacktimeoutZphZppZpuZpwrrr__init__sJ     zServer.__init__cCsZ|r4|dkr |j||||d}qV|j||||d}n"|dkrJ|j|d}n |j|d}|S)Nhttps)Z proxyUsernameZ proxyPasswordrM)rM)_transport_class_https_proxy_transport_class_proxy_transport_class_https_transport_class)rDtyper$rIrJrMrFrrrr7s zServer.default_transportcCs ||_dS)N)r6)rDZallowrrrallow_redirectszServer.allow_redirectcCs|js dS|jS)N)r6r9)rDrrr redirectedszServer.redirectedcCs||_|jj|dS)N)r,r;r@)rDrKrrrr@szServer.set_refresh_callbackcCs||_|jj|dS)N)r.r;set_buffer_size)rD bufferSizerrrrWszServer.set_buffer_size@cCs||_|jj||dS)N)r-r;rA)rDrLrXrrrrAszServer.set_progress_callbackcCstj|||jdS)N)rG) xmlrpclibdumpsr>)rDparams methodnamerrr _req_bodyszServer._req_bodycCs|jr|jjSdS)N)r;Z headers_in)rDrrrget_response_headersszServer.get_response_headerscCs|jr|jjSdS)N)r;response_status)rDrrrget_response_statusszServer.get_response_statuscCs|jr|jjSdS)N)r;Zresponse_reason)rDrrrget_response_reasonszServer.get_response_reasonc Cs|j}|sdS|jd}|s"dStd|j}|ddks@tt|dksPt|djd}t|dksnt|\}}|dkrd}nt|}|jd \}}|t|t|d }|S) aSReturns a dictionary with three values: length: the total length of the entity-body (can be None) first_byte_pos: the position of the first byte (zero based) last_byte_pos: the position of the last byte (zero based) The range is inclusive; that is, a response 8-9/102 means two bytes Nz Content-Rangerbytesrr/*-)ZlengthZfirst_byte_posZ last_byte_pos)r_getfilterrAssertionErrorrint) rDheadersZ content_ranger!brangeZ total_lenstartendresultrrrget_content_ranges(  zServer.get_content_rangecCs$|j}|sdSd|kr |dSdS)Nz Accept-Ranges)r_)rDrkrrr accept_ranges)s zServer.accept_rangescCst|j\}}|dkrtdt|dks:|dddkr>t|dkrR|j|_n||_|jd krjtd t|\|_|_ |j sd |_ dS) z Reset the attributes: self._host, self._handler, self._type according the value of self._uri. Nzmissing protocol in urirrz//httprOzunsupported XML-RPC protocolz/RPC2)rsrO) r r+r&rlowerr8IOErrorr _host_handler)rDrTrErrrr51s  z#Server._reset_host_handler_and_typecsd}g}x|D]}t|}|tks*|tkr>tj|dt|}nf|tkr^tfdd|D}nF|tkrzfdd|D}n*|t ks|t krt fdd|j D}|j |qWt|dkr|d St|Sd S) a> Strip characters, which are not allowed according: http://www.w3.org/TR/2006/REC-xml-20060816/#charsets From spec: Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */ z#[\x00-\x09]|[\x0b-\x0c]|[\x0e-\x1f]c3s|]}j|VqdS)N)_strip_characters).0i)rDrr Usz+Server._strip_characters..csg|]}j|qSr)ry)rzr{)rDrr Wsz,Server._strip_characters..csg|]\}}j||qSr)ry)rznameval)rDrrr}YsrrN)rTrrrsubrrtuplerr r dictitemsappendr)rDargsZregexproitemZ item_typer)rDrryHs   zServer._strip_charactersc Csd}d}|jxt|tkr$td|jjx$|jjD]\}}|jj||q:W|jjdd|j |jjdd|j r|jjdd|r|jjd d |j r|jjd |j |j |j ||}y&|jj|j|j||jd }|jj} Wn2tjk r|jr ntjdj} YnXd |_|d7}| dkr:Pn| dkrLd|_q|jj|_d|_d}|j srtd|jrtd|j|jft|j\} } | d kr| j} | dkrtd| |jdkr| dkrtdt | \|_|_|jsd|_|`|j!| |j"|j#|j$|j%|_|j&|j'|j(|j)|j*|j+|j,|j-|j.gkrt/|jdrx|j.D]} |jj0| qnWqWt1|t2j3r|St1|t4rt5|dkr|d}|S)zL Call a method on the remote server we can handle redirections. rz!Unable to fetch requested PackagezX-Infoz+RPC Processor (C) Red Hat, Inc (version %s)zX-Client-VersionrzX-RHN-Transport-Capabilityzfollow-redirects=3zX-RHN-Redirect0z X-RHN-Path)rHN-.zRedirects not allowedz%s redirected to %srsrOz%Redirected to unsupported protocol %sz)HTTPS redirected to HTTP is not supportedz/RPC2add_trusted_cert)rr)rsrO)6r5MAX_REDIRECTIONSInvalidRedirectionErrorr;Z clear_headersrCr set_header add_headerr4r6rBr^ryrequestrvrwr?r`rZZ ProtocolErrorr:sysexc_infoerrcoder9rVprintr+r rtr8r r7r/r0r1r2rAr-r@r,rWr.setlangr=r<hasattrr isinstancerZFilerr) rDr]r\Zredirect_responseZretrykvrZresponseZ save_responsetyprEcertfilerrr_requestbs                  zServer._requestcCsd|jj|j|jfS)Nz <%s for %s%s>) __class__r'rvrw)rDrrr__repr__szServer.__repr__cCs t|j|S)N)_Methodr)rDr~rrr __getattr__szServer.__getattr__cKs,|js dS|j||d|jjf|dS)N)transferrG)r;updateset_transport_flags)rDrrGkwargsrrrrs  zServer.set_transport_flagscCs|js iS|jjS)N)r;get_transport_flags)rDrrrrszServer.get_transport_flagscCsdS)Nr)rDrrrreset_transport_flagsszServer.reset_transport_flagscCs@t|tgtfgkr.dd|D|j|<nt||j|<dS)NcSsg|] }t|qSr)str)rzarrrr}sz%Server.set_header..)rTrCr)rDr~argrrrrszServer.set_headercCsF||jkr&|j|}t|ts4|g}ng}|j|<|jt|dS)N)rCrrrr)rDr~rZvlistrrrrs    zServer.add_headercCs(||_|jr$t|jdr$|jj|dS)Nr)r=r;rr)rDZlangrrrr szServer.setlangcCs tddS)NzThis method is deprecated)NotImplementedError)rDZca_chainrrr use_CA_chainszServer.use_CA_chaincCs.|jj||jr*t|jdr*|jj|dS)Nr)r<rr;rr)rDrrrrrs zServer.add_trusted_certcCs|jr|jjd|_dS)N)r;close)rDrrrrs z Server.close) NNrNNNNNN)NNNN)rY)rr)N))r'r(r)__doc__rZ TransportrSZ SafeTransportrRZProxyTransportrQZSafeProxyTransportrPrNr7rUrVr@rWrAr^r_rarbrprqr5ryrr__str__rrrrrrrrrrrrrrr*lsH C  #s   r*c @s\eZdZdddddidddf ddZddZddZdd d Zd d Zd dZdddZ dS) GETServerNrc CsBtj|||||||| | d ||_||_|j|_|jddddS)N)r$rIrJrFrKrLrM)offsetamount)r*rNZ_client_versionrCrw _orig_handler set_range) rDrErFr$rIrJZclient_versionrkrKrLrMrrrrNszGETServer.__init__cCs$| st|dkrtdtdd|jjd}|d|d|gt|dd}ddj||_|j|_|j r|j r|j |_x$|j j D]\}}|jj||qW|jdk r |jdkrt|jd}|jdk r|t|j|jd}ndt|j }|jjd d ||jjdd d S) Nrz$Required parameter channel not foundcSs|dkS)Nrxr)xrrr5sz%GETServer._req_body..rdz$RHNrrfZRangezbytes=)allow_partial_contentrx)r ExceptionrhrrlistjoinrwrBr9r: _new_req_bodyrCrr;r_offsetr_amountr)rDr\r]Zh_compsZhndlhrrlrrrr^1s&"    zGETServer._req_bodycCst|j\}}t|\}}|S)N)r r9r )rDrTZtmpuriZsiteZhandlerrrrrUs zGETServer._new_req_bodycCs|dk rBy t|}Wn,tk r@td|dtjdYnX|dk ry t|}Wn,tk rtd|dtjdYnX|dkrtd|||_||_dS)NzInvalid value `%s' for offsetrzInvalid value `%s' for amountr)rjr# RangeErrorrrrr)rDrrrrrrZs   zGETServer.set_rangecCs|jjdddS)Nr)r)r;r)rDrrrroszGETServer.reset_transport_flagscCs t|j|S)N) SlicingMethodr)rDr~rrrrrszGETServer.__getattr__cCs$tj||||||d}|jd|S)N)r$rIrJrMZGET)r*r7Z set_method)rDrTr$rIrJrMretrrrr7vs zGETServer.default_transport)NN)NNNN) r'r(r)rNr^rrrrr7rrrrrs$ rc@s eZdZdS)rN)r'r(r)rrrrr|src@s eZdZdS)rN)r'r(r)rrrrrsrcCs>ddl}t||js*||kr&||gSgSdd|j|DS)NrcSs g|]}|jdddjqS)rr)rstrip)rzrrrrr}sz#getHeaderValues..) mimetoolsrZMessageZgetallmatchingheaders)rkr~rrrrgetHeaderValuess  rc@s4eZdZdZddZddZddZdd ZeZd S) rz{ some magic to bind an XML-RPC method to an RPC server. supports "nested" methods (e.g. examples.getStateName) cCs||_||_dS)N)_send_name)rDsendr~rrrrNsz_Method.__init__cCst|jd|j|fS)Nz%s.%s)rrr)rDr~rrrrsz_Method.__getattr__cGs|j|j|S)N)rr)rDrrrr__call__sz_Method.__call__cCsd|jj|j|jfS)Nz <%s %s (%s)>)rr'rr)rDrrrrsz_Method.__repr__N) r'r(r)rrNrrrrrrrrrs rc@s(eZdZdZddZddZddZdS) rz; A "slicing method" allows for byte range requests cCstj|||d|_dS)N)rrNr)rDrr~rrrrNszSlicingMethod.__init__cCst|jd|j|fS)Nz%s.%s)rrr)rDr~rrrrszSlicingMethod.__getattr__cOs|jd|_|jd|_y|jjj|j|jdWntk rFYnX|j|j|}y|jjjWntk rzYnX|S)Nrr)rr) rgrrrZim_selfrAttributeErrorrr)rDrrrorrrrs   zSlicingMethod.__call__N)r'r(r)rrNrrrrrrrsrcCsbd}d}d}||kr t||}d}||krZt||}|rZdj|}ddl}d|j|}||fS)z% Reports the error from the headers. rrxzX-RHN-Fault-CodezX-RHN-Fault-StringNz%s)rjrrbase64Z decodestring)rkrerrmsgsZ_sListZ_srrrr reportErrors   r)-r3rrrZrhnrZrhn.i18nrZrhn.UserDictCaserrZtypesrrrrr r Zurllibr r ImportErrorZ xmlrpc.clientZclientrrrcrrZ urllib.parserrr"r%rur&r*rrrrrrrrrrrrsF     % 5^