diff options
author | Georg Brandl <georg@python.org> | 2008-05-26 11:14:17 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-05-26 11:14:17 (GMT) |
commit | 38eceaaf0c207709cfbb44c7a1b9715699622848 (patch) | |
tree | 874f496e0fbaf8e6f3c86e86cd0c95fe51845dde /Doc | |
parent | 7f986acb0142574d30e5c5460df02fdbb00760e9 (diff) | |
download | cpython-38eceaaf0c207709cfbb44c7a1b9715699622848.zip cpython-38eceaaf0c207709cfbb44c7a1b9715699622848.tar.gz cpython-38eceaaf0c207709cfbb44c7a1b9715699622848.tar.bz2 |
Create xmlrpc package. Issue #2886.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/docxmlrpcserver.rst | 95 | ||||
-rw-r--r-- | Doc/library/internet.rst | 5 | ||||
-rw-r--r-- | Doc/library/persistence.rst | 1 | ||||
-rw-r--r-- | Doc/library/xmlrpc.client.rst (renamed from Doc/library/xmlrpclib.rst) | 90 | ||||
-rw-r--r-- | Doc/library/xmlrpc.server.rst (renamed from Doc/library/simplexmlrpcserver.rst) | 113 | ||||
-rw-r--r-- | Doc/license.rst | 2 | ||||
-rw-r--r-- | Doc/tutorial/stdlib.rst | 2 |
7 files changed, 136 insertions, 172 deletions
diff --git a/Doc/library/docxmlrpcserver.rst b/Doc/library/docxmlrpcserver.rst deleted file mode 100644 index 8169684..0000000 --- a/Doc/library/docxmlrpcserver.rst +++ /dev/null @@ -1,95 +0,0 @@ - -:mod:`DocXMLRPCServer` --- Self-documenting XML-RPC server -========================================================== - -.. module:: DocXMLRPCServer - :synopsis: Self-documenting XML-RPC server implementation. -.. moduleauthor:: Brian Quinlan <brianq@activestate.com> -.. sectionauthor:: Brian Quinlan <brianq@activestate.com> - - -The :mod:`DocXMLRPCServer` module extends the classes found in -:mod:`SimpleXMLRPCServer` to serve HTML documentation in response to HTTP GET -requests. Servers can either be free standing, using :class:`DocXMLRPCServer`, -or embedded in a CGI environment, using :class:`DocCGIXMLRPCRequestHandler`. - - -.. class:: DocXMLRPCServer(addr[, requestHandler[, logRequests[, allow_none[, encoding[, bind_and_activate]]]]]) - - Create a new server instance. All parameters have the same meaning as for - :class:`SimpleXMLRPCServer.SimpleXMLRPCServer`; *requestHandler* defaults to - :class:`DocXMLRPCRequestHandler`. - - -.. class:: DocCGIXMLRPCRequestHandler() - - Create a new instance to handle XML-RPC requests in a CGI environment. - - -.. class:: DocXMLRPCRequestHandler() - - Create a new request handler instance. This request handler supports XML-RPC - POST requests, documentation GET requests, and modifies logging so that the - *logRequests* parameter to the :class:`DocXMLRPCServer` constructor parameter is - honored. - - -.. _doc-xmlrpc-servers: - -DocXMLRPCServer Objects ------------------------ - -The :class:`DocXMLRPCServer` class is derived from -:class:`SimpleXMLRPCServer.SimpleXMLRPCServer` and provides a means of creating -self-documenting, stand alone XML-RPC servers. HTTP POST requests are handled as -XML-RPC method calls. HTTP GET requests are handled by generating pydoc-style -HTML documentation. This allows a server to provide its own web-based -documentation. - - -.. method:: DocXMLRPCServer.set_server_title(server_title) - - Set the title used in the generated HTML documentation. This title will be used - inside the HTML "title" element. - - -.. method:: DocXMLRPCServer.set_server_name(server_name) - - Set the name used in the generated HTML documentation. This name will appear at - the top of the generated documentation inside a "h1" element. - - -.. method:: DocXMLRPCServer.set_server_documentation(server_documentation) - - Set the description used in the generated HTML documentation. This description - will appear as a paragraph, below the server name, in the documentation. - - -DocCGIXMLRPCRequestHandler --------------------------- - -The :class:`DocCGIXMLRPCRequestHandler` class is derived from -:class:`SimpleXMLRPCServer.CGIXMLRPCRequestHandler` and provides a means of -creating self-documenting, XML-RPC CGI scripts. HTTP POST requests are handled -as XML-RPC method calls. HTTP GET requests are handled by generating pydoc-style -HTML documentation. This allows a server to provide its own web-based -documentation. - - -.. method:: DocCGIXMLRPCRequestHandler.set_server_title(server_title) - - Set the title used in the generated HTML documentation. This title will be used - inside the HTML "title" element. - - -.. method:: DocCGIXMLRPCRequestHandler.set_server_name(server_name) - - Set the name used in the generated HTML documentation. This name will appear at - the top of the generated documentation inside a "h1" element. - - -.. method:: DocCGIXMLRPCRequestHandler.set_server_documentation(server_documentation) - - Set the description used in the generated HTML documentation. This description - will appear as a paragraph, below the server name, in the documentation. - diff --git a/Doc/library/internet.rst b/Doc/library/internet.rst index 16b0a44..a5f6d22 100644 --- a/Doc/library/internet.rst +++ b/Doc/library/internet.rst @@ -42,6 +42,5 @@ is currently supported on most popular platforms. Here is an overview: cgihttpserver.rst cookielib.rst cookie.rst - xmlrpclib.rst - simplexmlrpcserver.rst - docxmlrpcserver.rst + xmlrpc.client.rst + xmlrpc.server.rst diff --git a/Doc/library/persistence.rst b/Doc/library/persistence.rst index c5c2aa4..8d9fa3a 100644 --- a/Doc/library/persistence.rst +++ b/Doc/library/persistence.rst @@ -23,4 +23,5 @@ The list of modules described in this chapter is: shelve.rst marshal.rst dbm.rst + bsddb.rst sqlite3.rst diff --git a/Doc/library/xmlrpclib.rst b/Doc/library/xmlrpc.client.rst index c1f13c3..7d59750 100644 --- a/Doc/library/xmlrpclib.rst +++ b/Doc/library/xmlrpc.client.rst @@ -1,7 +1,7 @@ -:mod:`xmlrpclib` --- XML-RPC client access -========================================== +:mod:`xmlrpc.client` --- XML-RPC client access +============================================== -.. module:: xmlrpclib +.. module:: xmlrpc.client :synopsis: XML-RPC client access. .. moduleauthor:: Fredrik Lundh <fredrik@pythonware.com> .. sectionauthor:: Eric S. Raymond <esr@snark.thyrsus.com> @@ -86,7 +86,7 @@ between conformable Python objects and XML on the wire. raise a special :exc:`Fault` instance, used to signal XML-RPC server errors, or :exc:`ProtocolError` used to signal an error in the HTTP/HTTPS transport layer. Both :exc:`Fault` and :exc:`ProtocolError` derive from a base class called - :exc:`Error`. Note that the xmlrpclib module currently does not marshal + :exc:`Error`. Note that the xmlrpc client module currently does not marshal instances of subclasses of builtin types. When passing strings, characters special to XML such as ``<``, ``>``, and ``&`` @@ -169,28 +169,9 @@ grouped under the reserved :attr:`system` member: string may contain HTML markup. -.. _boolean-objects: - -Boolean Objects ---------------- - -This class may be initialized from any Python value; the instance returned -depends only on its truth value. It supports various Python operators through -:meth:`__cmp__`, :meth:`__repr__`, :meth:`__int__`, and :meth:`__bool__` -methods, all implemented in the obvious ways. - -It also has the following method, supported mainly for internal use by the -unmarshalling code: - - -.. method:: Boolean.encode(out) - - Write the XML-RPC encoding of this Boolean item to the out stream object. - A working example follows. The server code:: - import xmlrpclib - from SimpleXMLRPCServer import SimpleXMLRPCServer + from xmlrpc.server import SimpleXMLRPCServer def is_even(n): return n%2 == 0 @@ -202,9 +183,9 @@ A working example follows. The server code:: The client code for the preceding server:: - import xmlrpclib + import xmlrpc.client - proxy = xmlrpclib.ServerProxy("http://localhost:8000/") + proxy = xmlrpc.client.ServerProxy("http://localhost:8000/") print("3 is even: %s" % str(proxy.is_even(3))) print("100 is even: %s" % str(proxy.is_even(100))) @@ -235,12 +216,12 @@ and :meth:`__repr__` methods. A working example follows. The server code:: import datetime - from SimpleXMLRPCServer import SimpleXMLRPCServer - import xmlrpclib + from xmlrpc.server import SimpleXMLRPCServer + import xmlrpc.client def today(): today = datetime.datetime.today() - return xmlrpclib.DateTime(today) + return xmlrpc.client.DateTime(today) server = SimpleXMLRPCServer(("localhost", 8000)) print("Listening on port 8000...") @@ -249,10 +230,10 @@ A working example follows. The server code:: The client code for the preceding server:: - import xmlrpclib + import xmlrpc.client import datetime - proxy = xmlrpclib.ServerProxy("http://localhost:8000/") + proxy = xmlrpc.client.ServerProxy("http://localhost:8000/") today = proxy.today() # convert the ISO8601 string to a datetime object @@ -298,12 +279,12 @@ It also supports certain of Python's built-in operators through a Example usage of the binary objects. We're going to transfer an image over XMLRPC:: - from SimpleXMLRPCServer import SimpleXMLRPCServer - import xmlrpclib + from xmlrpc.server import SimpleXMLRPCServer + import xmlrpc.client def python_logo(): handle = open("python_logo.jpg") - return xmlrpclib.Binary(handle.read()) + return xmlrpc.client.Binary(handle.read()) handle.close() server = SimpleXMLRPCServer(("localhost", 8000)) @@ -314,9 +295,9 @@ XMLRPC:: The client gets the image and saves it to a file:: - import xmlrpclib + import xmlrpc.client - proxy = xmlrpclib.ServerProxy("http://localhost:8000/") + proxy = xmlrpc.client.ServerProxy("http://localhost:8000/") handle = open("fetched_python_logo.jpg", "w") handle.write(proxy.python_logo().data) handle.close() @@ -342,7 +323,7 @@ objects have the following members: In the following example we're going to intentionally cause a :exc:`Fault` by returning a complex type object. The server code:: - from SimpleXMLRPCServer import SimpleXMLRPCServer + from xmlrpc.server import SimpleXMLRPCServer # A marshalling error is going to occur because we're returning a # complex number @@ -357,12 +338,12 @@ returning a complex type object. The server code:: The client code for the preceding server:: - import xmlrpclib + import xmlrpc.client - proxy = xmlrpclib.ServerProxy("http://localhost:8000/") + proxy = xmlrpc.client.ServerProxy("http://localhost:8000/") try: proxy.add(2, 5) - except xmlrpclib.Fault, err: + except xmlrpc.client.Fault, err: print("A fault occured") print("Fault code: %d" % err.faultCode) print("Fault string: %s" % err.faultString) @@ -402,14 +383,14 @@ does not exist). It has the following members: In the following example we're going to intentionally cause a :exc:`ProtocolError` by providing an invalid URI:: - import xmlrpclib + import xmlrpc.client # create a ServerProxy with an invalid URI - proxy = xmlrpclib.ServerProxy("http://invalidaddress/") + proxy = xmlrpc.client.ServerProxy("http://invalidaddress/") try: proxy.some_method() - except xmlrpclib.ProtocolError, err: + except xmlrpc.client.ProtocolError, err: print("A protocol error occured") print("URL: %s" % err.url) print("HTTP/HTTPS headers: %s" % err.headers) @@ -435,7 +416,7 @@ encapsulate multiple calls to a remote server into a single request. A usage example of this class follows. The server code :: - from SimpleXMLRPCServer import SimpleXMLRPCServer + from xmlrpc.server import SimpleXMLRPCServer def add(x,y): return x+y @@ -461,10 +442,10 @@ A usage example of this class follows. The server code :: The client code for the preceding server:: - import xmlrpclib + import xmlrpc.client - proxy = xmlrpclib.ServerProxy("http://localhost:8000/") - multicall = xmlrpclib.MultiCall(proxy) + proxy = xmlrpc.client.ServerProxy("http://localhost:8000/") + multicall = xmlrpc.client.MultiCall(proxy) multicall.add(7,3) multicall.subtract(7,3) multicall.multiply(7,3) @@ -477,13 +458,6 @@ The client code for the preceding server:: Convenience Functions --------------------- - -.. function:: boolean(value) - - Convert any Python value to one of the XML-RPC Boolean constants, ``True`` or - ``False``. - - .. function:: dumps(params[, methodname[, methodresponse[, encoding[, allow_none]]]]) Convert *params* into an XML-RPC request. or into a response if *methodresponse* @@ -513,7 +487,7 @@ Example of Client Usage :: # simple test program (from the XML-RPC specification) - from xmlrpclib import ServerProxy, Error + from xmlrpc.client import ServerProxy, Error # server = ServerProxy("http://localhost:8000") # local server server = ServerProxy("http://betty.userland.com") @@ -532,9 +506,9 @@ transport. The following example shows how: :: - import xmlrpclib, httplib + import xmlrpc.client, httplib - class ProxiedTransport(xmlrpclib.Transport): + class ProxiedTransport(xmlrpc.client.Transport): def set_proxy(self, proxy): self.proxy = proxy def make_connection(self, host): @@ -548,7 +522,7 @@ transport. The following example shows how: p = ProxiedTransport() p.set_proxy('proxy-server:8080') - server = xmlrpclib.Server('http://time.xmlrpc.com/RPC2', transport=p) + server = xmlrpc.client.Server('http://time.xmlrpc.com/RPC2', transport=p) print(server.currentTime.getCurrentTime()) diff --git a/Doc/library/simplexmlrpcserver.rst b/Doc/library/xmlrpc.server.rst index f6b64b3..1a9c757 100644 --- a/Doc/library/simplexmlrpcserver.rst +++ b/Doc/library/xmlrpc.server.rst @@ -1,15 +1,14 @@ +:mod:`xmlrpc.server` --- Basic XML-RPC servers +============================================== -:mod:`SimpleXMLRPCServer` --- Basic XML-RPC server -================================================== - -.. module:: SimpleXMLRPCServer - :synopsis: Basic XML-RPC server implementation. +.. module:: xmlrpc.server + :synopsis: Basic XML-RPC server implementations. .. moduleauthor:: Brian Quinlan <brianq@activestate.com> .. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org> -The :mod:`SimpleXMLRPCServer` module provides a basic server framework for -XML-RPC servers written in Python. Servers can either be free standing, using +The :mod:`xmlrpc.server` module provides a basic server framework for XML-RPC +servers written in Python. Servers can either be free standing, using :class:`SimpleXMLRPCServer`, or embedded in a CGI environment, using :class:`CGIXMLRPCRequestHandler`. @@ -23,7 +22,7 @@ XML-RPC servers written in Python. Servers can either be free standing, using are passed to the :class:`socketserver.TCPServer` constructor. If *logRequests* is true (the default), requests will be logged; setting this parameter to false will turn off logging. The *allow_none* and *encoding* parameters are passed - on to :mod:`xmlrpclib` and control the XML-RPC responses that will be returned + on to :mod:`xmlrpc.client` and control the XML-RPC responses that will be returned from the server. The *bind_and_activate* parameter controls whether :meth:`server_bind` and :meth:`server_activate` are called immediately by the constructor; it defaults to true. Setting it to false allows code to manipulate @@ -33,8 +32,8 @@ XML-RPC servers written in Python. Servers can either be free standing, using .. class:: CGIXMLRPCRequestHandler([allow_none[, encoding]]) Create a new instance to handle XML-RPC requests in a CGI environment. The - *allow_none* and *encoding* parameters are passed on to :mod:`xmlrpclib` and - control the XML-RPC responses that will be returned from the server. + *allow_none* and *encoding* parameters are passed on to :mod:`xmlrpc.client` + and control the XML-RPC responses that will be returned from the server. .. class:: SimpleXMLRPCRequestHandler() @@ -115,8 +114,8 @@ SimpleXMLRPCServer Example ^^^^^^^^^^^^^^^^^^^^^^^^^^ Server code:: - from SimpleXMLRPCServer import SimpleXMLRPCServer - from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler + from xmlrpc.server import SimpleXMLRPCServer + from xmlrpc.server import SimpleXMLRPCRequestHandler # Restrict to a particular path. class RequestHandler(SimpleXMLRPCRequestHandler): @@ -150,9 +149,9 @@ Server code:: The following client code will call the methods made available by the preceding server:: - import xmlrpclib + import xmlrpc.client - s = xmlrpclib.ServerProxy('http://localhost:8000') + s = xmlrpc.client.ServerProxy('http://localhost:8000') print(s.pow(2,3)) # Returns 2**3 = 8 print(s.add(2,3)) # Returns 5 print(s.mul(5,2)) # Returns 5*2 = 10 @@ -220,3 +219,89 @@ Example:: handler.register_instance(MyFuncs()) handler.handle_request() + +Documenting XMLRPC server +------------------------- + +These classes extend the above classes to serve HTML documentation in response +to HTTP GET requests. Servers can either be free standing, using +:class:`DocXMLRPCServer`, or embedded in a CGI environment, using +:class:`DocCGIXMLRPCRequestHandler`. + + +.. class:: DocXMLRPCServer(addr[, requestHandler[, logRequests[, allow_none[, encoding[, bind_and_activate]]]]]) + + Create a new server instance. All parameters have the same meaning as for + :class:`SimpleXMLRPCServer`; *requestHandler* defaults to + :class:`DocXMLRPCRequestHandler`. + + +.. class:: DocCGIXMLRPCRequestHandler() + + Create a new instance to handle XML-RPC requests in a CGI environment. + + +.. class:: DocXMLRPCRequestHandler() + + Create a new request handler instance. This request handler supports XML-RPC + POST requests, documentation GET requests, and modifies logging so that the + *logRequests* parameter to the :class:`DocXMLRPCServer` constructor parameter is + honored. + + +.. _doc-xmlrpc-servers: + +DocXMLRPCServer Objects +----------------------- + +The :class:`DocXMLRPCServer` class is derived from :class:`SimpleXMLRPCServer` +and provides a means of creating self-documenting, stand alone XML-RPC +servers. HTTP POST requests are handled as XML-RPC method calls. HTTP GET +requests are handled by generating pydoc-style HTML documentation. This allows a +server to provide its own web-based documentation. + + +.. method:: DocXMLRPCServer.set_server_title(server_title) + + Set the title used in the generated HTML documentation. This title will be used + inside the HTML "title" element. + + +.. method:: DocXMLRPCServer.set_server_name(server_name) + + Set the name used in the generated HTML documentation. This name will appear at + the top of the generated documentation inside a "h1" element. + + +.. method:: DocXMLRPCServer.set_server_documentation(server_documentation) + + Set the description used in the generated HTML documentation. This description + will appear as a paragraph, below the server name, in the documentation. + + +DocCGIXMLRPCRequestHandler +-------------------------- + +The :class:`DocCGIXMLRPCRequestHandler` class is derived from +:class:`CGIXMLRPCRequestHandler` and provides a means of creating +self-documenting, XML-RPC CGI scripts. HTTP POST requests are handled as XML-RPC +method calls. HTTP GET requests are handled by generating pydoc-style HTML +documentation. This allows a server to provide its own web-based documentation. + + +.. method:: DocCGIXMLRPCRequestHandler.set_server_title(server_title) + + Set the title used in the generated HTML documentation. This title will be used + inside the HTML "title" element. + + +.. method:: DocCGIXMLRPCRequestHandler.set_server_name(server_name) + + Set the name used in the generated HTML documentation. This name will appear at + the top of the generated documentation inside a "h1" element. + + +.. method:: DocCGIXMLRPCRequestHandler.set_server_documentation(server_documentation) + + Set the description used in the generated HTML documentation. This description + will appear as a paragraph, below the server name, in the documentation. diff --git a/Doc/license.rst b/Doc/license.rst index 05962e9..ed399dc 100644 --- a/Doc/license.rst +++ b/Doc/license.rst @@ -570,7 +570,7 @@ The :mod:`uu` module contains the following notice:: XML Remote Procedure Calls -------------------------- -The :mod:`xmlrpclib` module contains the following notice:: +The :mod:`xmlrpc.client` module contains the following notice:: The XML-RPC client interface is diff --git a/Doc/tutorial/stdlib.rst b/Doc/tutorial/stdlib.rst index 725817c..66e73a9 100644 --- a/Doc/tutorial/stdlib.rst +++ b/Doc/tutorial/stdlib.rst @@ -294,7 +294,7 @@ Batteries Included Python has a "batteries included" philosophy. This is best seen through the sophisticated and robust capabilities of its larger packages. For example: -* The :mod:`xmlrpclib` and :mod:`SimpleXMLRPCServer` modules make implementing +* The :mod:`xmlrpc.client` and :mod:`xmlrpc.server` modules make implementing remote procedure calls into an almost trivial task. Despite the modules names, no direct knowledge or handling of XML is needed. |