
    F\h֏                     T   S r SSKJrJrJrJrJr  SSKJr  SSK	J
r
  SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKr SSKrS(S jrS	 r " S
 S5      r " S S\5      r " S S\R6                  \5      r " S S\5      r " S S\5      r " S S\R>                  5      r  " S S5      r! " S S\5      r" " S S\\!5      r# " S S\\!5      r$\%S:X  a  SSK&r& " S S 5      r'\" S!5       r(\(RS                  \*5        \(RS                  S" S#5        \(RW                  \'" 5       SS$9  \(RY                  5         \-" S%5        \-" S&5         \(R]                  5         SSS5        gg! \ a    Sr GN'f = f! \/ a    \-" S'5        \R`                  " S5         N;f = f! , (       d  f       g= f))a  XML-RPC Servers.

This module can be used to create simple XML-RPC servers
by creating a server and either installing functions, a
class instance, or by extending the SimpleXMLRPCServer
class.

It can also be used to handle XML-RPC requests in a CGI
environment using CGIXMLRPCRequestHandler.

The Doc* classes can be used to create XML-RPC servers that
serve pydoc-style documentation in response to HTTP
GET requests. This documentation is dynamically generated
based on the functions and methods registered with the
server.

A list of possible usage patterns follows:

1. Install functions:

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.serve_forever()

2. Install an instance:

class MyFuncs:
    def __init__(self):
        # make all of the sys functions available through sys.func_name
        import sys
        self.sys = sys
    def _listMethods(self):
        # implement this method so that system.listMethods
        # knows to advertise the sys methods
        return list_public_methods(self) + \
                ['sys.' + method for method in list_public_methods(self.sys)]
    def pow(self, x, y): return pow(x, y)
    def add(self, x, y) : return x + y

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(MyFuncs())
server.serve_forever()

3. Install an instance with custom dispatch method:

class Math:
    def _listMethods(self):
        # this method must be present for system.listMethods
        # to work
        return ['add', 'pow']
    def _methodHelp(self, method):
        # this method must be present for system.methodHelp
        # to work
        if method == 'add':
            return "add(2,3) => 5"
        elif method == 'pow':
            return "pow(x, y[, z]) => number"
        else:
            # By convention, return empty
            # string if no help is available
            return ""
    def _dispatch(self, method, params):
        if method == 'pow':
            return pow(*params)
        elif method == 'add':
            return params[0] + params[1]
        else:
            raise ValueError('bad method')

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(Math())
server.serve_forever()

4. Subclass SimpleXMLRPCServer:

class MathServer(SimpleXMLRPCServer):
    def _dispatch(self, method, params):
        try:
            # We are forcing the 'export_' prefix on methods that are
            # callable through XML-RPC to prevent potential security
            # problems
            func = getattr(self, 'export_' + method)
        except AttributeError:
            raise Exception('method "%s" is not supported' % method)
        else:
            return func(*params)

    def export_add(self, x, y):
        return x + y

server = MathServer(("localhost", 8000))
server.serve_forever()

5. CGI script:

server = CGIXMLRPCRequestHandler()
server.register_function(pow)
server.handle_request()
    )Faultdumpsloadsgzip_encodegzip_decode)BaseHTTPRequestHandler)partial)	signatureNTc                     U(       a  UR                  S5      nOU/nU H2  nUR                  S5      (       a  [        SU-  5      e[        X5      n M4     U $ )a3  resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d

Resolves a dotted attribute name to an object.  Raises
an AttributeError if any attribute in the chain starts with a '_'.

If the optional allow_dotted_names argument is false, dots are not
supported and this function operates similar to getattr(obj, attr).
._z(attempt to access private attribute "%s")split
startswithAttributeErrorgetattr)objattrallow_dotted_namesattrsis        $/usr/lib/python3.13/xmlrpc/server.pyresolve_dotted_attributer   |   s[     

3<< :Q>  #.C  J    c           	          [        U 5       Vs/ s H8  nUR                  S5      (       a  M  [        [        X5      5      (       d  M6  UPM:     sn$ s  snf )zgReturns a list of attribute strings, found in the specified
object, which represent callable attributesr   )dirr   callabler   )r   members     r   list_public_methodsr      sK     "%S 4v((- WS12  4 4 4s   AAAc                   n    \ rS rSrSr  SS jrSS jrSS jrS rS r	SS	 jr
S
 rS rS rS rS rSrg)SimpleXMLRPCDispatcher   a  Mix-in class that dispatches XML-RPC requests.

