AlkantarClanX12

Your IP : 3.16.137.229


Current Path : /proc/self/root/opt/alt/python311/lib64/python3.11/xmlrpc/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python311/lib64/python3.11/xmlrpc/__pycache__/server.cpython-311.pyc

�

c��f�����dZddlmZmZmZmZmZddlmZddl	m
Z
ddlmZddl
Z
ddlZddlZddlZddlZddlZddlZddlZ	ddlZn
#e$rdZYnwxYwd(d�Zd	�ZGd
�d��ZGd�d
e��ZGd�deje��ZGd�de��ZGd�de��ZGd�dej��Z Gd�d��Z!Gd�de��Z"Gd�dee!��Z#Gd�dee!��Z$e%dkr�ddl&Z&Gd�d ��Z'ed!��5Z(e(�)e*��e(�)d"�d#��e(�+e'��d�$��e(�,��e-d%��e-d&��	e(�.��n&#e/$re-d'��ej0d��YnwxYwddd��dS#1swxYwYdSdS))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��|r|�d��}n|g}|D]9}|�d��rtd|z���t||��}�:|S)aGresolve_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     �4/opt/alt/python311/lib64/python3.11/xmlrpc/server.py�resolve_dotted_attributer|sw�����
�
�3��������
�!�!���<�<����	!� �:�Q�>���
��#�a�.�.�C�C��J�c�:���fd�t���D��S)zkReturns a list of attribute strings, found in the specified
    object, which represent callable attributesc�x��g|]6}|�d���tt�|�����4|��7S)r
)r�callabler)�.0�memberrs  �r�
<listcomp>z'list_public_methods.<locals>.<listcomp>�sU���4�4�4�v��(�(��-�-�4��W�S�&�1�1�2�2�4�F�4�4�4r)�dir)rs`r�list_public_methodsr!�s3���4�4�4�4��S���4�4�4�4rc�`�eZdZdZ		dd�Zdd�Zdd�Zd�Zd�Zdd	�Z	d
�Z
d�Zd�Zd
�Z
d�ZdS)�SimpleXMLRPCDispatchera&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
    FNc�P�i|_d|_||_|pd|_||_dS�N�utf-8)�funcs�instance�
allow_none�encoding�use_builtin_types��selfr)r*r+s    r�__init__zSimpleXMLRPCDispatcher.__init__�s1����
���
�$��� �+�G��
�!2����rc�"�||_||_dS)aRegisters 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(rs   r�register_instancez(SimpleXMLRPCDispatcher.register_instance�s��B!��
�"4����rc�\�|�t|j|���S|�|j}||j|<|S)z�Registers a function to respond to XML-RPC requests.

        The optional name argument can be used to set a Unicode name
        for the function.
        N)�name)r	�register_function�__name__r')r-�functionr2s   rr3z(SimpleXMLRPCDispatcher.register_function�s>�����4�1��=�=�=�=��<��$�D�#��
