22# XML-RPC CLIENT LIBRARY
33# $Id$
44#
5- # an XML-RPC client interface for Python.
6- #
7- # the marshalling and response parser code can also be used to
8- # implement XML-RPC servers.
9- #
10- # Notes:
11- # this version is designed to work with Python 1.5.2 or newer.
12- # unicode encoding support requires at least Python 1.6.
13- # experimental HTTPS requires Python 2.0 built with SSL sockets.
14- # expat parser support requires Python 2.0 with pyexpat support.
15- #
165# History:
176# 1999-01-14 fl Created
187# 1999-01-15 fl Changed dateTime to use localtime
8776# TODO: authentication plugins
8877# TODO: memo problem (see HP's mail)
8978
79+ """
80+ An XML-RPC client interface for Python.
81+
82+ The marshalling and response parser code can also be used to
83+ implement XML-RPC servers.
84+
85+ Notes:
86+ This version is designed to work with Python 1.5.2 or newer.
87+ Unicode encoding support requires at least Python 1.6.
88+ Experimental HTTPS requires Python 2.0 built with SSL sockets.
89+ Expat parser support requires Python 2.0 with pyexpat support.
90+
91+ Exported exceptions:
92+
93+ Error Base class for client errors
94+ ProtocolError Indicates an HTTP protocol error
95+ ResponseError Indicates a broken response package
96+ Fault Indicates a XML-RPC fault package
97+
98+ Exported classes:
99+
100+ Boolean boolean wrapper to generate a "boolean" XML-RPC value
101+ DateTime dateTime wrapper for an ISO 8601 string or time tuple or
102+ localtime integer value to generate a "dateTime.iso8601"
103+ XML-RPC value
104+ Binary binary data wrapper
105+
106+ SlowParser Slow but safe standard parser
107+ Marshaller Generate an XML-RPC params chunk from a Python data structure
108+ Unmarshaller Unmarshal an XML-RPC response from incoming XML event message
109+
110+ Transport Handles an HTTP transaction to an XML-RPC server
111+ SafeTransport Handles an HTTPS transaction to an XML-RPC server
112+ ServerProxy Connect to a server through a proxy
113+ Server Same as ServerProxy
114+
115+ Exported constants:
116+
117+ True
118+ False
119+
120+ Exported functions:
121+
122+ boolean Convert any Python value to an XML-RPC boolean
123+ datetime Convert value to an XML-RPC datetime
124+ binary Convert value to an XML-RPC binary value
125+ getparser Create instance of the fastest available parser & attach
126+ to an unmarshalling object
127+ dumps Convert an argument tuple or a Fault instance to an XML-RPC
128+ request (or response, if the methodresponse option is used).
129+ loads Convert an XML-RPC packet to unmarshalled data plus a method
130+ name (None if not present).
131+
132+ """
133+
90134import re , string , time , operator
91135import urllib , xmllib
92136from types import *
@@ -120,11 +164,11 @@ def _stringify(string):
120164# Exceptions
121165
122166class Error (Exception ):
123- # base class for client errors
167+ """Base class for client errors."""
124168 pass
125169
126170class ProtocolError (Error ):
127- # indicates an HTTP protocol error
171+ """Indicates an HTTP protocol error."""
128172 def __init__ (self , url , errcode , errmsg , headers ):
129173 self .url = url
130174 self .errcode = errcode
@@ -137,11 +181,11 @@ def __repr__(self):
137181 )
138182
139183class ResponseError (Error ):
140- # indicates a broken response package
184+ """Indicates a broken response package"""
141185 pass
142186
143187class Fault (Error ):
144- # indicates a XML-RPC fault package
188+ """ indicates a XML-RPC fault package"""
145189 def __init__ (self , faultCode , faultString , ** extra ):
146190 self .faultCode = faultCode
147191 self .faultString = faultString
@@ -154,10 +198,12 @@ def __repr__(self):
154198# --------------------------------------------------------------------
155199# Special values
156200
157- # boolean wrapper
158- # use True or False to generate a "boolean" XML-RPC value
159201
160202class Boolean :
203+ """Boolean-value wrapper.
204+
205+ Use True or False to generate a "boolean" XML-RPC value.
206+ """
161207
162208 def __init__ (self , value = 0 ):
163209 self .value = operator .truth (value )
@@ -185,7 +231,7 @@ def __nonzero__(self):
185231True , False = Boolean (1 ), Boolean (0 )
186232
187233def boolean (value , truefalse = (False , True )):
188- # convert any Python value to XML-RPC boolean
234+ """Convert any Python value to XML-RPC boolean."""
189235 return truefalse [operator .truth (value )]
190236
191237#
@@ -194,6 +240,9 @@ def boolean(value, truefalse=(False, True)):
194240# in this class to generate a "dateTime.iso8601" XML-RPC value
195241
196242class DateTime :
243+ """DataTime wrapper for an ISO 8601 string or time tuple or
244+ localtime integer value to generate a 'dateTime.iso8601' XML-RPC
245+ value."""
197246
198247 def __init__ (self , value = 0 ):
199248 if not isinstance (value , StringType ):
@@ -225,10 +274,9 @@ def datetime(data):
225274 value .decode (data )
226275 return value
227276
228- #
229- # binary data wrapper
230277
231278class Binary :
279+ """Wrapper for binary data."""
232280
233281 def __init__ (self , data = None ):
234282 self .data = data
@@ -344,9 +392,11 @@ def close(self):
344392 del self ._target , self ._parser # get rid of circular references
345393
346394class SlowParser (xmllib .XMLParser ):
347- # slow but safe standard parser, based on the XML parser in
348- # Python's standard library. this is about 10 times slower
349- # than sgmlop, on roundtrip testing.
395+ """XML parser using xmllib.XMLParser.
396+
397+ This is about 10 times slower than sgmlop on roundtrip testing.
398+ """
399+
350400 def __init__ (self , target ):
351401 self .handle_xml = target .xml
352402 self .unknown_starttag = target .start
@@ -359,13 +409,14 @@ def __init__(self, target):
359409# XML-RPC marshalling and unmarshalling code
360410
361411class Marshaller :
362- """Generate an XML-RPC params chunk from a Python data structure"""
412+ """Generate an XML-RPC params chunk from a Python data structure.
363413
364- # USAGE: create a marshaller instance for each set of parameters,
365- # and use "dumps" to convert your data (represented as a tuple) to
366- # a XML-RPC params chunk. to write a fault response, pass a Fault
367- # instance instead. you may prefer to use the "dumps" convenience
368- # function for this purpose (see below).
414+ Create a marshaller instance for each set of parameters, and use
415+ "dumps" method to convert your data (represented as a tuple) to a
416+ XML-RPC params chunk. to write a fault response, pass a Fault
417+ instance instead. You may prefer to use the "dumps" convenience
418+ function for this purpose (see below).
419+ """
369420
370421 # by the way, if you don't understand what's going on in here,
371422 # that's perfectly ok.
@@ -469,13 +520,13 @@ def dump_instance(self, value):
469520 dispatch [InstanceType ] = dump_instance
470521
471522class Unmarshaller :
523+ """Unmarshal an XML-RPC response, based on incoming XML event
524+ messages (start, data, end). Call close() to get the resulting
525+ data structure.
472526
473- # unmarshal an XML-RPC response, based on incoming XML event
474- # messages (start, data, end). call close to get the resulting
475- # data structure
476-
477- # note that this reader is fairly tolerant, and gladly accepts
478- # bogus XML-RPC data without complaining (but not bogus XML).
527+ Note that this reader is fairly tolerant, and gladly accepts
528+ bogus XML-RPC data without complaining (but not bogus XML).
529+ """
479530
480531 # and again, if you don't understand what's going on in here,
481532 # that's perfectly ok.
0 commit comments