python / cpython

The Python programming language
https://www.python.org/
Other
59.71k stars 28.94k forks source link

SimpleXMLRPCServer - fixes and CGI #35379

Closed brianquinlan closed 21 years ago

brianquinlan commented 22 years ago
BPO 473586
Nosy @loewis, @brianquinlan
Files
  • xmlrpc.patch: SimpleXMLRPCServer patch
  • xmlrpc.patch2: v2 - fixed name
  • xmlrpc.patch3: v3 - fixed some docs
  • xmlrpc.patch4: v4 - commands and malformed requests
  • SimpleXMLRPCServer.patch1: v5 - backwards compatible with version released with Python 2.2
  • SimpleXMLRPCServer.patch2: SimpleXMLRPCServer patch #2
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields: ```python assignee = 'https://github.com/loewis' closed_at = created_at = labels = ['library'] title = 'SimpleXMLRPCServer - fixes and CGI' updated_at = user = 'https://github.com/brianquinlan' ``` bugs.python.org fields: ```python activity = actor = 'loewis' assignee = 'loewis' closed = True closed_date = None closer = None components = ['Library (Lib)'] creation = creator = 'bquinlan' dependencies = [] files = ['3695', '3696', '3697', '3698', '3699', '3700'] hgrepos = [] issue_num = 473586 keywords = ['patch'] message_count = 15.0 messages = ['37925', '37926', '37927', '37928', '37929', '37930', '37931', '37932', '37933', '37934', '37935', '37936', '37937', '37938', '37939'] nosy_count = 4.0 nosy_names = ['loewis', 'effbot', 'rgbecker', 'bquinlan'] pr_nums = [] priority = 'normal' resolution = 'accepted' stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue473586' versions = [] ```

    brianquinlan commented 22 years ago

    Changes:

    o treats xmlrpclib.Fault's correctly (no longer absorbes them as generic exceptions) o changed failed marshal to generate a useful Fault instead of an internal server error o adds a new class to make writing XML-RPC functions embedded in other servers, using CGI, easier (tested with APACHE) o to support the above, added a new dispatch helper class SimpleXMLRPCDispatcher

    brianquinlan commented 22 years ago

    Logged In: YES user_id=108973

    Changed a name to fit other naming conventions

    brianquinlan commented 22 years ago

    Logged In: YES user_id=108973

    I just can't stop mucking with it. This time there are only documentation changes. I should also have pointed out that this patch changes the mechanism for overriding the dispatch mechanism: you used to subclass the request handler, now you subclass the server. I believe that this change is correct because the server actually has the required state information to do the dispatching.

    61337411-43fc-4a9c-b8d5-4060aede66d0 commented 22 years ago

    Logged In: YES user_id=21627

    Brian, please note that Python 2.2b1 has been released, so no new features are acceptable until 2.2. So unless Fredrik Lundh wants to accept your entire patch, I think it has little chance to get integrated for the next few months. If you want pieces of it accepted, I'd recommend to split it into bug fixes and new features; bug fixes are still acceptable.

    brianquinlan commented 22 years ago

    Logged In: YES user_id=108973

    The advantage of the entire patch being accepted before 2.2 is that there is an API change and, once 2.2 is release, we will probably have to make a bit of an attempt to maintain backwards compatibility.

    If this patch is too high-risk for 2.2 then I can certainly design a bug-fix patch for 2.2 and submit a new patch for 2.3 (that is API compatible with 2.2).

    brianquinlan commented 22 years ago

    Logged In: YES user_id=108973

    brianquinlan commented 22 years ago

    Logged In: YES user_id=108973

    Please do not accept this patch past 2.2 release; there are so non-backwards compatible changes that need to be though through.

    brianquinlan commented 22 years ago

    Logged In: YES user_id=108973

    OK, I fixed the backwards compatibility problem.

    Also added: o support for the XML-RPC introspection methods system.listMethods and system.methodHelp o support for the XML-RPC boxcaring method system.multicall

    61337411-43fc-4a9c-b8d5-4060aede66d0 commented 21 years ago

    Logged In: YES user_id=21627

    Brian, the patch looks good to me. However, can you please also supply patches to Doc/lib/libsimplexmlrpc?

    brianquinlan commented 21 years ago

    Logged In: YES user_id=108973

    Martin, I don't have a lot of bandwidth right now but I'll try to do that soon.

    984255a6-3c8c-46ca-9711-185c8cf01fdd commented 21 years ago

    Logged In: YES user_id=6946

    Thanks I have applied the v5 patch and it seems fine, I suppose it is probably better to use the patch rather than stick with Brian's old code as I guess it will gradually get more and more out of date.

    Perhaps all the old introspection stuff belongs in a cookbook entry?

    brianquinlan commented 21 years ago

    Logged In: YES user_id=108973

    Attachment's aren't working right now, here is the documentation inline (sorry, I don't know enough about LaTeX to do my own markup):

    First page ----------

    The SimpleXMLRPCServer module provides a basic framework for XML-RPC servers written in Python. Servers can either be free standing, using SimpleXMLRPCServer, or embedded in a CGI environment, using CGIXMLRPCRequestHandler.

    class SimpleXMLRPCServer(addr[, requestHandler[, 
    logRequests]]) 
    Create a new server instance based on 
    SocketServer.TCPServer. The requestHandler parameter 
    should be a factory for request handler instances; it defaults 
    to SimpleXMLRPCRequestHandler. The addr and 
    requestHandler parameters are passed to the 
    SocketServer.TCPServer constructor. If logRequests is true 
    (the default), requests will be logged; setting this parameter 
    to false will turn off logging. This class provides methods for 
    registration of functions that can be called by the XML-RPC 
    protocol. 
    
    class CGIXMLRPCRequestHandler()
    Create a new instance to handle XML-RPC requests in a CGI 
    environment.

    SimpleXMLRPCServer ------------------

    The SimpleXMLRPCServer class is based on SocketServer.TCPServer and provides a means of creating simple, stand alone XML-RPC servers.

    register_function(function[, name]) 
    Register a function that can respond to XML-RPC requests. If 
    name is given, it will be the method name associated with 
    function, otherwise function.__name__ will be used. name 
    can be either a normal or Unicode string, and may contain 
    characters not legal in Python identifiers, including the period 
    character. 
    
    register_instance(instance) 
    Register an object which is used to expose method names 
    which have not been registered using register_function(). If 
    instance contains a _dispatch() method, it is called with the 
    requested method name and the parameters from the 
    request; the return value is returned to the client as the result. 
    If instance does not have a _dispatch() method, it is searched 
    for an attribute matching the name of the requested method; if 
    the requested method name contains periods, each 
    component of the method name is searched for individually, 
    with the effect that a simple hierarchical search is performed. 
    The value found from this search is then called with the 
    parameters from the request, and the return value is passed 
    back to the client. 

    register_introspection_functions Registers the XML-RPC introspection functions system.listMethods, system.methodHelp and system.methodSignature.

    register_multicall_functions Registers the XML-RPC multicall function system.multicall.

    Example:

    class MyFuncs:
        def div(self, x, y) : return div(x,y)
    
    server = SimpleXMLRPCServer(("localhost", 8000))
    server.register_function(pow)
    server.register_function(lambda x,y: x+y, 'add')
    server.register_introspection_functions()
    server.register_instance(MyFuncs())
    server.serve_forever()

    CGIXMLRPCRequestHandler -----------------------

    The CGIXMLRPCRequestHandler class can be used to handle XML-RPC requests sent to Python CGI scripts.

    register_function(function[, name]) 
    Register a function that can respond to XML-RPC requests. If 
    name is given, it will be the method name associated with 
    function, otherwise function.__name__ will be used. name 
    can be either a normal or Unicode string, and may contain 
    characters not legal in Python identifiers, including the period 
    character. 
    
    register_instance(instance) 
    Register an object which is used to expose method names 
    which have not been registered using register_function(). If 
    instance contains a _dispatch() method, it is called with the 
    requested method name and the parameters from the 
    request; the return value is returned to the client as the result. 
    If instance does not have a _dispatch() method, it is searched 
    for an attribute matching the name of the requested method; if 
    the requested method name contains periods, each 
    component of the method name is searched for individually, 
    with the effect that a simple hierarchical search is performed. 
    The value found from this search is then called with the 
    parameters from the request, and the return value is passed 
    back to the client. 

    register_introspection_functions Registers the XML-RPC introspection functions system.listMethods, system.methodHelp and system.methodSignature.

    register_multicall_functions Registers the XML-RPC multicall function system.multicall.

    handle_request(self, request_text = None)
    Handles a XML-RPC request. If request_text is given, it 
    should be the POST data provided by the HTTP server, 
    otherwise the contents of stdin will be used.

    Example:

    class MyFuncs:
        def div(self, x, y) : return div(x,y)
    
    handler = CGIXMLRPCRequestHandler(("localhost", 8000))
    handler.register_function(pow)
    handler.register_function(lambda x,y: x+y, 'add')
    handler.register_introspection_functions()
    handler.register_instance(MyFuncs())
    handler.handle_request()
    61337411-43fc-4a9c-b8d5-4060aede66d0 commented 21 years ago

    Logged In: YES user_id=21627

    Fredrik, do you see any reason to reject this patch, or request further modifications?

    b7a711ff-d634-47b2-ad1b-41e5ae806c8b commented 21 years ago

    Logged In: YES user_id=38376

    No problem here. Martin, can you check it in? (If not, assign it back to me)

    Thanks /F

    61337411-43fc-4a9c-b8d5-4060aede66d0 commented 21 years ago

    Logged In: YES user_id=21627

    Thanks for the patch. Committed as

    libsimplexmlrpc.tex 1.4 SimpleXMLRPCServer.py 1.3 NEWS 1.615