U e5d9 @sddlmZmZmZmZmZddlmZddlm Z ddl m Z ddl Z ddlZ ddlZddlZddlZddlZddlZddlZz ddlZWnek rdZYnXd*ddZd d ZGd d d ZGd ddeZGdddejeZGdddeZGdddeZGdddejZGdddZ GdddeZ!Gdddee Z"Gdddee Z#e$dkr ddl%Z%Gd d!d!Z&ed"~Z'e'(e)e'(d#d$d%e'j*e&dd&e'+e,d'e,d(z e'-Wn(e.k re,d)e/dYnXW5QRXdS)+)Faultdumpsloads gzip_encode gzip_decode)BaseHTTPRequestHandler)partial) signatureNTcCsF|r|d}n|g}|D]&}|dr6td|qt||}q|S)N._z(attempt to access private attribute "%s")split startswithAttributeErrorgetattr)objattrallow_dotted_namesZattrsir%/usr/lib64/python3.8/xmlrpc/server.pyresolve_dotted_attribute|s    rcsfddtDS)Ncs(g|] }|dstt|r|qS)r )r callabler).0memberrrr s z'list_public_methods..)dirrrrrlist_public_methodssrc@sleZdZdddZdddZdddZd d Zd d Zdd dZddZ ddZ ddZ ddZ ddZ dS)SimpleXMLRPCDispatcherFNcCs&i|_d|_||_|pd|_||_dSNutf-8)funcsinstance allow_noneencodinguse_builtin_typesselfr#r$r%rrr__init__s  zSimpleXMLRPCDispatcher.__init__cCs||_||_dSN)r"r)r'r"rrrrregister_instances!z(SimpleXMLRPCDispatcher.register_instancecCs2|dkrt|j|dS|dkr$|j}||j|<|S)N)name)rregister_function__name__r!)r'Zfunctionr+rrrr,s  z(SimpleXMLRPCDispatcher.register_functioncCs|j|j|j|jddS)N)zsystem.listMethodszsystem.methodSignaturezsystem.methodHelp)r!updatesystem_listMethodssystem_methodSignaturesystem_methodHelpr'rrr register_introspection_functionss z7SimpleXMLRPCDispatcher.register_introspection_functionscCs|jd|jidS)Nzsystem.multicall)r!r.system_multicallr2rrrregister_multicall_functionssz3SimpleXMLRPCDispatcher.register_multicall_functionsc CszPt||jd\}}|dk r(|||}n |||}|f}t|d|j|jd}Wntk r}zt||j|jd}W5d}~XYnNt\}} } z$ttdd|| f|j|jd}W5d}} } XYnX| |jdS)N)r%)Zmethodresponser#r$)r#r$%s:%sr$r#xmlcharrefreplace) rr% _dispatchrr#r$rsysexc_infoencode) r'datadispatch_methodpathparamsmethodresponsefaultexc_type exc_valueexc_tbrrr_marshaled_dispatchs0     z*SimpleXMLRPCDispatcher._marshaled_dispatchcCs^t|j}|jdk rVt|jdr8|t|jO}nt|jdsV|tt|jO}t|S)N _listMethodsr:)setr!keysr"hasattrrIrsorted)r'methodsrrrr/s   z)SimpleXMLRPCDispatcher.system_listMethodscCsdS)Nzsignatures not supportedr)r' method_namerrrr0/s z-SimpleXMLRPCDispatcher.system_methodSignaturecCsd}||jkr|j|}nX|jdk rrt|jdr<|j|St|jdsrzt|j||j}Wntk rpYnX|dkr~dSt|SdS)N _methodHelpr:) r!r"rLrPrrrpydocgetdoc)r'rOrBrrrr1<s$      z(SimpleXMLRPCDispatcher.system_methodHelpc Csg}|D]}|d}|d}z||||gWqtk rj}z||j|jdW5d}~XYqt\}}} z|dd||fdW5d}}} XYqXq|S)NZ methodNamerA) faultCode faultStringr6r7)appendr:rrTrUr;r<) r'Z call_listresultsZcallrOrArDrErFrGrrrr4[s,  z'SimpleXMLRPCDispatcher.system_multicallcCsz|j|}Wntk r"YnX|dk r4||Std||jdk rt|jdrd|j||Szt|j||j}Wntk rYnX|dk r||Std|dS)Nzmethod "%s" is not supportedr:) r!KeyError Exceptionr"rLr:rrr)r'rBrAfuncrrrr:s*   z SimpleXMLRPCDispatcher._dispatch)FNF)F)NN)NN)r- __module__ __qualname__r(r*r,r3r5rHr/r0r1r4r:rrrrrs   $   ) $rc@sbeZdZdZdZdZdZedej ej BZ ddZ dd Z d d Zd d ZddZdddZdS)SimpleXMLRPCRequestHandler)/z/RPC2ixTz \s* ([^\s;]+) \s* #content-coding (;\s* q \s*=\s* ([0-9\.]+))? #q cCs^i}|jdd}|dD]<}|j|}|r|d}|rFt|nd}|||d<q|S)NzAccept-EncodingrQ,g?r6)headersgetr aepatternmatchgroupfloat)r'rZaeerevrrraccept_encodingss  z+SimpleXMLRPCRequestHandler.accept_encodingscCs|jr|j|jkSdSdS)NT) rpc_pathsr@r2rrris_rpc_path_valids z,SimpleXMLRPCRequestHandler.is_rpc_path_validc Cs|s|dSzd}t|jd}g}|rht||}|j|}|sLqh|||t|d8}q,d |}| |}|dkrWdS|j |t |dd|j}Wntk r6}zp|dt|j dr|j jr|dt|t} t| d d d } |d | |d d |W5d}~XYnX|d|dd|jdk rt||jkr|dd} | rzt|}|ddWntk rYnX|d tt|||j|dS)Nizcontent-lengthr_r:i_send_traceback_headerz X-exceptionASCIIbackslashreplacez X-tracebackContent-length0 Content-typeztext/xmlgziprzContent-Encoding) rm report_404intrbminZrfilereadrVlenjoindecode_request_contentserverrHrr@rY send_responserLro send_headerstr traceback format_excr= end_headersencode_thresholdrkrcrNotImplementedErrorwfilewrite) r'Zmax_chunk_sizeZsize_remainingLZ chunk_sizechunkr>rCriZtraceqrrrdo_POSTs`            z"SimpleXMLRPCRequestHandler.do_POSTcCs|jdd}|dkr|S|dkrvz t|WStk rT|dd|Yqtk rr|ddYqXn|dd||dd |dS) Nzcontent-encodingZidentityrvizencoding %r not supportedzerror decoding gzip contentrrrs) rbrclowerrrr ValueErrorrr)r'r>r$rrrr}$s  z1SimpleXMLRPCRequestHandler.decode_request_contentcCsF|dd}|dd|dtt|||j|dS)Nis No such pageruz text/plainrr)rrrr{rrrr'rCrrrrw5s   z%SimpleXMLRPCRequestHandler.report_404-cCs|jjrt|||dSr))r~ logRequestsr log_request)r'codesizerrrr>sz&SimpleXMLRPCRequestHandler.log_requestN)rr)r-r[r\rlrZwbufsizeZdisable_nagle_algorithmrecompileVERBOSE IGNORECASErdrkrmrr}rwrrrrrr]s   G r]c@s*eZdZdZdZedddddfddZdS)SimpleXMLRPCServerTFNcCs,||_t||||tj||||dSr))rrr( socketserver TCPServerr'ZaddrZrequestHandlerrr#r$Zbind_and_activater%rrrr(WszSimpleXMLRPCServer.__init__)r-r[r\Zallow_reuse_addressror]r(rrrrrDs rc@s<eZdZedddddfddZddZdd Zd d d ZdS) MultiPathXMLRPCServerTFNc Cs2t||||||||i|_||_|p*d|_dSr)rr( dispatchersr#r$rrrrr(hszMultiPathXMLRPCServer.__init__cCs||j|<|Sr)r)r'r@ dispatcherrrradd_dispatcherrs z$MultiPathXMLRPCServer.add_dispatchercCs |j|Sr)r)r'r@rrrget_dispatchervsz$MultiPathXMLRPCServer.get_dispatcherc Cs|z|j||||}Wn^tdd\}}z2ttdd||f|j|jd}||jd}W5d}}XYnX|S)Nr6r7r8r9) rrHr;r<rrr$r#r=)r'r>r?r@rCrErFrrrrHys" z)MultiPathXMLRPCServer._marshaled_dispatch)NN)r-r[r\r]r(rrrHrrrrr`s rc@s0eZdZd ddZddZddZd d d ZdS) CGIXMLRPCRequestHandlerFNcCst||||dSr))rr(r&rrrr(sz CGIXMLRPCRequestHandler.__init__cCsP||}tdtdt|ttjtjj|tjjdS)NzContent-Type: text/xmlContent-Length: %d)rHprintr{r;stdoutflushbufferr)r' request_textrCrrr handle_xmlrpcs  z%CGIXMLRPCRequestHandler.handle_xmlrpccCsd}tj|\}}tjj|||d}|d}td||ftdtjjtdt|tt j t j j |t j j dS)Nr)rmessageexplainr z Status: %d %szContent-Type: %sr)rZ responseshttpr~ZDEFAULT_ERROR_MESSAGEr=rZDEFAULT_ERROR_CONTENT_TYPEr{r;rrrr)r'rrrrCrrr handle_gets   z"CGIXMLRPCRequestHandler.handle_getc Csz|dkr$tjdddkr$|nRzttjdd}Wnttfk rVd}YnX|dkrltj |}| |dS)NZREQUEST_METHODZGETZCONTENT_LENGTHr_) osenvironrcrrxr TypeErrorr;stdinrzr)r'rZlengthrrrhandle_requests   z&CGIXMLRPCRequestHandler.handle_request)FNF)N)r-r[r\r(rrrrrrrrs  rc@s:eZdZdiiifddZdiiidfddZddZdS) ServerHTMLDocNcCsZ|p|j}g}d}td}|||} | s0q:| \} } ||||| | \} } }}}}| r|| dd}|d||fn|rdt|}|d||| fn~|rdt|}|d||| fnV|| | dd kr || ||||n(|r"|d |n|| ||| }q||||dd |S) NrzM\b((http|ftp)://\S+[\w/]|RFC[- ]?(\d+)|PEP[- ]?(\d+)|(self\.)?((?:\w|\.)+))\b"z"z%sz'http://www.rfc-editor.org/rfc/rfc%d.txtz(http://www.python.org/dev/peps/pep-%04d/r6(zself.%srQ) escaperrsearchspanrVgroupsreplacerxZnamelinkr|)r'textrr!classesrNrWherepatternrestartendallZschemeZrfcZpepZselfdotr+Zurlrrrmarkups6      zServerHTMLDoc.markupcCs|r |jp dd|}d} d||||f} t|rHtt|} nd} t|trp|dp`| } |dpld} n t|} | | | o| d| } | | |j |||}|od|}d | |fS) NrQrz$%sz(...)rr6z'%sz
%s
z
%s
%s
) r-rrrr isinstancetuplerRrSZgreyr preformat)r'objectr+modr!rrNZclZanchorZnotetitleZargspecZ docstringZdecldocrrr docroutines2    zServerHTMLDoc.docroutinec Csi}|D] \}}d|||<||||<q ||}d|}||dd}|||j|} | ohd| } |d| }g} t|} | D]\}}| |j|||dq||ddd d | }|S) Nz#-z)%sz#ffffffz#7799eez %sz