This class is used to register XML-RPC method handlers
and then to dispatch them. This class doesn't need to be
instanced directly when used by SimpleXMLRPCServer but it
can be instanced when used by the MultiPathXMLRPCServer
Nc                 X    0 U l         S U l        Xl        U=(       d    SU l        X0l        g Nutf-8)funcsinstance
allow_noneencodinguse_builtin_typesselfr'   r(   r)   s       r   __init__SimpleXMLRPCDispatcher.__init__   s'    
$ +G!2r   c                     Xl         X l        g)an  Registers an instance to respond to XML-RPC requests.

Only one instance can be installed at a time.

If the registered instance has a _dispatch method then that
method will be called with the name of the XML-RPC method and
its parameters as a tuple
e.g. instance._dispatch('add',(2,3))

If the registered instance does not have a _dispatch method
then the instance will be searched to find a matching method
and, if found, will be called. Methods beginning with an '_'
are considered private and will not be called by
SimpleXMLRPCServer.

If a registered function matches an XML-RPC request, then it
will be called instead of the registered instance.

If the optional allow_dotted_names argument is true and the
instance does not have a _dispatch method, method names
containing dots are supported and resolved, as long as none of
the name segments start with an '_'.

    *** SECURITY WARNING: ***

    Enabling the allow_dotted_names options allows intruders
    to access your module's global variables and may allow
    intruders to execute arbitrary code on your machine.  Only
    use this option on a secure, closed network.

N)r&   r   )r+   r&   r   s      r   register_instance(SimpleXMLRPCDispatcher.register_instance   s    B !"4r   c                 n    Uc  [        U R                  US9$ Uc  UR                  nXR                  U'   U$ )zRegisters a function to respond to XML-RPC requests.

The optional name argument can be used to set a Unicode name
for the function.
)name)r	   register_function__name__r%   )r+   functionr2   s      r   r3   (SimpleXMLRPCDispatcher.register_function   s>     411==<$$D#

4r   c                 ~    U R                   R                  U R                  U R                  U R                  S.5        g)zxRegisters the XML-RPC introspection methods in the system
namespace.

see http://xmlrpc.usefulinc.com/doc/reserved.html
)zsystem.listMethodszsystem.methodSignaturezsystem.methodHelpN)r%   updatesystem_listMethodssystem_methodSignaturesystem_methodHelpr+   s    r    register_introspection_functions7SimpleXMLRPCDispatcher.register_introspection_functions   s7     	

$2I2I151L1L,0,B,BD 	Er   c                 R    U R                   R                  SU R                  05        g)zqRegisters the XML-RPC multicall method in the system
namespace.

see http://www.xmlrpc.com/discuss/msgReader$1208zsystem.multicallN)r%   r8   system_multicallr<   s    r   register_multicall_functions3SimpleXMLRPCDispatcher.register_multicall_functions   s"     	

-0E0EFGr   c           	          [        XR                  S9u  pEUb	  U" XT5      nOU R                  XT5      nU4n[        USU R                  U R
                  S9nUR                  U R
                  S5      $ ! [         a(  n[        XpR                  U R
                  S9n SnANISnAf[         aC  n[        [        S[        U5      < SU< 35      U R
                  U R                  S9n SnANSnAff = f)	a  Dispatches an XML-RPC method from marshalled (XML) data.

XML-RPC methods are dispatched from the marshalled (XML) data
using the _dispatch method and the result is returned as
marshalled data. For backwards compatibility, a dispatch
function can be provided as an argument (see comment in
SimpleXMLRPCRequestHandler.do_POST) but overriding the
existing method through subclassing is the preferred means
of changing method dispatch behavior.
)r)   N   )methodresponser'   r(   )r'   r(   :r(   r'   xmlcharrefreplace)
r   r)   	_dispatchr   r'   r(   r   BaseExceptiontypeencode)	r+   datadispatch_methodpathparamsmethodresponsefaultexcs	            r   _marshaled_dispatch*SimpleXMLRPCDispatcher._marshaled_dispatch   s    	"4;Q;QRNF **6:>>&9 {HXa(,$--QH t}}.ABB  	5U&*mm5H 	aDIs344??H	s$   AA3 3
C0=B  C0-9C++C0c                 t   [        U R                  R                  5       5      nU R                  b~  [	        U R                  S5      (       a'  U[        U R                  R                  5       5      -  nO<[	        U R                  S5      (       d!  U[        [        U R                  5      5      -  n[        U5      $ )zosystem.listMethods() => ['add', 'subtract', 'multiple']

Returns a list of the methods supported by the server._listMethodsrI   )setr%   keysr&   hasattrrX   r   sorted)r+   methodss     r   r9   )SimpleXMLRPCDispatcher.system_listMethods  s    
 djjoo'(==$ t}}n553t}}99;<< T]]K88324==ABBgr   c                     g)a  system.methodSignature('add') => [double, int, int]

Returns a list describing the signature of the method. In the
above example, the add method takes two integers as arguments
and returns a double result.

This server does NOT support system.methodSignature.zsignatures not supported )r+   method_names     r   r:   -SimpleXMLRPCDispatcher.system_methodSignature)  s     *r   c                    SnXR                   ;   a  U R                   U   nOU R                  bs  [        U R                  S5      (       a  U R                  R                  U5      $ [        U R                  S5      (       d"   [	        U R                  UU R
                  5      nUc  g[        R                  " U5      $ ! [         a     N&f = f)z}system.methodHelp('add') => "Adds two integers together"

Returns a string containing documentation for the specified method.N_methodHelprI    )	r%   r&   r[   rd   r   r   r   pydocgetdoc)r+   ra   rQ   s      r   r;   (SimpleXMLRPCDispatcher.system_methodHelp6  s    
 **$ZZ,F]]&t}}m44}}00== T]]K885 $ + $ 7 7"F ><<'' & s   !B< <
