Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38eceaa

Browse files
committed
Create xmlrpc package. Issue #2886.
1 parent 7f986ac commit 38eceaa

17 files changed

Lines changed: 462 additions & 668 deletions

Doc/library/docxmlrpcserver.rst

Lines changed: 0 additions & 95 deletions
This file was deleted.

Doc/library/internet.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,5 @@ is currently supported on most popular platforms. Here is an overview:
4242
cgihttpserver.rst
4343
cookielib.rst
4444
cookie.rst
45-
xmlrpclib.rst
46-
simplexmlrpcserver.rst
47-
docxmlrpcserver.rst
45+
xmlrpc.client.rst
46+
xmlrpc.server.rst

Doc/library/persistence.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ The list of modules described in this chapter is:
2323
shelve.rst
2424
marshal.rst
2525
dbm.rst
26+
bsddb.rst
2627
sqlite3.rst
Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
:mod:`xmlrpclib` --- XML-RPC client access
2-
==========================================
1+
:mod:`xmlrpc.client` --- XML-RPC client access
2+
==============================================
33

4-
.. module:: xmlrpclib
4+
.. module:: xmlrpc.client
55
:synopsis: XML-RPC client access.
66
.. moduleauthor:: Fredrik Lundh <[email protected]>
77
.. sectionauthor:: Eric S. Raymond <[email protected]>
@@ -86,7 +86,7 @@ between conformable Python objects and XML on the wire.
8686
raise a special :exc:`Fault` instance, used to signal XML-RPC server errors, or
8787
:exc:`ProtocolError` used to signal an error in the HTTP/HTTPS transport layer.
8888
Both :exc:`Fault` and :exc:`ProtocolError` derive from a base class called
89-
:exc:`Error`. Note that the xmlrpclib module currently does not marshal
89+
:exc:`Error`. Note that the xmlrpc client module currently does not marshal
9090
instances of subclasses of builtin types.
9191

9292
When passing strings, characters special to XML such as ``<``, ``>``, and ``&``
@@ -169,28 +169,9 @@ grouped under the reserved :attr:`system` member:
169169
string may contain HTML markup.
170170

171171

172-
.. _boolean-objects:
173-
174-
Boolean Objects
175-
---------------
176-
177-
This class may be initialized from any Python value; the instance returned
178-
depends only on its truth value. It supports various Python operators through
179-
:meth:`__cmp__`, :meth:`__repr__`, :meth:`__int__`, and :meth:`__bool__`
180-
methods, all implemented in the obvious ways.
181-
182-
It also has the following method, supported mainly for internal use by the
183-
unmarshalling code:
184-
185-
186-
.. method:: Boolean.encode(out)
187-
188-
Write the XML-RPC encoding of this Boolean item to the out stream object.
189-
190172
A working example follows. The server code::
191173

192-
import xmlrpclib
193-
from SimpleXMLRPCServer import SimpleXMLRPCServer
174+
from xmlrpc.server import SimpleXMLRPCServer
194175

195176
def is_even(n):
196177
return n%2 == 0
@@ -202,9 +183,9 @@ A working example follows. The server code::
202183

203184
The client code for the preceding server::
204185

205-
import xmlrpclib
186+
import xmlrpc.client
206187

207-
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
188+
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
208189
print("3 is even: %s" % str(proxy.is_even(3)))
209190
print("100 is even: %s" % str(proxy.is_even(100)))
210191

@@ -235,12 +216,12 @@ and :meth:`__repr__` methods.
235216
A working example follows. The server code::
236217

237218
import datetime
238-
from SimpleXMLRPCServer import SimpleXMLRPCServer
239-
import xmlrpclib
219+
from xmlrpc.server import SimpleXMLRPCServer
220+
import xmlrpc.client
240221

241222
def today():
242223
today = datetime.datetime.today()
243-
return xmlrpclib.DateTime(today)
224+
return xmlrpc.client.DateTime(today)
244225

245226
server = SimpleXMLRPCServer(("localhost", 8000))
246227
print("Listening on port 8000...")
@@ -249,10 +230,10 @@ A working example follows. The server code::
249230

250231
The client code for the preceding server::
251232

252-
import xmlrpclib
233+
import xmlrpc.client
253234
import datetime
254235

255-
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
236+
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
256237

257238
today = proxy.today()
258239
# convert the ISO8601 string to a datetime object
@@ -298,12 +279,12 @@ It also supports certain of Python's built-in operators through a
298279
Example usage of the binary objects. We're going to transfer an image over
299280
XMLRPC::
300281

301-
from SimpleXMLRPCServer import SimpleXMLRPCServer
302-
import xmlrpclib
282+
from xmlrpc.server import SimpleXMLRPCServer
283+
import xmlrpc.client
303284