%s

)r!ZMethodsz#eeaa77rQ) itemsrZheadingrrrMrVrZ bigsectionr|) r' server_nameZpackage_documentationrNZfdictkeyvalueheadresultrcontentsZ method_itemsrrr docservers*      zServerHTMLDoc.docserver)r-r[r\rrrrrrrrs) rc@s4eZdZddZddZddZddZd d Zd S) XMLRPCDocGeneratorcCsd|_d|_d|_dS)NzXML-RPC Server DocumentationzGThis server exports the following methods through the XML-RPC protocol.)rserver_documentation server_titler2rrrr(:szXMLRPCDocGenerator.__init__cCs ||_dSr))r)r'rrrrset_server_titleBsz#XMLRPCDocGenerator.set_server_titlecCs ||_dSr))r)r'rrrrset_server_nameGsz"XMLRPCDocGenerator.set_server_namecCs ||_dSr))r)r'rrrrset_server_documentationLsz+XMLRPCDocGenerator.set_server_documentationc Csi}|D]}||jkr&|j|}n|jdk rddg}t|jdrT|j||d<t|jdrp|j||d<t|}|dkr|}qt|jdszt|j|}Wqtk r|}YqXq|}n|||<q t }| |j |j |}| t|j|S)N_get_method_argstringrrPr6)NNr:)r/r!r"rLrrPrrrrrrrZpagehtmlrr)r'rNrOrBZ method_infoZ documenterZ documentationrrrgenerate_html_documentationQs<          z.XMLRPCDocGenerator.generate_html_documentationN)r-r[r\r(rrrrrrrrr3s rc@seZdZddZdS)DocXMLRPCRequestHandlercCsf|s|dS|jd}|d|dd|dtt|| |j |dS)Nr rtruz text/htmlrr) rmrwr~rr=rrrr{rrrrrrrdo_GETs  zDocXMLRPCRequestHandler.do_GETN)r-r[r\rrrrrrs rc@s"eZdZedddddfddZdS)DocXMLRPCServerTFNc Cs&t||||||||t|dSr))rr(rrrrrr(s zDocXMLRPCServer.__init__)r-r[r\rr(rrrrrsrc@seZdZddZddZdS)DocCGIXMLRPCRequestHandlercCsT|d}tdtdt|ttjtjj|tjjdS)Nr zContent-Type: text/htmlr) rr=rr{r;rrrrrrrrrs z%DocCGIXMLRPCRequestHandler.handle_getcCst|t|dSr))rr(rr2rrrr(s z#DocCGIXMLRPCRequestHandler.__init__N)r-r[r\rr(rrrrrsr__main__c@s"eZdZddZGdddZdS)ExampleServicecCsdS)NZ42rr2rrrgetDataszExampleService.getDatac@seZdZeddZdS)zExampleService.currentTimecCs tjSr))datetimeZnowrrrrgetCurrentTimesz)ExampleService.currentTime.getCurrentTimeN)r-r[r\ staticmethodrrrrr currentTimesrN)r-r[r\rrrrrrrsr)Z localhosti@cCs||Sr)r)xyrrrrnradd)rz&Serving XML-RPC on localhost port 8000zKIt is advisable to run this example server within a secure, closed network.z& Keyboard interrupt received, exiting.)T)0Z xmlrpc.clientrrrrrZ http.serverr functoolsrinspectr rrrr;rrrRrZfcntl ImportErrorrrrr]rrrrZHTMLDocrrrrrr-rrr~r,powr*r5rZ serve_foreverKeyboardInterruptexitrrrrksf      ,EbQ