C	C	c                 b   / nU H/  nUS   nUS   n UR                  U R                  XE5      /5        M1     U$ ! [         a3  nUR                  UR                  UR                  S.5         SnAMm  SnAf[
         a/  nUR                  S[        U5      < SU< 3S.5         SnAM  SnAff = f)zsystem.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => [[4], ...]

Allows the caller to package multiple XML-RPC calls into a single
request.

See http://www.xmlrpc.com/discuss/msgReader$1208

methodNamerP   )	faultCodefaultStringNrD   rF   )appendrI   r   rk   rl   rJ   rK   )r+   	call_listresultscallra   rP   rS   rT   s           r   r@   'SimpleXMLRPCDispatcher.system_multicallU  s     D|,K(^F { CDE $   #(??%*%6%68  ! #$04S	3%?A s!   !:
B.(A22B.?$B))B.c                     U R                   U   nUb  U" U6 $ [        SU-  5      e! [         a     Of = fU R                  bq  [	        U R                  S5      (       a  U R                  R                  X5      $  [        U R                  UU R                  5      nUb  U" U6 $ O! [         a     Of = f[        SU-  5      e)a  Dispatches the XML-RPC method.

XML-RPC calls are forwarded to a registered function that
matches the called XML-RPC method name. If no such function
exists then the call is forwarded to the registered instance,
if available.

If the registered instance has a _dispatch method then that
method will be called with the name of the XML-RPC method and
its parameters as a tuple
e.g. instance._dispatch('add',(2,3))

If the registered instance does not have a _dispatch method
then the instance will be searched to find a matching method
and, if found, will be called.

Methods beginning with an '_' are considered private and will
not be called.
zmethod "%s" is not supportedrI   )	r%   	ExceptionKeyErrorr&   r[   rI   r   r   r   )r+   rQ   rP   funcs       r   rI    SimpleXMLRPCDispatcher._dispatcht  s    *	E::f%D V}$:VCDD  		 ==$t}}k22}}..v>>
)/MM++ #=( $ "  6?@@s   ' 
44;!B% %
B21B2)r   r'   r(   r%   r&   r)   FNF)FNN)r4   
__module____qualname____firstlineno____doc__r,   r/   r3   r=   rA   rU   r9   r:   r;   r@   rI   __static_attributes__r`   r   r   r    r       sL     37#(3"5H 	EH!CF$*(>>1Ar   r    c                       \ rS rSrSrSrSrSrSr\	R                  " S\	R                  \	R                  -  5      rS rS	 rS
 rS rS rSS jrSrg)SimpleXMLRPCRequestHandleri  zwSimple XML-RPC request handler class.

Handles all HTTP POST requests and attempts to decode them as
XML-RPC requests.
)/z/RPC2
/pydoc.cssix  Tz
                            \s* ([^\s;]+) \s*            #content-coding
                            (;\s* q \s*=\s* ([0-9\.]+))? #q
                            c                 *   0 nU R                   R                  SS5      nUR                  S5       H_  nU R                  R	                  U5      nU(       d  M'  UR                  S5      nU(       a  [        U5      OSnXQUR                  S5      '   Ma     U$ )NzAccept-Encodingre   ,   g      ?rD   )headersgetr   	aepatternmatchgroupfloat)r+   raeer   vs         r   accept_encodings+SimpleXMLRPCRequestHandler.accept_encodings  sz    \\/4#ANN((+EuKKN !E!Hs$%%++a.!  r   c                 X    U R                   (       a  U R                  U R                   ;   $ g)NT)	rpc_pathsrO   r<   s    r   is_rpc_path_valid,SimpleXMLRPCRequestHandler.is_rpc_path_valid  s!    >>99.. r   c                    U R                  5       (       d  U R                  5         g Sn[        U R                  S   5      n/ nU(       aY  [	        X!5      nU R
                  R                  U5      nU(       d  O+UR                  U5        U[        US   5      -  nU(       a  MY  SR                  U5      nU R                  U5      nUc  gU R                  R                  U[        U SS5      U R                  5      nU R                  S5        U R!                  SS	5        U R"                  b^  [        U5      U R"                  :  aE  U R%                  5       R'                  S
S5      nU(       a   [)        U5      nU R!                  SS
5        U R!                  S[-        [        U5      5      5        U R/                  5         U R0                  R3                  U5        g! [*         a     N\f = f! [4         a  n	U R                  S5        [7        U R                  S5      (       ay  U R                  R8                  (       a^  U R!                  S[-        U	5      5        [:        R<                  " 5       n
[-        U
R?                  SS5      S5      n
U R!                  SU
5        U R!                  SS5        U R/                  5          Sn	A	gSn	A	ff = f)zHandles the HTTP POST request.

Attempts to interpret all HTTP POST requests as XML-RPC calls,
which are forwarded to the server's _dispatch method for handling.
Ni   zcontent-lengthr   r   rI      Content-typeztext/xmlgzipr   zContent-EncodingContent-lengthi  _send_traceback_headerzX-exceptionASCIIbackslashreplacezX-traceback0) r   
report_404intr   minrfilereadrm   lenjoindecode_request_contentserverrU   r   rO   send_responsesend_headerencode_thresholdr   r   r   NotImplementedErrorstrend_headerswfilewriters   r[   r   	traceback
format_excrL   )r+   max_chunk_sizesize_remainingL
chunk_sizechunkrM   rR   qr   traces              r   do_POST"SimpleXMLRPCRequestHandler.do_POST  sS    %%''OO9	'
 *N .>!?@NA  @



3#ae*, !. 88A;D..t4D| {{66'$T:DIIH$ s#^Z8$$0x=4#8#88--/33FA>A!'28'<H ,,-?H -s3x=/ABJJX&	  3 ! !1  	s# t{{$<==KK66  A7!,,.ELL2DEwO  6-s3	s7   A:G* $%G* 
2G* -G 
G'&G'*
K4CK  Kc                 ~   U R                   R                  SS5      R                  5       nUS:X  a  U$ US:X  a   [        U5      $ U R                  SSU-  5        U R                  SS	5        U R                  5         g ! [         a    U R                  SSU-  5         ND[         a    U R                  SS5         Naf = f)
Nzcontent-encodingidentityr   i  zencoding %r not supported  zerror decoding gzip contentr   r   )	r   r   lowerr   r   r   
ValueErrorr   r   )r+   rM   r(   s      r   r   1SimpleXMLRPCRequestHandler.decode_request_content  s    <<##$6
CIIKz!KvG"4(( s$?($JK)3/ ' P""3(Ch(NO G""3(EFGs   
A= =B<B<;B<c                     U R                  S5        SnU R                  SS5        U R                  S[        [        U5      5      5        U R	                  5         U R
                  R                  U5        g )Ni  s   No such pager   z
text/plainr   )r   r   r   r   r   r   r   r+   rR   s     r   r   %SimpleXMLRPCRequestHandler.report_404*  s]    3"6)3s8}+=>

"r   c                 j    U R                   R                  (       a  [        R                  " XU5        gg)z$Selectively log an accepted request.N)r   logRequestsr   log_request)r+   codesizes      r   r   &SimpleXMLRPCRequestHandler.log_request3  s&     ;;"""..t4@ #r   r`   N)-r   )r4   ry   rz   r{   r|   r   r   wbufsizedisable_nagle_algorithmrecompileVERBOSE
IGNORECASEr   r   r   r   r   r   r   r}   r`   r   r   r   r     sk     -I  H" 

   "$bmm!;=I
	E'N"#Ar   r   c                   6    \ rS rSrSrSrSr\SSSSS4S jrSr	g)SimpleXMLRPCServeri9  aO  Simple XML-RPC server.

Simple XML-RPC server that allows functions and a single instance
to be installed to handle requests. The default implementation
attempts to dispatch XML-RPC calls to the functions or instance
installed in the server. Override the _dispatch method inherited
from SimpleXMLRPCDispatcher to change this behavior.
TFNc                 |    X0l         [        R                  XXW5        [        R                  R                  XX&5        g N)r   r    r,   socketserver	TCPServerr+   addrrequestHandlerr   r'   r(   bind_and_activater)   s           r   r,   SimpleXMLRPCServer.__init__L  s0     '''(V''NVr   )r   )
r4   ry   rz   r{   r|   allow_reuse_addressr   r   r,   r}   r`   r   r   r   r   9  s,      #,F!ed#'5Wr   r   c                   D    \ rS rSrSr\SSSSS4S jrS rS rSS	 jr	S
r
g)MultiPathXMLRPCServeriU  aD  Multipath XML-RPC Server
This specialization of SimpleXMLRPCServer allows the user to create
multiple Dispatcher instances and assign them to different
HTTP request paths.  This makes it possible to run two or more
'virtual XML-RPC servers' at the same port.
Make sure that the requestHandler accepts the paths in question.
TFNc           
      p    [         R                  XX#UXVU5        0 U l        X@l        U=(       d    SU l        g r#   )r   r,   dispatchersr'   r(   r   s           r   r,   MultiPathXMLRPCServer.__init__]  s8     	##DZ$,AR	T$ +Gr   c                 "    X R                   U'   U$ r   r   )r+   rO   
dispatchers      r   add_dispatcher$MultiPathXMLRPCServer.add_dispatcherg  s    !+r   c                      U R                   U   $ r   r   )r+   rO   s     r   get_dispatcher$MultiPathXMLRPCServer.get_dispatcherk  s    %%r   c           	           U R                   U   R                  XU5      nU$ ! [         a`  n[        [	        S[        U5      < SU< 35      U R                  U R                  S9nUR                  U R                  S5      n S nAU$ S nAff = f)NrD   rF   rG   rH   )	r   rU   rJ   r   r   rK   r(   r'   rL   )r+   rM   rN   rO   rR   rT   s         r   rU   )MultiPathXMLRPCServer._marshaled_dispatchn  s    
	K''-AAd,H   	K aDIs344??DH  t}}6IJH	Ks   # 
BABB)r'   r   r(   rx   )r4   ry   rz   r{   r|   r   r,   r   r   rU   r}   r`   r   r   r   r   U  s-     -G!ed#'5,&r   r   c                   8    \ rS rSrSrS	S jrS rS rS
S jrSr	g)CGIXMLRPCRequestHandleri|  z3Simple handler for XML-RPC data passed through CGI.Nc                 0    [         R                  XX#5        g r   )r    r,   r*   s       r   r,    CGIXMLRPCRequestHandler.__init__  s    ''(Vr   c                 \   U R                  U5      n[        S5        [        S[        U5      -  5        [        5         [        R                  R                  5         [        R                  R                  R                  U5        [        R                  R                  R                  5         g)zHandle a single XML-RPC requestzContent-Type: text/xmlContent-Length: %dN)rU   printr   sysstdoutflushbufferr   )r+   request_textrR   s      r   handle_xmlrpc%CGIXMLRPCRequestHandler.handle_xmlrpc  sr     ++L9&'"S]23



)