304285
def python_logo():
305286
handle = open("python_logo.jpg")
306-
return xmlrpclib.Binary(handle.read())
287+
return xmlrpc.client.Binary(handle.read())
307288
handle.close()
308289

309290
server = SimpleXMLRPCServer(("localhost", 8000))
@@ -314,9 +295,9 @@ XMLRPC::
314295

315296
The client gets the image and saves it to a file::
316297

317-
import xmlrpclib
298+
import xmlrpc.client
318299

319-
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
300+
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
320301
handle = open("fetched_python_logo.jpg", "w")
321302
handle.write(proxy.python_logo().data)
322303
handle.close()
@@ -342,7 +323,7 @@ objects have the following members:
342323
In the following example we're going to intentionally cause a :exc:`Fault` by
343324
returning a complex type object. The server code::
344325

345-
from SimpleXMLRPCServer import SimpleXMLRPCServer
326+
from xmlrpc.server import SimpleXMLRPCServer
346327

347328
# A marshalling error is going to occur because we're returning a
348329
# complex number
@@ -357,12 +338,12 @@ returning a complex type object. The server code::
357338

358339
The client code for the preceding server::
359340

360-
import xmlrpclib
341+
import xmlrpc.client
361342

362-
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
343+
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
363344
try:
364345
proxy.add(2, 5)
365-
except xmlrpclib.Fault, err:
346+
except xmlrpc.client.Fault, err:
366347
print("A fault occured")
367348
print("Fault code: %d" % err.faultCode)
368349
print("Fault string: %s" % err.faultString)
@@ -402,14 +383,14 @@ does not exist). It has the following members:
402383
In the following example we're going to intentionally cause a :exc:`ProtocolError`
403384
by providing an invalid URI::
404385

405-
import xmlrpclib
386+
import xmlrpc.client
406387

407388
# create a ServerProxy with an invalid URI
408-
proxy = xmlrpclib.ServerProxy("http://invalidaddress/")
389+
proxy = xmlrpc.client.ServerProxy("http://invalidaddress/")
409390

410391
try:
411392
proxy.some_method()
412-
except xmlrpclib.ProtocolError, err:
393+
except xmlrpc.client.ProtocolError, err:
413394
print("A protocol error occured")
414395
print("URL: %s" % err.url)
415396
print("HTTP/HTTPS headers: %s" % err.headers)
@@ -435,7 +416,7 @@ encapsulate multiple calls to a remote server into a single request.
435416

436417
A usage example of this class follows. The server code ::
437418

438-
from SimpleXMLRPCServer import SimpleXMLRPCServer
419+
from xmlrpc.server import SimpleXMLRPCServer
439420

440421
def add(x,y):
441422
return x+y
@@ -461,10 +442,10 @@ A usage example of this class follows. The server code ::
461442

462443
The client code for the preceding server::
463444

464-
import xmlrpclib
445+
import xmlrpc.client
465446

466-
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
467-
multicall = xmlrpclib.MultiCall(proxy)
447+
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
448+
multicall = xmlrpc.client.MultiCall(proxy)
468449
multicall.add(7,3)
469450
multicall.subtract(7,3)
470451
multicall.multiply(7,3)
@@ -477,13 +458,6 @@ The client code for the preceding server::
477458
Convenience Functions
478459
---------------------
479460

480-
481-
.. function:: boolean(value)
482-
483-
Convert any Python value to one of the XML-RPC Boolean constants, ``True`` or
484-
``False``.
485-
486-
487461
.. function:: dumps(params[, methodname[, methodresponse[, encoding[, allow_none]]]])
488462

489463
Convert *params* into an XML-RPC request. or into a response if *methodresponse*
@@ -513,7 +487,7 @@ Example of Client Usage
513487
::
514488

515489
# simple test program (from the XML-RPC specification)
516-
from xmlrpclib import ServerProxy, Error
490+
from xmlrpc.client import ServerProxy, Error
517491

518492
# server = ServerProxy("http://localhost:8000") # local server
519493
server = ServerProxy("http://betty.userland.com")
@@ -532,9 +506,9 @@ transport. The following example shows how:
532506
533507
::
534508

535-
import xmlrpclib, httplib
509+
import xmlrpc.client, httplib
536510

537-
class ProxiedTransport(xmlrpclib.Transport):
511+
class ProxiedTransport(xmlrpc.client.Transport):
538512
def set_proxy(self, proxy):
539513
self.proxy = proxy
540514
def make_connection(self, host):
@@ -548,7 +522,7 @@ transport. The following example shows how:
548522

549523
p = ProxiedTransport()
550524
p.set_proxy('proxy-server:8080')
551-
server = xmlrpclib.Server('http://time.xmlrpc.com/RPC2', transport=p)
525+
server = xmlrpc.client.Server('http://time.xmlrpc.com/RPC2', transport=p)
552526
print(server.currentTime.getCurrentTime())
553527

554528

0 commit comments

Comments
 (0)