�4���rc�`�|j�|j|j|jd���dS)z�Registers the XML-RPC introspection methods in the system
        namespace.

        see http://xmlrpc.usefulinc.com/doc/reserved.html
        )zsystem.listMethodszsystem.methodSignaturezsystem.methodHelpN)r'�update�system_listMethods�system_methodSignature�system_methodHelp�r-s r� register_introspection_functionsz7SimpleXMLRPCDispatcher.register_introspection_functions�sJ��	
�
���$�2I�15�1L�,0�,B�D�D�	E�	E�	E�	E�	Erc�H�|j�d|ji��dS)z�Registers the XML-RPC multicall method in the system
        namespace.

        see http://www.xmlrpc.com/discuss/msgReader$1208zsystem.multicallN)r'r7�system_multicallr;s r�register_multicall_functionsz3SimpleXMLRPCDispatcher.register_multicall_functions�s)��	
�
���-��0E�F�G�G�G�G�Grc	��	t||j���\}}|�
|||��}n|�||��}|f}t|d|j|j���}n�#t$r&}t||j|j���}Yd}~nVd}~wt$rF}tt
dt|���d|����|j|j���}Yd}~nd}~wwxYw|�	|jd��S)	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)
rr+�	_dispatchrr)r*r�
BaseException�type�encode)	r-�data�dispatch_method�path�params�method�response�fault�excs	         r�_marshaled_dispatchz*SimpleXMLRPCDispatcher._marshaled_dispatch�s7��	�"�4�4�;Q�R�R�R�N�F�F��*�*�?�6�6�:�:����>�>�&�&�9�9�� �{�H��X�a�(,��$�-�Q�Q�Q�H�H���	5�	5�	5��U�t��&*�m�5�5�5�H�H�H�H�H�H������	�	�	���a�D��I�I�I�I�s�s�3�4�4���4�?����H�H�H�H�H�H�����	�������t�}�.A�B�B�Bs$�AA!�!
C�+B�
C�<C�Cc�j�t|j�����}|j�xt	|jd��r*|t|j�����z}n9t	|jd��s$|tt
|j����z}t|��S)zwsystem.listMethods() => ['add', 'subtract', 'multiple']

        Returns a list of the methods supported by the server.N�_listMethodsrF)�setr'�keysr(�hasattrrTr!�sorted)r-�methodss  rr8z)SimpleXMLRPCDispatcher.system_listMethodss���
�d�j�o�o�'�'�(�(���=�$��t�}�n�5�5�
C��3�t�}�9�9�;�;�<�<�<����T�]�K�8�8�
C��3�2�4�=�A�A�B�B�B���g���rc��dS)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.zsignatures not supported�)r-�method_names  rr9z-SimpleXMLRPCDispatcher.system_methodSignature)s
��*�)rc�T�d}||jvr|j|}nx|j�qt|jd��r|j�|��St|jd��s-	t	|j||j��}n#t$rYnwxYw|�dStj|��S)z�system.methodHelp('add') => "Adds two integers together"

        Returns a string containing documentation for the specified method.N�_methodHelprF�)	r'r(rWr^rrr�pydoc�getdoc)r-r\rNs   rr:z(SimpleXMLRPCDispatcher.system_methodHelp6s���
���$�*�$�$��Z��,�F�F�
�]�
&��t�}�m�4�4�
��}�0�0��=�=�=��T�]�K�8�8�
��5� $�
� +� $� 7�"�"�F�F��
&�����D�����
�>��2��<��'�'�'s�&B�
B�Bc�t�g}|D]�}|d}|d}	|�|�||��g���>#t$r,}|�|j|jd���Yd}~�od}~wt
$r4}|�dt
|���d|��d���Yd}~��d}~wwxYw|S)z�system.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
        �
methodNamerM)�	faultCode�faultStringNrArC)�appendrFrrdrerGrH)r-�	call_list�results�callr\rMrPrQs        rr>z'SimpleXMLRPCDispatcher.system_multicallUs,�����	�	�D��|�,�K��(�^�F�

�������{�F� C� C�D�E�E�E�E���
�
�
����#(�?�%*�%6�8�8�������������!�
�
�
����#$�04�S�	�	�	�	�3�3�%?�A�A�������������
����
�s#�*A�
B5�
"A4�4
B5�*B0�0B5c�j�	|j|}|�||�Std|z���#t$rYnwxYw|j�dt	|jd��r|j�||��S	t
|j||j��}|�||�Sn#t$rYnwxYwtd|z���)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.
        Nzmethod "%s" is not supportedrF)	r'�	Exception�KeyErrorr(rWrFrrr)r-rNrM�funcs    rrFz SimpleXMLRPCDispatcher._dispatchts��*	E��:�f�%�D����t�V�}�$��:�V�C�D�D�D���	�	�	��D�	�����=�$��t�}�k�2�2�
?��}�.�.�v�v�>�>�>�

)�/��M���+�����#��4��=�(�$��"�
�
�
���
�����6��?�@�@�@s�
(�
5�5�0B�
B �B �FNF)F�NN)r4�
__module__�__qualname__�__doc__r.r0r3r<r?rRr8r9r:r>rFr[rrr#r#�s���������37�#(�3�3�3�3�"5�"5�"5�"5�H���� 	E�	E�	E�H�H�H�!C�!C�!C�!C�F���$*�*�*�(�(�(�>���>1A�1A�1A�1A�1Arr#c��eZdZdZdZdZdZdZej	dej
ejz��Zd�Z
d�Zd	�Zd
�Zd�Zdd
�ZdS)�SimpleXMLRPCRequestHandlerz�Simple 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�(�i}|j�dd��}|�d��D]^}|j�|��}|r@|�d��}|rt
|��nd}|||�d��<�_|S)NzAccept-Encodingr_�,�g�?rA)�headers�getr�	aepattern�match�group�float)r-�r�ae�er~�vs      r�accept_encodingsz+SimpleXMLRPCRequestHandler.accept_encodings�s�����
�\�
�
�/��
4�
4�����#���	&�	&�A��N�(�(��+�+�E��
&��K�K��N�N�� !�*�E�!�H�H�H�s��$%��%�+�+�a�.�.�!���rc�0�|jr|j|jvSdS)NT)�	rpc_pathsrLr;s r�is_rpc_path_validz,SimpleXMLRPCRequestHandler.is_rpc_path_valid�s"���>�	��9���.�.��4rc���|���s|���dS	d}t|jd��}g}|r\t	||��}|j�|��}|sn/|�|��|t|d��z}|�\d�	|��}|�
|��}|�dS|j�|t|dd��|j��}|�d��|�dd	��|j�yt|��|jkra|����d
d��}|r7	t)|��}|�dd
��n#t*$rYnwxYw|�d
t-t|������|���|j�|��dS#t4$r�}	|�d��t7|jd��r||jjrp|�dt-|	����t;j��}
t-|
�dd��d��}
|�d|
��|�d
d��|���Yd}	~	dSd}	~	wwxYw)z�Handles 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�zcontent-lengthrwrrF���Content-typeztext/xml�gziprzContent-Encoding�Content-lengthi��_send_traceback_headerzX-exception�ASCII�backslashreplacezX-traceback�0) r��
report_404�intr{�min�rfile�readrf�len�join�decode_request_content�serverrRrrL�
send_response�send_header�encode_thresholdr�r|r�NotImplementedError�str�end_headers�wfile�writerkrWr��	traceback�
format_excrI)r-�max_chunk_size�size_remaining�L�
chunk_size�chunkrJrO�qr��traces           r�do_POSTz"SimpleXMLRPCRequestHandler.do_POST�s���%�%�'�'�	��O�O�����F�9	'�
*�N� ���.>�!?�@�@�N��A� �
-� ���@�@�
��
���
�3�3�������������#�a��e�*�*�,��
!�
-��8�8�A�;�;�D��.�.�t�4�4�D��|����{�6�6��'�$��T�:�:�D�I���H�$
���s�#�#�#����^�Z�8�8�8��$�0��x�=�=�4�#8�8�8��-�-�/�/�3�3�F�A�>�>�A��!�!�'2�8�'<�'<�H� �,�,�-?��H�H�H�H��2�!�!�!� �D�!�������-�s�3�x�=�=�/A�/A�B�B�B��������J���X�&�&�&�&�&��9�
	�
	�
	����s�#�#�#��t�{�$<�=�=�
7��K�6�
7�� � ���A���7�7�7�!�,�.�.���E�L�L��2D�E�E�w�O�O��� � ���6�6�6����-�s�3�3�3�����������������
	���s1�B(H�0H�;%F!�!
F.�-F.�
K6�CK1�1K6c��|j�dd�����}|dkr|S|dkrZ	t|��S#t$r|�dd|z��Yn>t$r|�dd��YnwxYw|�dd|z��|�dd	��|���dS)
Nzcontent-encoding�identityr�i�zencoding %r not supported�zerror decoding gzip contentr�r�)	r{r|�lowerrr�r��
ValueErrorr�r�)r-rJr*s   rr�z1SimpleXMLRPCRequestHandler.decode_request_contents���<�#�#�$6�
�C�C�I�I�K�K���z�!�!��K��v���
G�"�4�(�(�(��&�
P�
P�
P��"�"�3�(C�h�(N�O�O�O�O�O��
G�
G�
G��"�"�3�(E�F�F�F�F�F�
G����
���s�$?�(�$J�K�K�K����)�3�/�/�/��������s�A�#B�1B�Bc��|�d��d}|�dd��|�dtt|������|���|j�|��dS)Ni�sNo such pager�z
text/plainr�)r�r�r�r�r�r�r��r-rOs  rr�z%SimpleXMLRPCRequestHandler.report_404*s������3����"�������6�6�6����)�3�s�8�}�}�+=�+=�>�>�>��������
����"�"�"�"�"r�-c�N�|jjrtj|||��dSdS)z$Selectively log an accepted request.N)r��logRequestsr�log_request)r-�code�sizes   rr�z&SimpleXMLRPCRequestHandler.log_request3s9���;�"�	A�"�.�t�T�4�@�@�@�@�@�	A�	ArN)r�r�)r4rprqrrr�r��wbufsize�disable_nagle_algorithm�re�compile�VERBOSE�
IGNORECASEr}r�r�r�r�r�r�r[rrrtrt�s���������-�I����H�"����
� �"$��b�m�!;�=�=�I�
	�	�	����E'�E'�E'�N���"#�#�#�A�A�A�A�A�Arrtc�.�eZdZdZdZdZedddddfd�ZdS)�SimpleXMLRPCServeragSimple 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��||_t�||||��tj�||||��dS�N)r�r#r.�socketserver�	TCPServer�r-�addr�requestHandlerr�r)r*�bind_and_activater+s        rr.zSimpleXMLRPCServer.__init__LsK��'����'�'��j�(�DU�V�V�V���'�'��d�N�DU�V�V�V�V�Vr)r4rprqrr�allow_reuse_addressr�rtr.r[rrr�r�9sW����������#��,F�!�e�d�#'�5�W�W�W�W�W�Wrr�c�:�eZdZdZedddddfd�Zd�Zd�Zd	d�ZdS)
�MultiPathXMLRPCServera\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
�v�t�||||||||��i|_||_|pd|_dSr%)r�r.�dispatchersr)r*r�s        rr.zMultiPathXMLRPCServer.__init__]sQ��	�#�#�D�$���Z�$,�.?�AR�	T�	T�	T����$��� �+�G��
�
�
rc��||j|<|Sr��r�)r-rL�
dispatchers   r�add_dispatcherz$MultiPathXMLRPCServer.add_dispatchergs��!+������rc��|j|Sr�r�)r-rLs  r�get_dispatcherz$MultiPathXMLRPCServer.get_dispatcherks�����%�%rc	�*�	|j|�|||��}nn#t$ra}tt	dt|���d|����|j|j���}|�|jd��}Yd}~nd}~wwxYw|S)NrArCrDrE)	r�rRrGrrrHr*r)rI)r-rJrKrLrOrQs      rrRz)MultiPathXMLRPCServer._marshaled_dispatchns���
	K��'��-�A�A��_�d�,�,�H�H���	K�	K�	K���a�D��I�I�I�I�s�s�3�4�4���4�?�D�D�D�H� ���t�}�6I�J�J�H�H�H�H�H�H�����	K�����s�"%�
B�AB�Bro)	r4rprqrrrtr.r�r�rRr[rrr�r�Usv��������-G�!�e�d�#'�5�,�,�,�,����&�&�&������rr�c�.�eZdZdZdd�Zd�Zd�Zd	d�ZdS)
�CGIXMLRPCRequestHandlerz3Simple handler for XML-RPC data passed through CGI.FNc�@�t�||||��dSr�)r#r.r,s    rr.z CGIXMLRPCRequestHandler.__init__s#���'�'��j�(�DU�V�V�V�V�Vrc�r�|�|��}td��tdt|��z��t��tj���tjj�|��tjj���dS)zHandle a single XML-RPC requestzContent-Type: text/xml�Content-Length: %dN)rR�printr��sys�stdout�flush�bufferr�)r-�request_textrOs   r�
handle_xmlrpcz%CGIXMLRPCRequestHandler.handle_xmlrpc�s����+�+�L�9�9��
�&�'�'�'�
�"�S��]�]�2�3�3�3�
�����
�������
�����)�)�)��
����!�!�!�!�!rc��d}tj|\}}tjj|||d�z}|�d��}t
d||fz��t
dtjjz��t
dt|��z��t
��tj
���tj
j�
|��tj
j���dS)z�Handle a single HTTP GET request.

        Default implementation indicates an error because
        XML-RPC uses the POST method.
        r�)r��message�explainr&z
Status: %d %szContent-Type: %sr�N)r�	responses�httpr��DEFAULT_ERROR_MESSAGErIr��DEFAULT_ERROR_CONTENT_TYPEr�r�r�r�r�r�)r-r�r�r�rOs     r�
handle_getz"CGIXMLRPCRequestHandler.handle_get�s�����1�;�D�A�����;�4�� � �
�
����?�?�7�+�+��
�o��w��/�0�0�0�
� �4�;�#I�I�J�J�J�
�"�S��]�]�2�3�3�3�
�����
�������
�����)�)�)��
����!�!�!�!�!rc�z�|�:tj�dd��dkr|���dS	t	tj�dd����}n#t
tf$rd}YnwxYw|�tj�	|��}|�
|��dS)z�Handle 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_LENGTHrw)�os�environr|r�r�r��	TypeErrorr��stdinr�r�)r-r��lengths   r�handle_requestz&CGIXMLRPCRequestHandler.handle_request�s������J�N�N�+�T�2�2�e�;�;��O�O������
��R�Z�^�^�,<�d�C�C�D�D�����	�*�
�
�
�����
�����#�"�y�~�~�f�5�5�����|�,�,�,�,�,s�-A,�,B�Brnr�)r4rprqrrr.r�r�r�r[rrr�r�|sd������=�=�W�W�W�W�
"�
"�
"�"�"�"�2-�-�-�-�-�-rr�c�@�eZdZdZdiiifd�Zdiiidfd�Zd�Zd�ZdS)�
ServerHTMLDocz7Class used to generate pydoc HTML document for a serverNc��|p|j}g}d}tjd��}	|�||��}	|	s�n�|	���\}
}|�||||
�����|	���\}}
}}}}|
r<||���dd��}|�d|�d|�d���n�|r8d	t|��z}|�d|�d||���d���n�|r8d
t|��z}|�d|�d||���d���n�|||dz�dkr,|�|�	||||����nD|r|�d|z��n)|�|�	||����|}���|�|||d
�����d�
|��S)z�Mark up some plain text, given a context of symbols to look for.
        Each context dictionary maps object names to anchor names.rzS\b((http|https|ftp)://\S+[\w/]|RFC[- ]?(\d+)|PEP[- ]?(\d+)|(self\.)?((?:\w|\.)+))\brA�"z&quot;z	<a href="z">z</a>z(https://www.rfc-editor.org/rfc/rfc%d.txtz!https://peps.python.org/pep-%04d/�(zself.<strong>%s</strong>Nr_)�escaper�r��search�spanrf�groups�replacer��namelinkr�)r-�textr�r'�classesrYrh�here�patternr~�start�end�all�scheme�rfc�pep�selfdotr2�urls                   r�markupzServerHTMLDoc.markup�s6���&�4�;�������*�<�=�=��	��N�N�4��.�.�E���%������J�E�3��N�N�6�6�$�t�E�z�"2�3�3�4�4�4�38�<�<�>�>�0�C���c�7�D��
=��f�S�k�k�)�)�#�x�8�8���������S�S�S�A�B�B�B�B��
=�@�3�s�8�8�K���������V�V�C�[�[�[�[�I�J�J�J�J��
=�9�C��H�H�D���������V�V�C�[�[�[�[�I�J�J�J�J��c�#�a�%�i��C�'�'����t�}�}�T�7�E�7�K�K�L�L�L�L��
=����9�D�@�A�A�A�A����t�}�}�T�7�;�;�<�<�<��D�-	�.	���v�v�d�4�5�5�k�*�*�+�+�+��w�w�w���rc��|r|jpddz|z}d}	d|�|���d|�|���d�}
t|��rtt	|����}nd}t|t��r|dp|}|dpd}ntj|��}|
|z|	o|�	d	|	z��z}
|�
||j|||��}|od
|z}d|
�d|�d
�S)z;Produce HTML documentation for a function or method object.r_r�z	<a name="z
"><strong>z
</strong></a>z(...)rrAz'<font face="helvetica, arial">%s</font>z<dd><tt>%s</tt></dd>z<dl><dt>z</dt>z</dl>
)r4r�rr�r
�
isinstance�tupler`ra�greyr�	preformat)r-�objectr2�modr'rrY�cl�anchor�note�title�argspec�	docstring�decl�docs               r�
docroutinezServerHTMLDoc.docroutine�s>���$���*��c�1�D�8�����
�K�K���������T�!2�!2�!2�!2�4���F���	��)�F�+�+�,�,�G�G��G��f�e�$�$�	-��Q�i�*�7�G��q�	��R�I�I���V�,�,�I��w��$�#A�4�9�9�8�4�?�,A�,A�B���k�k��t�~�u�g�w�@�@���2�,�s�2���-1�T�T�3�3�3�7�7rc��i}|���D]\}}d|z||<||||<�|�|��}d|z}|�|��}|�||j|��}	|	od|	z}	|d|	zz}g}
t|�����}|D]0\}}|
�|�|||������1||�ddd�	|
����z}|S)	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�	functionsr_)
�itemsr��headingrrrXrfr�
bigsectionr�)r-�server_name�package_documentationrY�fdict�key�value�head�resultr�contents�method_itemss            r�	docserverzServerHTMLDoc.docserver
s,����!�-�-�/�/�	&�	&�J�C�����E�#�J� ��:�E�%�L�L��k�k�+�.�.��:�[�H�����d�#�#���k�k�/����G�G���)�m�c�)���-�#�-�-�����g�m�m�o�o�.�.��&�	F�	F�J�C���O�O�D�O�O�E�3�e�O�D�D�E�E�E�E��$�/�/��{�B�G�G�H�$5�$5�7�7�7���
rc�(�d}d|z}d|�d|�d|�d�S)zFormat an HTML page.rvz1<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-rr)�css_path�css_links     r�pagezServerHTMLDoc.page$s:����?��
�	��',�e�e�X�X�X�x�x�x�
A�	Ar)r4rprqrrrrr+r/r[rrr�r��s}������A�A�"&�b�"�b�' �' �' �' �R,0��R���8�8�8�8�:���4A�A�A�A�Arr�c�0�eZdZdZd�Zd�Zd�Zd�Zd�ZdS)�XMLRPCDocGeneratorz�Generates documentation for an XML-RPC server.

    This class is designed as mix-in and should not
    be constructed directly.
    c�0�d|_d|_d|_dS)NzXML-RPC Server DocumentationzGThis server exports the following methods through the XML-RPC protocol.)r"�server_documentation�server_titler;s rr.zXMLRPCDocGenerator.__init__9s'��9���
�	
�!�;����rc��||_dS)z8Set the HTML title of the generated server documentationN)r4)r-r4s  r�set_server_titlez#XMLRPCDocGenerator.set_server_titleAs��)����rc��||_dS)z7Set the name of the generated HTML server documentationN)r")r-r"s  r�set_server_namez"XMLRPCDocGenerator.set_server_nameFs��'����rc��||_dS)z3Set the documentation string for the entire server.N)r3)r-r3s  r�set_server_documentationz+XMLRPCDocGenerator.set_server_documentationKs��%9��!�!�!rc���i}|���D]�}||jvr|j|}n�|j��ddg}t|jd��r|j�|��|d<t|jd��r|j�|��|d<t
|��}|dkr|}nKt|jd��s)	t|j|��}n#t$r|}YnwxYw|}n
Jd���|||<��t��}|�
|j|j|��}|�
tj|j��|��S)	agenerate_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_argstringrr^rArorFzACould not find method in self.functions and no instance installed)r8r'r(rWr<r^rrrr�r+r"r3r/�htmlr�r4)r-rYr\rN�method_info�
documenter�
documentations       r�generate_html_documentationz.XMLRPCDocGenerator.generate_html_documentationPs������2�2�4�4�	*�	*�K��d�j�(�(���K�0�����*�#�T�l���4�=�*A�B�B�V�%)�]�%H�%H��%U�%U�K��N��4�=�-�8�8�L�%)�]�%>�%>�{�%K�%K�K��N�#�K�0�0���,�.�.�(�F�F� ����<�<�	)�-�!9�$(�M�$/�"&�"&����*�-�-�-�!,����-����)�F�F�/�/�/�/�q�$*�G�K� � �"�_�_�
�"�,�,� $� 0� $� 9� '���
����t�{�4�+<�=�=�}�M�M�Ms�
C#�#C2�1C2N)	r4rprqrrr.r6r8r:rAr[rrr1r12sn��������;�;�;�)�)�)�
'�'�'�
9�9�9�
1N�1N�1N�1N�1Nrr1c��eZdZdZd�Zd�ZdS)�DocXMLRPCRequestHandlerz�XML-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�F�tj�tj�t����}tj�|ddd��}t
|d���5}|���cddd��S#1swxYwYdS)Nz..�
pydoc_dataz
_pydoc.css�rb)�mode)r�rL�dirname�realpath�__file__r��openr�)r-r
�	path_herer-�fps     r�_get_cssz DocXMLRPCRequestHandler._get_css�s����G�O�O�B�G�$4�$4�X�$>�$>�?�?�	��7�<�<�	�4��|�L�L��
�(��
&�
&�
&�	�"��7�7�9�9�	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�5B�B�Bc�<�|���s|���dS|j�d��rd}|�|j��}n.d}|j����d��}|�d��|�	dd|z��|�	d	tt|������|���|j
�|��dS)
�}Handles the HTTP GET request.

        Interpret all HTTP GET requests as requests for server
        documentation.
        Nz.cssztext/cssz	text/htmlr&r�zContent-Typez%s; charset=UTF-8r�)r�r�rL�endswithrNr�rArIr�r�r�r�r�r�r�)r-�content_typerOs   r�do_GETzDocXMLRPCRequestHandler.do_GET�s	���%�%�'�'�	��O�O�����F��9���f�%�%�	Q�%�L��}�}�T�Y�/�/�H�H�&�L��{�>�>�@�@�G�G��P�P�H����3��������)<�|�)K�L�L�L����)�3�s�8�}�}�+=�+=�>�>�>��������
����"�"�"�"�"rN)r4rprqrrrNrSr[rrrCrC�s<�����������#�#�#�#�#rrCc�&�eZdZdZedddddfd�ZdS)�DocXMLRPCServerz�XML-RPC and HTML documentation server.

    Adds the ability to serve server documentation to the capabilities
    of SimpleXMLRPCServer.
    TFNc
�|�t�||||||||��t�|��dSr�)r�r.r1r�s        rr.zDocXMLRPCServer.__init__�sK��	�#�#�D�$���$.��:K�$5�	7�	7�	7�	�#�#�D�)�)�)�)�)r)r4rprqrrrCr.r[rrrUrU�sD��������-D�!�e�d�#'�5�*�*�*�*�*�*rrUc��eZdZdZd�Zd�ZdS)�DocCGIXMLRPCRequestHandlerzJHandler for XML-RPC data and documentation requests passed through
    CGIc��|����d��}td��tdt|��z��t��tj���tjj�|��tjj���dS)rPr&zContent-Type: text/htmlr�N)	rArIr�r�r�r�r�r�r�r�s  rr�z%DocCGIXMLRPCRequestHandler.handle_get�s����3�3�5�5�<�<�W�E�E��
�'�(�(�(�
�"�S��]�]�2�3�3�3�
�����
�������
�����)�)�)��
����!�!�!�!�!rc�n�t�|��t�|��dSr�)r�r.r1r;s rr.z#DocCGIXMLRPCRequestHandler.__init__�s0���(�(��.�.�.��#�#�D�)�)�)�)�)rN)r4rprqrrr�r.r[rrrXrX�s<��������"�"�"� *�*�*�*�*rrX�__main__c�.�eZdZd�ZGd�d��ZdS)�ExampleServicec��dS)N�42r[r;s r�getDatazExampleService.getData�s���4rc�$�eZdZed���ZdS)�ExampleService.currentTimec�>�tj���Sr�)�datetime�nowr[rr�getCurrentTimez)ExampleService.currentTime.getCurrentTime�s���(�,�,�.�.�.rN)r4rprq�staticmethodrfr[rr�currentTimerb�s-������
�
/�
/��\�
/�
/�
/rrhN)r4rprqr`rhr[rrr]r]�sK������	�	�	�	/�	/�	/�	/�	/�	/�	/�	/�	/�	/rr])�	localhosti@c��||zSr�r[)�x�ys  r�<lambda>rm�s
��Q�q�S�r�add)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)1rr�
xmlrpc.clientrrrrr�http.serverr�	functoolsr	�inspectr
r=r�r�r�r�r�r`r��fcntl�ImportErrorrr!r#rtr�r�r�r��HTMLDocr�r1rCrUrXr4rdr]r�r3�powr0r?r��
serve_forever�KeyboardInterrupt�exitr[rr�<module>rzs���e�e�TH�G�G�G�G�G�G�G�G�G�G�G�G�G�.�.�.�.�.�.�������������������������
�
�
�
�	�	�	�	�	�	�	�	�����������L�L�L�L�������E�E�E���������04�4�4�IA�IA�IA�IA�IA�IA�IA�IA�VPA�PA�PA�PA�PA�!7�PA�PA�PA�dW�W�W�W�W��/�/�W�W�W�8%�%�%�%�%�.�%�%�%�N?-�?-�?-�?-�?-�4�?-�?-�?-�JoA�oA�oA�oA�oA�E�M�oA�oA�oA�bON�ON�ON�ON�ON�ON�ON�ON�b&#�&#�&#�&#�&#�8�&#�&#�&#�P*�*�*�*�*�*�*�*�*�*� *�*�*�*�*�$;�$6�*�*�*�4�z����O�O�O�/�/�/�/�/�/�/�/�
�	�/�	0�	0��F�� � ��%�%�%�� � ���%�8�8�8�� � ���!1�!1�d� �K�K�K��+�+�-�-�-�
��6�7�7�7�
��[�\�\�\�	�� � �"�"�"�"�� �	�	�	��E�;�<�<�<��C�H�Q�K�K�K�K�K�	��������������������������sI�A	�	A�A�A6G�
F"�!G�" G�G�G�G�G�G