!r   c                     Sn[         R                  U   u  p#[        R                  R                  UUUS.-  nUR                  S5      n[        SX4-  5        [        S[        R                  R                  -  5        [        S[        U5      -  5        [        5         [        R                  R                  5         [        R                  R                  R                  U5        [        R                  R                  R                  5         g)zsHandle a single HTTP GET request.

Default implementation indicates an error because
XML-RPC uses the POST method.
r   )r   messageexplainr$   zStatus: %d %szContent-Type: %sr   N)r   	responseshttpr   DEFAULT_ERROR_MESSAGErL   r   DEFAULT_ERROR_CONTENT_TYPEr   r   r   r   r   r   )r+   r   r   r   rR   s        r   
handle_get"CGIXMLRPCRequestHandler.handle_get  s     1;;DA;;44   ??7+o/0 4;;#I#IIJ"S]23



)

!r   c                 ^   Uc5  [         R                  R                  SS5      S:X  a  U R                  5         g [	        [         R                  R                  SS5      5      nUc  [        R                  R                  U5      nU R                  U5        g! [
        [        4 a    Sn NHf = f)zHandle a single XML-RPC request passed through a CGI post method.

If no XML data is given then it is read from stdin. The resulting
XML-RPC response is printed to stdout along with the correct HTTP
headers.
NREQUEST_METHODGETCONTENT_LENGTHr   )osenvironr   r  r   r   	TypeErrorr   stdinr   r   )r+   r   lengths      r   handle_request&CGIXMLRPCRequestHandler.handle_request  s     JJNN+T2e;OORZZ^^,<dCD #"yy~~f5|, 	* s   )B B,+B,r`   rw   r   )
r4   ry   rz   r{   r|   r,   r   r  r  r}   r`   r   r   r   r   |  s    =W
""2-r   r   c                   J    \ rS rSrSrS0 0 0 4S jrS0 0 0 S4S jrS rS rSr	g)	ServerHTMLDoci  z7Class used to generate pydoc HTML document for a serverNc                    U=(       d    U R                   n/ nSn[        R                  " S5      nUR                  X5      =n	(       Gan  U	R	                  5       u  pUR                  U" XU
 5      5        U	R                  5       u  ppnnU(       a3  U" U5      R                  SS5      nUR                  SU< SU< S35        OU(       a/  S[        U5      -  nUR                  SU< SU" U5      < S35        OU(       a/  S	[        U5      -  nUR                  SU< SU" U5      < S35        OkXUS
-    S:X  a#  UR                  U R                  UXSU5      5        O=U(       a  UR                  SU-  5        O!UR                  U R                  UU5      5        UnUR                  X5      =n	(       a  GMn  UR                  U" XS 5      5        SR                  U5      $ )z{Mark up some plain text, given a context of symbols to look for.
Each context dictionary maps object names to anchor names.r   zS\b((http|https|ftp)://\S+[\w/]|RFC[- ]?(\d+)|PEP[- ]?(\d+)|(self\.)?((?:\w|\.)+))\b"z&quot;z	<a href="z">z</a>z(https://www.rfc-editor.org/rfc/rfc%d.txtz!https://peps.python.org/pep-%04d/rD   (zself.<strong>%s</strong>Nre   )escaper   r   searchspanrm   groupsreplacer   namelinkr   )r+   textr  r%   classesr]   ro   herepatternr   startendallschemerfcpepselfdotr2   urls                      r   markupServerHTMLDoc.markup  s    &4;; ** < = ~~d11e1JENN6$E"23438<<>0C7DSk))#x8SAB@3s8KVC[IJ9CHDVC[IJ#a%C't}}T77KL9D@At}}T7;<D) ~~d11e11* 	vd5k*+wwwr   c                 .   U=(       a    UR                   =(       d    SS-   U-   nSn	SU R                  U5      < SU R                  U5      < S3n
[        U5      (       a  [        [	        U5      5      nOSn[        U[        5      (       a  US   =(       d    UnUS   =(       d    SnO[        R                  " U5      nX-   U	=(       a    U R                  S	U	-  5      -   nU R                  XR                  XEU5      nU=(       a    S
U-  nSU< SU< S3$ )z;Produce HTML documentation for a function or method object.re   r   z	<a name="z
"><strong>z</strong></a>z(...)r   rD   z'<font face="helvetica, arial">%s</font>z<dd><tt>%s</tt></dd>z<dl><dt>z</dt>z</dl>
)r4   r  r   r   r
   
isinstancetuplerf   rg   greyr%  	preformat)r+   objectr2   modr%   r  r]   clanchornotetitleargspec	docstringdecldocs                  r   
docroutineServerHTMLDoc.docroutine  s     $*c1D8 KKT!24 F)F+,GGfe$$Qi*7Gq	RIV,I$ #A49984?,A B kk~~uw@2,s2-1377r   c           	         0 nUR                  5        H  u  pVSU-   XE'   XE   XF'   M     U R                  U5      nSU-  nU R                  U5      nU R                  X R                  U5      n	U	=(       a    SU	-  n	USU	-  -   n/ n
[        UR                  5       5      nU H$  u  pVU
R                  U R                  XeUS95        M&     XR                  SSSR                  U
5      5      -   nU$ )	z1Produce HTML documentation for an XML-RPC server.z#-z)<big><big><strong>%s</strong></big></big>z<tt>%s</tt>z
<p>%s</p>
)r%   Methods	functionsre   )
itemsr  headingr%  r+  r\   rm   r6  
bigsectionr   )r+   server_namepackage_documentationr]   fdictkeyvalueheadresultr5  contentsmethod_itemss               r   	docserverServerHTMLDoc.docserver  s     !--/JCEJ :EL * kk+.:[Hd#kk/G)mc)-#--gmmo.&JCOODOOEeODE '//{BGGH$57 7 r   c                 .    SnSU-  nSU< SU< SU< S3$ )zFormat an HTML page.r   z1<link rel="stylesheet" type="text/css" href="%s">zI<!DOCTYPE>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Python: z	</title>
z</head><body>z</body></html>r`   )r+   r1  rE  css_pathcss_links        r   pageServerHTMLDoc.page"  s,    ? 	 ',XxA 	Ar   r`   )
r4   ry   rz   r{   r|   r%  r6  rG  rL  r}   r`   r   r   r  r    s2    A"&b"b % N ,0R8:4Ar   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
XMLRPCDocGeneratori0  zyGenerates documentation for an XML-RPC server.

This class is designed as mix-in and should not
be constructed directly.
c                 .    SU l         SU l        SU l        g )NzXML-RPC Server DocumentationzGThis server exports the following methods through the XML-RPC protocol.)r>  server_documentationserver_titler<   s    r   r,   XMLRPCDocGenerator.__init__7  s!    9 	! ;r   c                     Xl         g)z8Set the HTML title of the generated server documentationN)rR  )r+   rR  s     r   set_server_title#XMLRPCDocGenerator.set_server_title?  s
     )r   c                     Xl         g)z7Set the name of the generated HTML server documentationN)r>  )r+   r>  s     r   set_server_name"XMLRPCDocGenerator.set_server_nameD  s
     'r   c                     Xl         g)z3Set the documentation string for the entire server.N)rQ  )r+   rQ  s     r   set_server_documentation+XMLRPCDocGenerator.set_server_documentationI  s
     %9!r   c                    0 nU R                  5        H  nX R                  ;   a  U R                  U   nOU R                  b  SS/n[        U R                  S5      (       a  U R                  R	                  U5      US'   [        U R                  S5      (       a  U R                  R                  U5      US'   [        U5      nUS:w  a  UnO=[        U R                  S5      (       d   [        U R                  U5      nO
UnO S5       eX1U'   M     [        5       nUR                  U R                  U R                  U5      nUR                  [        R                  " U R                   5      U5      $ ! [         a    Un Nwf = f)	a  generate_html_documentation() => html documentation for the server

Generates HTML documentation for the server using introspection for
installed functions and instances that do not implement the
_dispatch method. Alternatively, instances can choose to implement
the _get_method_argstring(method_name) method to provide the
argument string used in the documentation and the
_methodHelp(method_name) method to provide the help text used
in the documentation.N_get_method_argstringr   rd   rD   rx   rI   zACould not find method in self.functions and no instance installed)r9   r%   r&   r[   r^  rd   r)  r   r   r  rG  r>  rQ  rL  htmlr  rR  )r+   r]   ra   rQ   method_info
documenterdocumentations          r   generate_html_documentation.XMLRPCDocGenerator.generate_html_documentationN  sc    224Kjj(K0*#Tl4==*ABB%)]]%H%H%UKN4==-88%)]]%>%>{%KKN#K0,.(F <<-!9$(MM$/"& )F/ / /q $*K 7 5: #_
",, $ 0 0 $ 9 9 ' t{{4+<+<=}MM# * -!,-s   (E22F F)rQ  r>  rR  N)r4   ry   rz   r{   r|   r,   rU  rX  r[  rc  r}   r`   r   r   rO  rO  0  s!    ;)
'
9
1Nr   rO  c                   $    \ rS rSrSrS rS rSrg)DocXMLRPCRequestHandleri  zXML-RPC and documentation request handler class.

