a Rf@ @s ddlmZmZmZmZmZddlmZddlm Z ddl m Z ddl Z ddlZ ddlZddlZddlZddlZddlZddlZz ddlZWneydZYn0d*ddZd d ZGd d d ZGd ddeZGdddejeZGdddeZGdddeZGdddejZGdddZ GdddeZ!Gdddee Z"Gdddee Z#e$dkrddl%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.ye,d)e/dYn0Wdn1s0YdS)+)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_namesattrsir2/opt/alt/python39/lib64/python3.9/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|durt|j|dS|dur$|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_multicallr3rrrregister_multicall_functionssz3SimpleXMLRPCDispatcher.register_multicall_functionsc CszPt||jd\}}|dur(|||}n |||}|f}t|d|j|jd}Wnty}zt||j|jd}WYd}~nbd}~0t\}} } z0ttdd|| f|j|jd}Wd}} } nd}} } 0Yn0| |jdS)N)r&)Zmethodresponser$r%)r$r%%s:%sr%r$xmlcharrefreplace) rr& _dispatchrr$r%rsysexc_infoencode) r(datadispatch_methodpathparamsmethodresponsefaultexc_type exc_valueexc_tbrrr_marshaled_dispatchs,    "z*SimpleXMLRPCDispatcher._marshaled_dispatchcCs^t|j}|jdurVt|jdr8|t|jO}nt|jdsV|tt|jO}t|S)N _listMethodsr;)setr"keysr#hasattrrJrsorted)r(methodsrrrr0s   z)SimpleXMLRPCDispatcher.system_listMethodscCsdS)Nzsignatures not supportedr)r( method_namerrrr1/s z-SimpleXMLRPCDispatcher.system_methodSignaturecCsd}||jvr|j|}nV|jdurpt|jdr<|j|St|jdspzt|j||j}WntynYn0|dur|dSt|SdS)N _methodHelpr;) r"r#rMrQrrrpydocgetdoc)r(rPrCrrrr2<s$       z(SimpleXMLRPCDispatcher.system_methodHelpc Csg}|D]}|d}|d}z||||gWqtyl}z ||j|jdWYd}~qd}~0t\}}} z(|dd||fdWd}}} nd}}} 0Yq0q|S)NZ methodNamerB) faultCode faultStringr7r8)appendr;rrUrVr<r=) r(Z call_listresultsZcallrPrBrErFrGrHrrrr5[s,  $z'SimpleXMLRPCDispatcher.system_multicallcCsz|j|}Wnty Yn0|dur2||Std||jdurt|jdrb|j||Szt|j||j}WntyYn0|dur||Std|dS)Nzmethod "%s" is not supportedr;) r"KeyError Exceptionr#rMr;rrr)r(rCrBfuncrrrr;s*     z SimpleXMLRPCDispatcher._dispatch)FNF)F)NN)NN)r. __module__ __qualname__r)r+r-r4r6rIr0r1r2r5r;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-EncodingrR,g?r7)headersgetr aepatternmatchgroupfloat)r(rZaeerfvrrraccept_encodingss  z+SimpleXMLRPCRequestHandler.accept_encodingscCs|jr|j|jvSdSdS)NT) rpc_pathsrAr3rrris_rpc_path_valids z,SimpleXMLRPCRequestHandler.is_rpc_path_validc Cs|s|dSzd}t|jd}g}|rht||}|j|}|sLqh|||t|d8}q,d |}| |}|durWdS|j |t |dd|j}Wnty8}zx|dt|j dr|j jr|dt|t} t| d d d } |d | |d d |WYd}~nd}~00|d|dd|jdurt||jkr|dd} | rzt|}|ddWntyYn0|d tt|||j|dS)Nizcontent-lengthr`r;i_send_traceback_headerz X-exceptionASCIIbackslashreplacez X-tracebackContent-length0 Content-typeztext/xmlgziprzContent-Encoding) rn report_404intrcminZrfilereadrWlenjoindecode_request_contentserverrIrrArZ send_responserMrp send_headerstr traceback format_excr> end_headersencode_thresholdrlrdrNotImplementedErrorwfilewrite) r(Zmax_chunk_sizeZsize_remainingLZ chunk_sizechunkr?rDrjZtraceqrrrdo_POSTs\           z"SimpleXMLRPCRequestHandler.do_POSTcCs|jdd}|dkr|S|dkrrz t|WStyR|dd|Yqtyn|ddYq0n|dd||dd |dS) Nzcontent-encodingZidentityrwizencoding %r not supportedzerror decoding gzip contentrsrt) rcrdlowerrrr ValueErrorrr)r(r?r%rrrr~$s    z1SimpleXMLRPCRequestHandler.decode_request_contentcCsF|dd}|dd|dtt|||j|dS)Nis No such pagervz text/plainrs)rrrr|rrrr(rDrrrrx5s   z%SimpleXMLRPCRequestHandler.report_404-cCs|jjrt|||dSr*)r logRequestsr log_request)r(codesizerrrr>sz&SimpleXMLRPCRequestHandler.log_requestN)rr)r.r\r]rmrZwbufsizeZdisable_nagle_algorithmrecompileVERBOSE IGNORECASErerlrnrr~rxrrrrrr^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_addressrpr^r)rrrrrDs  rc@s<eZdZedddddfddZddZdd Zd d d ZdS) MultiPathXMLRPCServerTFNc Cs2t||||||||i|_||_|p*d|_dSr )rr) dispatchersr$r%rrrrr)hs zMultiPathXMLRPCServer.__init__cCs||j|<|Sr*r)r(rA dispatcherrrradd_dispatcherrs z$MultiPathXMLRPCServer.add_dispatchercCs |j|Sr*r)r(rArrrget_dispatchervsz$MultiPathXMLRPCServer.get_dispatcherc Csz|j||||}Wnftdd\}}z:ttdd||f|j|jd}||jd}Wd}}n d}}0Yn0|S)Nr7r8r9r:) rrIr<r=rrr%r$r>)r(r?r@rArDrFrGrrrrIys z)MultiPathXMLRPCServer._marshaled_dispatch)NN)r.r\r]r^r)rrrIrrrrr`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)rIprintr|r<stdoutflushbufferr)r( request_textrDrrr 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 responseshttprZDEFAULT_ERROR_MESSAGEr>rZDEFAULT_ERROR_CONTENT_TYPEr|r<rrrr)r(rrrrDrrr handle_gets   z"CGIXMLRPCRequestHandler.handle_getc Csx|dur$tjdddkr$|nPzttjdd}WnttfyTd}Yn0|durjtj |}| |dS)NZREQUEST_METHODZGETZCONTENT_LENGTHr`) osenvironrdrryr TypeErrorr<stdinr{r)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) NrzS\b((http|https|ftp)://\S+[\w/]|RFC[- ]?(\d+)|PEP[- ]?(\d+)|(self\.)?((?:\w|\.)+))\b"z"z%sz'http://www.rfc-editor.org/rfc/rfc%d.txtz)https://www.python.org/dev/peps/pep-%04d/r7(zself.%srR) escaperrsearchspanrWgroupsreplaceryZnamelinkr})r(textrr"classesrOrXherepatternrfstartendallZschemeZrfcZpepZselfdotr,Zurlrrrmarkups4      zServerHTMLDoc.markupcCs|r |jp dd|}d} d||||f} t|rHtt|} nd} t|trp|dp`| } |dpld} n t|} | | | o| d| } | | |j |||}|od|}d | |fS) NrRrz$%sz(...)rr7z'%sz
%s
z
%s
%s
) r.rrrr isinstancetuplerSrTZgreyr preformat)r(objectr,modr"rrOZclZanchorZnotetitleZargspecZ docstringZdecldocrrr docroutines(     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#eeaa77rR) itemsrZheadingrrrNrWrZ bigsectionr}) r( server_nameZpackage_documentationrOZfdictkeyvalueheadresultrcontentsZ 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_titler3rrrr):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]}||jvr&|j|}n|jdurddg}t|jdrT|j||d<t|jdrp|j||d<t|}|dkr|}qt|jdszt|j|}Wqty|}Yq0q|}n|||<q t }| |j |j |}| t|j|S)N_get_method_argstringrrQr7)NNr;)r0r"r#rMrrQrrrrrrrZpagehtmlrr)r(rOrPrCZ 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!rurvz text/htmlrs) rnrxrrr>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)rr3rrrr)s z#DocCGIXMLRPCRequestHandler.__init__N)r.r\r]rr)rrrrrsr__main__c@s"eZdZddZGdddZdS)ExampleServicecCsdS)NZ42rr3rrrgetDataszExampleService.getDatac@seZdZeddZdS)zExampleService.currentTimecCs tjSr*)datetimeZnowrrrrgetCurrentTimesz)ExampleService.currentTime.getCurrentTimeN)r.r\r] staticmethodrrrrr currentTimesrN)r.r\r]rrrrrrrsr)Z localhosti@cCs||Sr*r)xyrrrroradd)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<rrrSrZfcntl ImportErrorrrrr^rrrrZHTMLDocrrrrrr.rrrr-powr+r6rZ serve_foreverKeyboardInterruptexitrrrrksf       ,EbQ