Handles all HTTP POST requests and attempts to decode them as
XML-RPC requests.

Handles all HTTP GET requests and interprets them as requests
for documentation.
c                 0   [         R                  R                  [         R                  R                  [        5      5      n[         R                  R                  USSS5      n[        USS9 nUR                  5       sS S S 5        $ ! , (       d  f       g = f)Nz..
pydoc_dataz
_pydoc.cssrb)mode)r  rO   dirnamerealpath__file__r   openr   )r+   r$  	path_hererJ  fps        r   _get_css DocXMLRPCRequestHandler._get_css  s\    GGOOBGG$4$4X$>?	77<<	4|L(&"779 '&&s   -B
Bc                    U R                  5       (       d  U R                  5         gU R                  R                  S5      (       a  SnU R	                  U R                  5      nO+SnU R
                  R                  5       R                  S5      nU R                  S5        U R                  SSU-  5        U R                  S	[        [        U5      5      5        U R                  5         U R                  R                  U5        g)
eHandles the HTTP GET request.

Interpret all HTTP GET requests as requests for server
documentation.
Nz.cssztext/cssz	text/htmlr$   r   zContent-Typez%s; charset=UTF-8r   )r   r   rO   endswithrq  r   rc  rL   r   r   r   r   r   r   r   )r+   content_typerR   s      r   do_GETDocXMLRPCRequestHandler.do_GET  s     %%''OO99f%%%L}}TYY/H&L{{>>@GGPH3)<|)KL)3s8}+=>

"r   r`   N)r4   ry   rz   r{   r|   rq  rw  r}   r`   r   r   rf  rf    s    #r   rf  c                   .    \ rS rSrSr\SSSSS4S jrSrg)DocXMLRPCServeri  zXML-RPC and HTML documentation server.

Adds the ability to serve server documentation to the capabilities
of SimpleXMLRPCServer.
TFNc           
      `    [         R                  XX#XEUU5        [        R                  U 5        g r   )r   r,   rO  r   s           r   r,   DocXMLRPCServer.__init__  s/     	##D$.:K$5	7 	##D)r   r`   )r4   ry   rz   r{   r|   rf  r,   r}   r`   r   r   rz  rz    s     -D!ed#'5*r   rz  c                   $    \ rS rSrSrS rS rSrg)DocCGIXMLRPCRequestHandleri  zFHandler for XML-RPC data and documentation requests passed through
CGIc                 x   U R                  5       R                  S5      n[        S5        [        S[        U5      -  5        [        5         [        R
                  R                  5         [        R
                  R                  R                  U5        [        R
                  R                  R                  5         g)rt  r$   zContent-Type: text/htmlr   N)	rc  rL   r   r   r   r   r   r   r   r   s     r   r  %DocCGIXMLRPCRequestHandler.handle_get  s{     335<<WE'("S]23



)

!r   c                 X    [         R                  U 5        [        R                  U 5        g r   )r   r,   rO  r<   s    r   r,   #DocCGIXMLRPCRequestHandler.__init__  s    ((.##D)r   r`   N)r4   ry   rz   r{   r|   r  r,   r}   r`   r   r   r~  r~    s    " *r   r~  __main__c                   .    \ rS rSrS r " S S5      rSrg)ExampleServicei  c                     g)N42r`   r<   s    r   getDataExampleService.getData  s    r   c                   $    \ rS rSr\S 5       rSrg)ExampleService.currentTimei  c                  >    [         R                   R                  5       $ r   )datetimenowr`   r   r   getCurrentTime)ExampleService.currentTime.getCurrentTime  s    ((,,..r   r`   N)r4   ry   rz   r{   staticmethodr  r}   r`   r   r   currentTimer    s    / /r   r  r`   N)r4   ry   rz   r{   r  r  r}   r`   r   r   r  r    s    		/ 	/r   r  )	localhosti@  c                 
    X-   $ r   r`   )xys     r   <lambda>r    s    QSr   add)r   z&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)1r|   xmlrpc.clientr   r   r   r   r   http.serverr   	functoolsr	   inspectr
   r_  r   r   r   r  r   rf   r   fcntlImportErrorr   r   r    r   r   r   r   r   HTMLDocr  rO  rf  rz  r~  r4   r  r  r   r3   powr/   rA   r   serve_foreverKeyboardInterruptexitr`   r   r   <module>r     s  eT H G .      
 	 	  04IA IAVPA!7 PAdW///W8%. %N?-4 ?-JmAEMM mA^ON ONb&#8 &#P**** *$;$6*4 z/ / 
/	0F  %  %8  !1d K++-67[\	  " 
1	0 u  E^ ! 	;<HHQK	 
1	0s=   E$ /AF
E3$E0/E03 FFFF
F'