annotate Lib/xmlrpclib.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents bcf6663c5c04
children 97a0a8589014
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
2 # XML-RPC CLIENT LIBRARY
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
3 # $Id$
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
4 #
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
5 # an XML-RPC client interface for Python.
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
6 #
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
7 # the marshalling and response parser code can also be used to
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
8 # implement XML-RPC servers.
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
9 #
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
10 # Notes:
33209
34a8d75edd2b Bump minimum Python version to 2.1. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 32249
diff changeset
11 # this version is designed to work with Python 2.1 or newer.
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
12 #
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
13 # History:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
14 # 1999-01-14 fl Created
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
15 # 1999-01-15 fl Changed dateTime to use localtime
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
16 # 1999-01-16 fl Added Binary/base64 element, default to RPC2 service
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
17 # 1999-01-19 fl Fixed array data element (from Skip Montanaro)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
18 # 1999-01-21 fl Fixed dateTime constructor, etc.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
19 # 1999-02-02 fl Added fault handling, handle empty sequences, etc.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
20 # 1999-02-10 fl Fixed problem with empty responses (from Skip Montanaro)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
21 # 1999-06-20 fl Speed improvements, pluggable parsers/transports (0.9.8)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
22 # 2000-11-28 fl Changed boolean to check the truth value of its argument
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
23 # 2001-02-24 fl Added encoding/Unicode/SafeTransport patches
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
24 # 2001-02-26 fl Added compare support to wrappers (0.9.9/1.0b1)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
25 # 2001-03-28 fl Make sure response tuple is a singleton
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
26 # 2001-03-29 fl Don't require empty params element (from Nicholas Riley)
19450
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
27 # 2001-06-10 fl Folded in _xmlrpclib accelerator support (1.0b2)
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
28 # 2001-08-20 fl Base xmlrpclib.Error on built-in Exception (from Paul Prescod)
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
29 # 2001-09-03 fl Allow Transport subclass to override getparser
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
30 # 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup)
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
31 # 2001-10-01 fl Remove containers from memo cache when done with them
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
32 # 2001-10-01 fl Use faster escape method (80% dumps speedup)
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
33 # 2001-10-02 fl More dumps microtuning
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
34 # 2001-10-04 fl Make sure import expat gets a parser (from Guido van Rossum)
20363
6b1d8cb9904a allow long ints to be marshalled as ints - no check is made to the incoming
Skip Montanaro <skip@pobox.com>
parents: 20216
diff changeset
35 # 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
36 # 2001-10-17 sm Test for int and long overflow (allows use on 64-bit systems)
21494
44c479f84e36 partial merge with current pythonware codebase:
Fredrik Lundh <fredrik@pythonware.com>
parents: 20504
diff changeset
37 # 2001-11-12 fl Use repr() to marshal doubles (from Paul Felix)
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
38 # 2002-03-17 fl Avoid buffered read when possible (from James Rucker)
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
39 # 2002-04-07 fl Added pythondoc comments
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
40 # 2002-04-16 fl Added __str__ methods to datetime/binary wrappers
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
41 # 2002-05-15 fl Added error constants (from Andrew Kuchling)
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
42 # 2002-06-27 fl Merged with Python CVS version
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
43 # 2002-10-22 fl Added basic authentication (based on code from Phillip Eby)
29825
a37106ac7c8c Patch #764470: Fix marshalling of faults. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29489
diff changeset
44 # 2003-01-22 sm Add support for the bool type
a37106ac7c8c Patch #764470: Fix marshalling of faults. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29489
diff changeset
45 # 2003-02-27 gvr Remove apply calls
a37106ac7c8c Patch #764470: Fix marshalling of faults. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29489
diff changeset
46 # 2003-04-24 sm Use cStringIO if available
a37106ac7c8c Patch #764470: Fix marshalling of faults. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29489
diff changeset
47 # 2003-04-25 ak Add support for nil
a37106ac7c8c Patch #764470: Fix marshalling of faults. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29489
diff changeset
48 # 2003-06-15 gn Add support for time.struct_time
a37106ac7c8c Patch #764470: Fix marshalling of faults. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29489
diff changeset
49 # 2003-07-12 gp Correct marshalling of Faults
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
50 # 2003-10-31 mvl Add multicall support
33209
34a8d75edd2b Bump minimum Python version to 2.1. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 32249
diff changeset
51 # 2004-08-20 mvl Bump minimum supported Python version to 2.1
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
52 #
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
53 # Copyright (c) 1999-2002 by Secret Labs AB.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
54 # Copyright (c) 1999-2002 by Fredrik Lundh.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
55 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
56 # info@pythonware.com
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
57 # http://www.pythonware.com
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
58 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
59 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
60 # The XML-RPC client interface is
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
61 #
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
62 # Copyright (c) 1999-2002 by Secret Labs AB
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
63 # Copyright (c) 1999-2002 by Fredrik Lundh
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
64 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
65 # By obtaining, using, and/or copying this software and/or its
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
66 # associated documentation, you agree that you have read, understood,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
67 # and will comply with the following terms and conditions:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
68 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
69 # Permission to use, copy, modify, and distribute this software and
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
70 # its associated documentation for any purpose and without fee is
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
71 # hereby granted, provided that the above copyright notice appears in
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
72 # all copies, and that both that copyright notice and this permission
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
73 # notice appear in supporting documentation, and that the name of
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
74 # Secret Labs AB or the author not be used in advertising or publicity
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
75 # pertaining to distribution of the software without specific, written
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
76 # prior permission.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
77 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
78 # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
79 # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
80 # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
81 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
82 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
83 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
84 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
85 # OF THIS SOFTWARE.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
86 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
87
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
88 #
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
89 # things to look into some day:
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
90
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
91 # TODO: sort out True/False/boolean issues for Python 2.3
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
92
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
93 """
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
94 An XML-RPC client interface for Python.
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
95
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
96 The marshalling and response parser code can also be used to
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
97 implement XML-RPC servers.
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
98
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
99 Exported exceptions:
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
100
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
101 Error Base class for client errors
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
102 ProtocolError Indicates an HTTP protocol error
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
103 ResponseError Indicates a broken response package
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
104 Fault Indicates an XML-RPC fault package
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
105
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
106 Exported classes:
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
107
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
108 ServerProxy Represents a logical connection to an XML-RPC server
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
109
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
110 MultiCall Executor of boxcared xmlrpc requests
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
111 Boolean boolean wrapper to generate a "boolean" XML-RPC value
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
112 DateTime dateTime wrapper for an ISO 8601 string or time tuple or
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
113 localtime integer value to generate a "dateTime.iso8601"
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
114 XML-RPC value
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
115 Binary binary data wrapper
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
116
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
117 SlowParser Slow but safe standard parser (based on xmllib)
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
118 Marshaller Generate an XML-RPC params chunk from a Python data structure
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
119 Unmarshaller Unmarshal an XML-RPC response from incoming XML event message
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
120 Transport Handles an HTTP transaction to an XML-RPC server
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
121 SafeTransport Handles an HTTPS transaction to an XML-RPC server
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
122
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
123 Exported constants:
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
124
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
125 True
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
126 False
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
127
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
128 Exported functions:
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
129
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
130 boolean Convert any Python value to an XML-RPC boolean
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
131 getparser Create instance of the fastest available parser & attach
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
132 to an unmarshalling object
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
133 dumps Convert an argument tuple or a Fault instance to an XML-RPC
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
134 request (or response, if the methodresponse option is used).
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
135 loads Convert an XML-RPC packet to unmarshalled data plus a method
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
136 name (None if not present).
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
137 """
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
138
20481
cd96c4b01ff0 Remove unused import; reported by Neal Norwitz.
Fred Drake <fdrake@acm.org>
parents: 20363
diff changeset
139 import re, string, time, operator
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
140
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
141 from types import *
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
142
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
143 # --------------------------------------------------------------------
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
144 # Internal stuff
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
145
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
146 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
147 unicode
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
148 except NameError:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
149 unicode = None # unicode support not available
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
150
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
151 try:
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
152 import datetime
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
153 except ImportError:
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
154 datetime = None
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
155
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
156 try:
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
157 _bool_is_builtin = False.__class__.__name__ == "bool"
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
158 except NameError:
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
159 _bool_is_builtin = 0
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
160
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
161 def _decode(data, encoding, is8bit=re.compile("[\x80-\xff]").search):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
162 # decode non-ascii string (if possible)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
163 if unicode and encoding and is8bit(data):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
164 data = unicode(data, encoding)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
165 return data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
166
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
167 def escape(s, replace=string.replace):
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
168 s = replace(s, "&", "&amp;")
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
169 s = replace(s, "<", "&lt;")
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
170 return replace(s, ">", "&gt;",)
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
171
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
172 if unicode:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
173 def _stringify(string):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
174 # convert to 7-bit ascii if possible
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
175 try:
34582
0a6e779d347d fix decoding in _stringify to not depend on the default encoding
Fred Drake <fdrake@acm.org>
parents: 34578
diff changeset
176 return string.encode("ascii")
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
177 except UnicodeError:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
178 return string
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
179 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
180 def _stringify(string):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
181 return string
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
182
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
183 __version__ = "1.0.1"
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
184
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
185 # xmlrpc integer limits
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
186 MAXINT = 2L**31-1
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
187 MININT = -2L**31
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
188
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
189 # --------------------------------------------------------------------
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
190 # Error constants (from Dan Libby's specification at
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
191 # http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php)
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
192
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
193 # Ranges of errors
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
194 PARSE_ERROR = -32700
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
195 SERVER_ERROR = -32600
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
196 APPLICATION_ERROR = -32500
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
197 SYSTEM_ERROR = -32400
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
198 TRANSPORT_ERROR = -32300
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
199
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
200 # Specific errors
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
201 NOT_WELLFORMED_ERROR = -32700
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
202 UNSUPPORTED_ENCODING = -32701
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
203 INVALID_ENCODING_CHAR = -32702
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
204 INVALID_XMLRPC = -32600
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
205 METHOD_NOT_FOUND = -32601
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
206 INVALID_METHOD_PARAMS = -32602
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
207 INTERNAL_ERROR = -32603
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
208
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
209 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
210 # Exceptions
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
211
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
212 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
213 # Base class for all kinds of client-side errors.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
214
19450
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
215 class Error(Exception):
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
216 """Base class for client errors."""
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
217 def __str__(self):
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
218 return repr(self)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
219
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
220 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
221 # Indicates an HTTP-level protocol error. This is raised by the HTTP
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
222 # transport layer, if the server returns an error code other than 200
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
223 # (OK).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
224 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
225 # @param url The target URL.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
226 # @param errcode The HTTP error code.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
227 # @param errmsg The HTTP error message.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
228 # @param headers The HTTP header dictionary.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
229
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
230 class ProtocolError(Error):
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
231 """Indicates an HTTP protocol error."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
232 def __init__(self, url, errcode, errmsg, headers):
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
233 Error.__init__(self)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
234 self.url = url
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
235 self.errcode = errcode
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
236 self.errmsg = errmsg
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
237 self.headers = headers
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
238 def __repr__(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
239 return (
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
240 "<ProtocolError for %s: %s %s>" %
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
241 (self.url, self.errcode, self.errmsg)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
242 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
243
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
244 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
245 # Indicates a broken XML-RPC response package. This exception is
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
246 # raised by the unmarshalling layer, if the XML-RPC response is
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
247 # malformed.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
248
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
249 class ResponseError(Error):
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
250 """Indicates a broken response package."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
251 pass
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
252
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
253 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
254 # Indicates an XML-RPC fault response package. This exception is
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
255 # raised by the unmarshalling layer, if the XML-RPC response contains
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
256 # a fault string. This exception can also used as a class, to
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
257 # generate a fault XML-RPC message.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
258 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
259 # @param faultCode The XML-RPC fault code.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
260 # @param faultString The XML-RPC fault string.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
261
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
262 class Fault(Error):
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
263 """Indicates an XML-RPC fault package."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
264 def __init__(self, faultCode, faultString, **extra):
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
265 Error.__init__(self)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
266 self.faultCode = faultCode
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
267 self.faultString = faultString
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
268 def __repr__(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
269 return (
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
270 "<Fault %s: %s>" %
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
271 (self.faultCode, repr(self.faultString))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
272 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
273
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
274 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
275 # Special values
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
276
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
277 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
278 # Wrapper for XML-RPC boolean values. Use the xmlrpclib.True and
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
279 # xmlrpclib.False constants, or the xmlrpclib.boolean() function, to
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
280 # generate boolean XML-RPC values.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
281 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
282 # @param value A boolean value. Any true value is interpreted as True,
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
283 # all other values are interpreted as False.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
284
48160
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
285 from sys import modules
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
286 mod_dict = modules[__name__].__dict__
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
287 if _bool_is_builtin:
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
288 boolean = Boolean = bool
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
289 # to avoid breaking code which references xmlrpclib.{True,False}
48160
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
290 mod_dict['True'] = True
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
291 mod_dict['False'] = False
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
292 else:
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
293 class Boolean:
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
294 """Boolean-value wrapper.
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
295
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
296 Use True or False to generate a "boolean" XML-RPC value.
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
297 """
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
298
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
299 def __init__(self, value = 0):
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
300 self.value = operator.truth(value)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
301
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
302 def encode(self, out):
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
303 out.write("<value><boolean>%d</boolean></value>\n" % self.value)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
304
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
305 def __cmp__(self, other):
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
306 if isinstance(other, Boolean):
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
307 other = other.value
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
308 return cmp(self.value, other)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
309
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
310 def __repr__(self):
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
311 if self.value:
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
312 return "<Boolean True at %x>" % id(self)
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
313 else:
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
314 return "<Boolean False at %x>" % id(self)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
315
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
316 def __int__(self):
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
317 return self.value
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
318
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
319 def __nonzero__(self):
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
320 return self.value
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
321
48160
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
322 mod_dict['True'] = Boolean(1)
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
323 mod_dict['False'] = Boolean(0)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
324
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
325 ##
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
326 # Map true or false value to XML-RPC boolean values.
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
327 #
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
328 # @def boolean(value)
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
329 # @param value A boolean value. Any true value is mapped to True,
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
330 # all other values are mapped to False.
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
331 # @return xmlrpclib.True or xmlrpclib.False.
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
332 # @see Boolean
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
333 # @see True
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
334 # @see False
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
335
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
336 def boolean(value, _truefalse=(False, True)):
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
337 """Convert any Python value to XML-RPC 'boolean'."""
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
338 return _truefalse[operator.truth(value)]
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
339
48160
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
340 del modules, mod_dict
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
341
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
342 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
343 # Wrapper for XML-RPC DateTime values. This converts a time value to
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
344 # the format used by XML-RPC.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
345 # <p>
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
346 # The value can be given as a string in the format
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
347 # "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
348 # time.localtime()), or an integer value (as returned by time.time()).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
349 # The wrapper uses time.localtime() to convert an integer to a time
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
350 # tuple.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
351 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
352 # @param value The time, given as an ISO 8601 string, a time
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
353 # tuple, or a integer time value.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
354
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
355 def _strftime(value):
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
356 if datetime:
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
357 if isinstance(value, datetime.datetime):
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
358 return "%04d%02d%02dT%02d:%02d:%02d" % (
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
359 value.year, value.month, value.day,
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
360 value.hour, value.minute, value.second)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
361
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
362 if not isinstance(value, (TupleType, time.struct_time)):
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
363 if value == 0:
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
364 value = time.time()
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
365 value = time.localtime(value)
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
366
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
367 return "%04d%02d%02dT%02d:%02d:%02d" % value[:6]
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
368
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
369 class DateTime:
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
370 """DateTime wrapper for an ISO 8601 string or time tuple or
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
371 localtime integer value to generate 'dateTime.iso8601' XML-RPC
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
372 value.
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
373 """
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
374
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
375 def __init__(self, value=0):
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
376 if isinstance(value, StringType):
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
377 self.value = value
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
378 else:
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
379 self.value = _strftime(value)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
380
45459
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
381 def make_comparable(self, other):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
382 if isinstance(other, DateTime):
45459
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
383 s = self.value
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
384 o = other.value
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
385 elif datetime and isinstance(other, datetime.datetime):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
386 s = self.value
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
387 o = other.strftime("%Y%m%dT%H:%M:%S")
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
388 elif isinstance(other, (str, unicode)):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
389 s = self.value
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
390 o = other
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
391 elif hasattr(other, "timetuple"):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
392 s = self.timetuple()
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
393 o = other.timetuple()
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
394 else:
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
395 otype = (hasattr(other, "__class__")
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
396 and other.__class__.__name__
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
397 or type(other))
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
398 raise TypeError("Can't compare %s and %s" %
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
399 (self.__class__.__name__, otype))
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
400 return s, o
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
401
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
402 def __lt__(self, other):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
403 s, o = self.make_comparable(other)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
404 return s < o
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
405
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
406 def __le__(self, other):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
407 s, o = self.make_comparable(other)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
408 return s <= o
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
409
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
410 def __gt__(self, other):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
411 s, o = self.make_comparable(other)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
412 return s > o
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
413
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
414 def __ge__(self, other):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
415 s, o = self.make_comparable(other)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
416 return s >= o
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
417
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
418 def __eq__(self, other):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
419 s, o = self.make_comparable(other)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
420 return s == o
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
421
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
422 def __ne__(self, other):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
423 s, o = self.make_comparable(other)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
424 return s != o
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
425
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
426 def timetuple(self):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
427 return time.strptime(self.value, "%Y%m%dT%H:%M:%S")
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
428
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
429 def __cmp__(self, other):
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
430 s, o = self.make_comparable(other)
1cc47e129ff4 #1330538: Improve comparison of xmlrpclib.DateTime and datetime instances.
Andrew M. Kuchling <amk@amk.ca>
parents: 40360
diff changeset
431 return cmp(s, o)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
432
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
433 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
434 # Get date/time value.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
435 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
436 # @return Date/time value, as an ISO 8601 string.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
437
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
438 def __str__(self):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
439 return self.value
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
440
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
441 def __repr__(self):
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
442 return "<DateTime %s at %x>" % (repr(self.value), id(self))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
443
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
444 def decode(self, data):
35984
75d536b247ea [Bug #1164912] Ensure Datetime wrapper class .value attribute is an 8-bit string, not a Unicode string
Andrew M. Kuchling <amk@amk.ca>
parents: 34956
diff changeset
445 data = str(data)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
446 self.value = string.strip(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
447
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
448 def encode(self, out):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
449 out.write("<value><dateTime.iso8601>")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
450 out.write(self.value)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
451 out.write("</dateTime.iso8601></value>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
452
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
453 def _datetime(data):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
454 # decode xml element contents into a DateTime structure.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
455 value = DateTime()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
456 value.decode(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
457 return value
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
458
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
459 def _datetime_type(data):
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
460 t = time.strptime(data, "%Y%m%dT%H:%M:%S")
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
461 return datetime.datetime(*tuple(t)[:6])
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
462
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
463 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
464 # Wrapper for binary data. This can be used to transport any kind
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
465 # of binary data over XML-RPC, using BASE64 encoding.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
466 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
467 # @param data An 8-bit string containing arbitrary data.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
468
28802
25c8cee4457e move imports in Binary class to top level to avoid repeated imports.
Skip Montanaro <skip@pobox.com>
parents: 28089
diff changeset
469 import base64
25c8cee4457e move imports in Binary class to top level to avoid repeated imports.
Skip Montanaro <skip@pobox.com>
parents: 28089
diff changeset
470 try:
25c8cee4457e move imports in Binary class to top level to avoid repeated imports.
Skip Montanaro <skip@pobox.com>
parents: 28089
diff changeset
471 import cStringIO as StringIO
25c8cee4457e move imports in Binary class to top level to avoid repeated imports.
Skip Montanaro <skip@pobox.com>
parents: 28089
diff changeset
472 except ImportError:
25c8cee4457e move imports in Binary class to top level to avoid repeated imports.
Skip Montanaro <skip@pobox.com>
parents: 28089
diff changeset
473 import StringIO
25c8cee4457e move imports in Binary class to top level to avoid repeated imports.
Skip Montanaro <skip@pobox.com>
parents: 28089
diff changeset
474
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
475 class Binary:
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
476 """Wrapper for binary data."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
478 def __init__(self, data=None):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
479 self.data = data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
480
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
481 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
482 # Get buffer contents.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
483 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
484 # @return Buffer contents, as an 8-bit string.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
485
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
486 def __str__(self):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
487 return self.data or ""
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
488
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
489 def __cmp__(self, other):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
490 if isinstance(other, Binary):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
491 other = other.data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
492 return cmp(self.data, other)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
493
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
494 def decode(self, data):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
495 self.data = base64.decodestring(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
496
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
497 def encode(self, out):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
498 out.write("<value><base64>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
499 base64.encode(StringIO.StringIO(self.data), out)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
500 out.write("</base64></value>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
501
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
502 def _binary(data):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
503 # decode xml element contents into a Binary structure
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
504 value = Binary()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
505 value.decode(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
506 return value
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
507
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
508 WRAPPERS = (DateTime, Binary)
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
509 if not _bool_is_builtin:
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
510 WRAPPERS = WRAPPERS + (Boolean,)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
511
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
512 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
513 # XML parsers
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
514
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
515 try:
33741
d1f0c7079b82 removed info@pythonware.com reference
Fredrik Lundh <fredrik@pythonware.com>
parents: 33223
diff changeset
516 # optional xmlrpclib accelerator
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
517 import _xmlrpclib
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
518 FastParser = _xmlrpclib.Parser
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
519 FastUnmarshaller = _xmlrpclib.Unmarshaller
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
520 except (AttributeError, ImportError):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
521 FastParser = FastUnmarshaller = None
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
522
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
523 try:
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
524 import _xmlrpclib
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
525 FastMarshaller = _xmlrpclib.Marshaller
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
526 except (AttributeError, ImportError):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
527 FastMarshaller = None
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
528
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
529 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
530 # the SGMLOP parser is about 15x faster than Python's builtin
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
531 # XML parser. SGMLOP sources can be downloaded from:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
532 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
533 # http://www.pythonware.com/products/xml/sgmlop.htm
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
534 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
535
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
536 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
537 import sgmlop
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
538 if not hasattr(sgmlop, "XMLParser"):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
539 raise ImportError
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
540 except ImportError:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
541 SgmlopParser = None # sgmlop accelerator not available
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
542 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
543 class SgmlopParser:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
544 def __init__(self, target):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
545
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
546 # setup callbacks
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
547 self.finish_starttag = target.start
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
548 self.finish_endtag = target.end
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
549 self.handle_data = target.data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
550 self.handle_xml = target.xml
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
551
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
552 # activate parser
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
553 self.parser = sgmlop.XMLParser()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
554 self.parser.register(self)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
555 self.feed = self.parser.feed
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
556 self.entity = {
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
557 "amp": "&", "gt": ">", "lt": "<",
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
558 "apos": "'", "quot": '"'
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
559 }
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
560
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
561 def close(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
562 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
563 self.parser.close()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
564 finally:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
565 self.parser = self.feed = None # nuke circular reference
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
566
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
567 def handle_proc(self, tag, attr):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
568 m = re.search("encoding\s*=\s*['\"]([^\"']+)[\"']", attr)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
569 if m:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
570 self.handle_xml(m.group(1), 1)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
571
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
572 def handle_entityref(self, entity):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
573 # <string> entity
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
574 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
575 self.handle_data(self.entity[entity])
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
576 except KeyError:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
577 self.handle_data("&%s;" % entity)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
578
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
579 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
580 from xml.parsers import expat
20216
a5a330646c13 Under certain conditions (sometimes triggered by the test suite),
Guido van Rossum <guido@python.org>
parents: 20208
diff changeset
581 if not hasattr(expat, "ParserCreate"):
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
582 raise ImportError
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
583 except ImportError:
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
584 ExpatParser = None # expat not available
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
585 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
586 class ExpatParser:
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
587 # fast expat parser for Python 2.0 and later. this is about
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
588 # 50% slower than sgmlop, on roundtrip testing
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
589 def __init__(self, target):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
590 self._parser = parser = expat.ParserCreate(None, None)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
591 self._target = target
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
592 parser.StartElementHandler = target.start
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
593 parser.EndElementHandler = target.end
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
594 parser.CharacterDataHandler = target.data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
595 encoding = None
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
596 if not parser.returns_unicode:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
597 encoding = "utf-8"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
598 target.xml(encoding, None)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
599
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
600 def feed(self, data):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
601 self._parser.Parse(data, 0)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
602
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
603 def close(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
604 self._parser.Parse("", 1) # end of data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
605 del self._target, self._parser # get rid of circular references
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
606
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
607 class SlowParser:
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
608 """Default XML parser (based on xmllib.XMLParser)."""
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
609 # this is about 10 times slower than sgmlop, on roundtrip
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
610 # testing.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
611 def __init__(self, target):
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
612 import xmllib # lazy subclassing (!)
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
613 if xmllib.XMLParser not in SlowParser.__bases__:
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
614 SlowParser.__bases__ = (xmllib.XMLParser,)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
615 self.handle_xml = target.xml
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
616 self.unknown_starttag = target.start
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
617 self.handle_data = target.data
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
618 self.handle_cdata = target.data
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
619 self.unknown_endtag = target.end
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
620 try:
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
621 xmllib.XMLParser.__init__(self, accept_utf8=1)
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
622 except TypeError:
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
623 xmllib.XMLParser.__init__(self) # pre-2.0
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
624
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
625 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
626 # XML-RPC marshalling and unmarshalling code
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
627
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
628 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
629 # XML-RPC marshaller.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
630 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
631 # @param encoding Default encoding for 8-bit strings. The default
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
632 # value is None (interpreted as UTF-8).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
633 # @see dumps
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
634
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
635 class Marshaller:
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
636 """Generate an XML-RPC params chunk from a Python data structure.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
637
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
638 Create a Marshaller instance for each set of parameters, and use
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
639 the "dumps" method to convert your data (represented as a tuple)
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
640 to an XML-RPC params chunk. To write a fault response, pass a
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
641 Fault instance instead. You may prefer to use the "dumps" module
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
642 function for this purpose.
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
643 """
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
644
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
645 # by the way, if you don't understand what's going on in here,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
646 # that's perfectly ok.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
647
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
648 def __init__(self, encoding=None, allow_none=0):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
649 self.memo = {}
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
650 self.data = None
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
651 self.encoding = encoding
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
652 self.allow_none = allow_none
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28808
diff changeset
653
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
654 dispatch = {}
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
655
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
656 def dumps(self, values):
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
657 out = []
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
658 write = out.append
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
659 dump = self.__dump
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
660 if isinstance(values, Fault):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
661 # fault instance
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
662 write("<fault>\n")
29825
a37106ac7c8c Patch #764470: Fix marshalling of faults. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29489
diff changeset
663 dump({'faultCode': values.faultCode,
a37106ac7c8c Patch #764470: Fix marshalling of faults. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29489
diff changeset
664 'faultString': values.faultString},
a37106ac7c8c Patch #764470: Fix marshalling of faults. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29489
diff changeset
665 write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
666 write("</fault>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
667 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
668 # parameter block
19451
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
669 # FIXME: the xml-rpc specification allows us to leave out
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
670 # the entire <params> block if there are no parameters.
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
671 # however, changing this may break older code (including
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
672 # old versions of xmlrpclib.py), so this is better left as
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
673 # is for now. See @XMLRPC3 for more information. /F
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
674 write("<params>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
675 for v in values:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
676 write("<param>\n")
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
677 dump(v, write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
678 write("</param>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
679 write("</params>\n")
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
680 result = string.join(out, "")
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
681 return result
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
682
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
683 def __dump(self, value, write):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
684 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
685 f = self.dispatch[type(value)]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
686 except KeyError:
40360
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
687 # check if this object can be marshalled as a structure
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
688 try:
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
689 value.__dict__
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
690 except:
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
691 raise TypeError, "cannot marshal %s objects" % type(value)
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
692 # check if this class is a sub-class of a basic type,
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
693 # because we don't know how to marshal these types
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
694 # (e.g. a string sub-class)
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
695 for type_ in type(value).__mro__:
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
696 if type_ in self.dispatch.keys():
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
697 raise TypeError, "cannot marshal %s objects" % type(value)
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
698 f = self.dispatch[InstanceType]
40166e5011f8 Patch #1070046: Marshal new-style objects like InstanceType
Martin v. Löwis <martin@v.loewis.de>
parents: 35984
diff changeset
699 f(self, value, write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
700
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
701 def dump_nil (self, value, write):
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
702 if not self.allow_none:
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
703 raise TypeError, "cannot marshal None unless allow_none is enabled"
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
704 write("<value><nil/></value>")
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
705 dispatch[NoneType] = dump_nil
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28808
diff changeset
706
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
707 def dump_int(self, value, write):
20504
e0864aac9b6b test for int and long int overflow (allows operation on 64-bit platforms)
Skip Montanaro <skip@pobox.com>
parents: 20481
diff changeset
708 # in case ints are > 32 bits
e0864aac9b6b test for int and long int overflow (allows operation on 64-bit platforms)
Skip Montanaro <skip@pobox.com>
parents: 20481
diff changeset
709 if value > MAXINT or value < MININT:
e0864aac9b6b test for int and long int overflow (allows operation on 64-bit platforms)
Skip Montanaro <skip@pobox.com>
parents: 20481
diff changeset
710 raise OverflowError, "int exceeds XML-RPC limits"
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
711 write("<value><int>")
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
712 write(str(value))
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
713 write("</int></value>\n")
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
714 dispatch[IntType] = dump_int
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
715
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
716 if _bool_is_builtin:
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
717 def dump_bool(self, value, write):
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
718 write("<value><boolean>")
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
719 write(value and "1" or "0")
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
720 write("</boolean></value>\n")
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
721 dispatch[bool] = dump_bool
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
722
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
723 def dump_long(self, value, write):
20504
e0864aac9b6b test for int and long int overflow (allows operation on 64-bit platforms)
Skip Montanaro <skip@pobox.com>
parents: 20481
diff changeset
724 if value > MAXINT or value < MININT:
e0864aac9b6b test for int and long int overflow (allows operation on 64-bit platforms)
Skip Montanaro <skip@pobox.com>
parents: 20481
diff changeset
725 raise OverflowError, "long int exceeds XML-RPC limits"
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
726 write("<value><int>")
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
727 write(str(int(value)))
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
728 write("</int></value>\n")
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
729 dispatch[LongType] = dump_long
20363
6b1d8cb9904a allow long ints to be marshalled as ints - no check is made to the incoming
Skip Montanaro <skip@pobox.com>
parents: 20216
diff changeset
730
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
731 def dump_double(self, value, write):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
732 write("<value><double>")
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
733 write(repr(value))
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
734 write("</double></value>\n")
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
735 dispatch[FloatType] = dump_double
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
736
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
737 def dump_string(self, value, write, escape=escape):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
738 write("<value><string>")
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
739 write(escape(value))
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
740 write("</string></value>\n")
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
741 dispatch[StringType] = dump_string
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
742
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
743 if unicode:
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
744 def dump_unicode(self, value, write, escape=escape):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
745 value = value.encode(self.encoding)
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
746 write("<value><string>")
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
747 write(escape(value))
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
748 write("</string></value>\n")
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
749 dispatch[UnicodeType] = dump_unicode
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
750
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
751 def dump_array(self, value, write):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
752 i = id(value)
48160
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
753 if i in self.memo:
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
754 raise TypeError, "cannot marshal recursive sequences"
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
755 self.memo[i] = None
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
756 dump = self.__dump
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
757 write("<value><array><data>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
758 for v in value:
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
759 dump(v, write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
760 write("</data></array></value>\n")
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
761 del self.memo[i]
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
762 dispatch[TupleType] = dump_array
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
763 dispatch[ListType] = dump_array
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
764
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
765 def dump_struct(self, value, write, escape=escape):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
766 i = id(value)
48160
21f146387a63 Remove assignment to True/False and use of dict.has_key() to silence warnings
Brett Cannon <bcannon@gmail.com>
parents: 47369
diff changeset
767 if i in self.memo:
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
768 raise TypeError, "cannot marshal recursive dictionaries"
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
769 self.memo[i] = None
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
770 dump = self.__dump
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
771 write("<value><struct>\n")
32249
7409c0c370e2 [Bug #841757] Patch from /F to allow Unicode strings as struct keys
Andrew M. Kuchling <amk@amk.ca>
parents: 30838
diff changeset
772 for k, v in value.items():
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
773 write("<member>\n")
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
774 if type(k) is not StringType:
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
775 if unicode and type(k) is UnicodeType:
32249
7409c0c370e2 [Bug #841757] Patch from /F to allow Unicode strings as struct keys
Andrew M. Kuchling <amk@amk.ca>
parents: 30838
diff changeset
776 k = k.encode(self.encoding)
7409c0c370e2 [Bug #841757] Patch from /F to allow Unicode strings as struct keys
Andrew M. Kuchling <amk@amk.ca>
parents: 30838
diff changeset
777 else:
7409c0c370e2 [Bug #841757] Patch from /F to allow Unicode strings as struct keys
Andrew M. Kuchling <amk@amk.ca>
parents: 30838
diff changeset
778 raise TypeError, "dictionary key must be string"
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
779 write("<name>%s</name>\n" % escape(k))
32249
7409c0c370e2 [Bug #841757] Patch from /F to allow Unicode strings as struct keys
Andrew M. Kuchling <amk@amk.ca>
parents: 30838
diff changeset
780 dump(v, write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
781 write("</member>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
782 write("</struct></value>\n")
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
783 del self.memo[i]
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
784 dispatch[DictType] = dump_struct
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
785
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
786 if datetime:
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
787 def dump_datetime(self, value, write):
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
788 write("<value><dateTime.iso8601>")
46471
4f8261b92fc5 resolve issue 2014
Skip Montanaro <skip@pobox.com>
parents: 45459
diff changeset
789 write(_strftime(value))
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
790 write("</dateTime.iso8601></value>\n")
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
791 dispatch[datetime.datetime] = dump_datetime
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
792
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
793 def dump_instance(self, value, write):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
794 # check for special wrappers
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
795 if value.__class__ in WRAPPERS:
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
796 self.write = write
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
797 value.encode(self)
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
798 del self.write
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
799 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
800 # store instance attributes as a struct (really?)
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
801 self.dump_struct(value.__dict__, write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
802 dispatch[InstanceType] = dump_instance
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
803
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
804 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
805 # XML-RPC unmarshaller.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
806 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
807 # @see loads
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
808
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
809 class Unmarshaller:
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
810 """Unmarshal an XML-RPC response, based on incoming XML event
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
811 messages (start, data, end). Call close() to get the resulting
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
812 data structure.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
813
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
814 Note that this reader is fairly tolerant, and gladly accepts bogus
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
815 XML-RPC data without complaining (but not bogus XML).
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
816 """
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
817
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
818 # and again, if you don't understand what's going on in here,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
819 # that's perfectly ok.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
820
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
821 def __init__(self, use_datetime=0):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
822 self._type = None
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
823 self._stack = []
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
824 self._marks = []
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
825 self._data = []
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
826 self._methodname = None
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
827 self._encoding = "utf-8"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
828 self.append = self._stack.append
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
829 self._use_datetime = use_datetime
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
830 if use_datetime and not datetime:
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
831 raise ValueError, "the datetime module is not available"
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
832
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
833 def close(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
834 # return response tuple and target method
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
835 if self._type is None or self._marks:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
836 raise ResponseError()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
837 if self._type == "fault":
28089
14f65d661084 Get rid of many apply() calls.
Guido van Rossum <guido@python.org>
parents: 27345
diff changeset
838 raise Fault(**self._stack[0])
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
839 return tuple(self._stack)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
840
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
841 def getmethodname(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
842 return self._methodname
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
843
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
844 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
845 # event handlers
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
846
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
847 def xml(self, encoding, standalone):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
848 self._encoding = encoding
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
849 # FIXME: assert standalone == 1 ???
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
850
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
851 def start(self, tag, attrs):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
852 # prepare to handle this element
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
853 if tag == "array" or tag == "struct":
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
854 self._marks.append(len(self._stack))
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
855 self._data = []
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
856 self._value = (tag == "value")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
857
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
858 def data(self, text):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
859 self._data.append(text)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
860
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
861 def end(self, tag, join=string.join):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
862 # call the appropriate end tag handler
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
863 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
864 f = self.dispatch[tag]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
865 except KeyError:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
866 pass # unknown tag ?
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
867 else:
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
868 return f(self, join(self._data, ""))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
869
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
870 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
871 # accelerator support
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
872
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
873 def end_dispatch(self, tag, data):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
874 # dispatch data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
875 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
876 f = self.dispatch[tag]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
877 except KeyError:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
878 pass # unknown tag ?
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
879 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
880 return f(self, data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
881
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
882 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
883 # element decoders
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
884
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
885 dispatch = {}
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
886
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
887 def end_nil (self, data):
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
888 self.append(None)
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
889 self._value = 0
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
890 dispatch["nil"] = end_nil
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28808
diff changeset
891
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
892 def end_boolean(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
893 if data == "0":
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
894 self.append(False)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
895 elif data == "1":
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
896 self.append(True)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
897 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
898 raise TypeError, "bad boolean value"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
899 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
900 dispatch["boolean"] = end_boolean
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
901
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
902 def end_int(self, data):
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
903 self.append(int(data))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
904 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
905 dispatch["i4"] = end_int
47369
ef51fcda348b #2985: allow i8 in XMLRPC responses.
Georg Brandl <georg@python.org>
parents: 46471
diff changeset
906 dispatch["i8"] = end_int
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
907 dispatch["int"] = end_int
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
908
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
909 def end_double(self, data):
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
910 self.append(float(data))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
911 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
912 dispatch["double"] = end_double
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
913
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
914 def end_string(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
915 if self._encoding:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
916 data = _decode(data, self._encoding)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
917 self.append(_stringify(data))
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
918 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
919 dispatch["string"] = end_string
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
920 dispatch["name"] = end_string # struct keys are always strings
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
921
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
922 def end_array(self, data):
24058
37ffce2d9c3c Code modernization. Replace v=s[i]; del s[i] with single lookup v=s.pop(i)
Raymond Hettinger <python@rcn.com>
parents: 24031
diff changeset
923 mark = self._marks.pop()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
924 # map arrays to Python lists
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
925 self._stack[mark:] = [self._stack[mark:]]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
926 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
927 dispatch["array"] = end_array
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
928
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
929 def end_struct(self, data):
24058
37ffce2d9c3c Code modernization. Replace v=s[i]; del s[i] with single lookup v=s.pop(i)
Raymond Hettinger <python@rcn.com>
parents: 24031
diff changeset
930 mark = self._marks.pop()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
931 # map structs to Python dictionaries
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
932 dict = {}
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
933 items = self._stack[mark:]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
934 for i in range(0, len(items), 2):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
935 dict[_stringify(items[i])] = items[i+1]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
936 self._stack[mark:] = [dict]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
937 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
938 dispatch["struct"] = end_struct
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
939
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
940 def end_base64(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
941 value = Binary()
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
942 value.decode(data)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
943 self.append(value)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
944 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
945 dispatch["base64"] = end_base64
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
946
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
947 def end_dateTime(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
948 value = DateTime()
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
949 value.decode(data)
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
950 if self._use_datetime:
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
951 value = _datetime_type(data)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
952 self.append(value)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
953 dispatch["dateTime.iso8601"] = end_dateTime
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
954
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
955 def end_value(self, data):
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
956 # if we stumble upon a value element with no internal
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
957 # elements, treat it as a string element
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
958 if self._value:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
959 self.end_string(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
960 dispatch["value"] = end_value
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
961
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
962 def end_params(self, data):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
963 self._type = "params"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
964 dispatch["params"] = end_params
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
965
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
966 def end_fault(self, data):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
967 self._type = "fault"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
968 dispatch["fault"] = end_fault
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
969
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
970 def end_methodName(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
971 if self._encoding:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
972 data = _decode(data, self._encoding)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
973 self._methodname = data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
974 self._type = "methodName" # no params
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
975 dispatch["methodName"] = end_methodName
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
976
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
977 ## Multicall support
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
978 #
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
979
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
980 class _MultiCallMethod:
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
981 # some lesser magic to store calls made to a MultiCall object
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
982 # for batch execution
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
983 def __init__(self, call_list, name):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
984 self.__call_list = call_list
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
985 self.__name = name
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
986 def __getattr__(self, name):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
987 return _MultiCallMethod(self.__call_list, "%s.%s" % (self.__name, name))
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
988 def __call__(self, *args):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
989 self.__call_list.append((self.__name, args))
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
990
33223
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
991 class MultiCallIterator:
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
992 """Iterates over the results of a multicall. Exceptions are
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
993 thrown in response to xmlrpc faults."""
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
994
33223
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
995 def __init__(self, results):
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
996 self.results = results
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
997
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
998 def __getitem__(self, i):
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
999 item = self.results[i]
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1000 if type(item) == type({}):
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1001 raise Fault(item['faultCode'], item['faultString'])
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1002 elif type(item) == type([]):
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1003 return item[0]
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1004 else:
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1005 raise ValueError,\
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1006 "unexpected type in multicall result"
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
1007
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1008 class MultiCall:
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1009 """server -> a object used to boxcar method calls
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1010
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1011 server should be a ServerProxy object.
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1012
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1013 Methods can be added to the MultiCall using normal
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1014 method call syntax e.g.:
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1015
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1016 multicall = MultiCall(server_proxy)
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1017 multicall.add(2,3)
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1018 multicall.get_address("Guido")
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1019
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1020 To execute the multicall, call the MultiCall object e.g.:
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1021
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1022 add_result, address = multicall()
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1023 """
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
1024
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1025 def __init__(self, server):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1026 self.__server = server
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1027 self.__call_list = []
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
1028
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1029 def __repr__(self):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1030 return "<MultiCall at %x>" % id(self)
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
1031
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1032 __str__ = __repr__
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1033
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1034 def __getattr__(self, name):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1035 return _MultiCallMethod(self.__call_list, name)
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1036
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1037 def __call__(self):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1038 marshalled_list = []
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1039 for name, args in self.__call_list:
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1040 marshalled_list.append({'methodName' : name, 'params' : args})
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1041
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
1042 return MultiCallIterator(self.__server.system.multicall(marshalled_list))
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
1043
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1044 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1045 # convenience functions
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1046
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1047 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1048 # Create a parser object, and connect it to an unmarshalling instance.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1049 # This function picks the fastest available XML parser.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1050 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1051 # return A (parser, unmarshaller) tuple.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1052
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1053 def getparser(use_datetime=0):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1054 """getparser() -> parser, unmarshaller
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1055
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
1056 Create an instance of the fastest available parser, and attach it
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
1057 to an unmarshalling object. Return both objects.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1058 """
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1059 if use_datetime and not datetime:
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1060 raise ValueError, "the datetime module is not available"
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1061 if FastParser and FastUnmarshaller:
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1062 if use_datetime:
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1063 mkdatetime = _datetime_type
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1064 else:
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1065 mkdatetime = _datetime
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1066 target = FastUnmarshaller(True, False, _binary, mkdatetime, Fault)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1067 parser = FastParser(target)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1068 else:
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1069 target = Unmarshaller(use_datetime=use_datetime)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1070 if FastParser:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1071 parser = FastParser(target)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1072 elif SgmlopParser:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1073 parser = SgmlopParser(target)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1074 elif ExpatParser:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1075 parser = ExpatParser(target)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1076 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1077 parser = SlowParser(target)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1078 return parser, target
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1079
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1080 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1081 # Convert a Python tuple or a Fault instance to an XML-RPC packet.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1082 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1083 # @def dumps(params, **options)
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1084 # @param params A tuple or Fault instance.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1085 # @keyparam methodname If given, create a methodCall request for
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1086 # this method name.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1087 # @keyparam methodresponse If given, create a methodResponse packet.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1088 # If used with a tuple, the tuple must be a singleton (that is,
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1089 # it must contain exactly one element).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1090 # @keyparam encoding The packet encoding.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1091 # @return A string containing marshalled data.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1092
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
1093 def dumps(params, methodname=None, methodresponse=None, encoding=None,
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
1094 allow_none=0):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1095 """data [,options] -> marshalled data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1096
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1097 Convert an argument tuple or a Fault instance to an XML-RPC
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1098 request (or response, if the methodresponse option is used).
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1099
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
1100 In addition to the data object, the following options can be given
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
1101 as keyword arguments:
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1102
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1103 methodname: the method name for a methodCall packet
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1104
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1105 methodresponse: true to create a methodResponse packet.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1106 If this option is used with a tuple, the tuple must be
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1107 a singleton (i.e. it can contain only one element).
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1108
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1109 encoding: the packet encoding (default is UTF-8)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1110
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1111 All 8-bit strings in the data structure are assumed to use the
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1112 packet encoding. Unicode strings are automatically converted,
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
1113 where necessary.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1114 """
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1115
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
1116 assert isinstance(params, TupleType) or isinstance(params, Fault),\
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1117 "argument must be tuple or Fault instance"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1118
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1119 if isinstance(params, Fault):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1120 methodresponse = 1
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
1121 elif methodresponse and isinstance(params, TupleType):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1122 assert len(params) == 1, "response tuple must be a singleton"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1123
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1124 if not encoding:
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1125 encoding = "utf-8"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1126
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1127 if FastMarshaller:
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1128 m = FastMarshaller(encoding)
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1129 else:
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
1130 m = Marshaller(encoding, allow_none)
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1131
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1132 data = m.dumps(params)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1133
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1134 if encoding != "utf-8":
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1135 xmlheader = "<?xml version='1.0' encoding='%s'?>\n" % str(encoding)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1136 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1137 xmlheader = "<?xml version='1.0'?>\n" # utf-8 is default
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1138
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1139 # standard XML-RPC wrappings
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1140 if methodname:
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1141 # a method call
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
1142 if not isinstance(methodname, StringType):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1143 methodname = methodname.encode(encoding)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1144 data = (
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1145 xmlheader,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1146 "<methodCall>\n"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1147 "<methodName>", methodname, "</methodName>\n",
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1148 data,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1149 "</methodCall>\n"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1150 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1151 elif methodresponse:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1152 # a method response, or a fault structure
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1153 data = (
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1154 xmlheader,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1155 "<methodResponse>\n",
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1156 data,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1157 "</methodResponse>\n"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1158 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1159 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1160 return data # return as is
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1161 return string.join(data, "")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1162
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1163 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1164 # Convert an XML-RPC packet to a Python object. If the XML-RPC packet
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1165 # represents a fault condition, this function raises a Fault exception.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1166 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1167 # @param data An XML-RPC packet, given as an 8-bit string.
30723
6f15e73b59f2 Backport checkin:
Walter Dörwald <walter@livinglogic.de>
parents: 29825
diff changeset
1168 # @return A tuple containing the unpacked data, and the method name
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1169 # (None if not present).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1170 # @see Fault
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1171
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1172 def loads(data, use_datetime=0):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1173 """data -> unmarshalled data, method name
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1174
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1175 Convert an XML-RPC packet to unmarshalled data plus a method
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1176 name (None if not present).
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1177
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1178 If the XML-RPC packet represents a fault condition, this function
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1179 raises a Fault exception.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1180 """
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1181 p, u = getparser(use_datetime=use_datetime)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1182 p.feed(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1183 p.close()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1184 return u.close(), u.getmethodname()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1185
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1186
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1187 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1188 # request dispatcher
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1189
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1190 class _Method:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1191 # some magic to bind an XML-RPC method to an RPC server.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1192 # supports "nested" methods (e.g. examples.getStateName)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1193 def __init__(self, send, name):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1194 self.__send = send
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1195 self.__name = name
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1196 def __getattr__(self, name):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1197 return _Method(self.__send, "%s.%s" % (self.__name, name))
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1198 def __call__(self, *args):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1199 return self.__send(self.__name, args)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1200
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1201 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1202 # Standard transport class for XML-RPC over HTTP.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1203 # <p>
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1204 # You can create custom transports by subclassing this method, and
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1205 # overriding selected methods.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1206
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1207 class Transport:
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1208 """Handles an HTTP transaction to an XML-RPC server."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1209
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1210 # client identifier (may be overridden)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1211 user_agent = "xmlrpclib.py/%s (by www.pythonware.com)" % __version__
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1212
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1213 def __init__(self, use_datetime=0):
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1214 self._use_datetime = use_datetime
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1215
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1216 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1217 # Send a complete request, and parse the response.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1218 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1219 # @param host Target host.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1220 # @param handler Target PRC handler.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1221 # @param request_body XML-RPC request body.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1222 # @param verbose Debugging flag.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1223 # @return Parsed response.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1224
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1225 def request(self, host, handler, request_body, verbose=0):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1226 # issue XML-RPC request
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1227
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1228 h = self.make_connection(host)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1229 if verbose:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1230 h.set_debuglevel(1)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1231
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1232 self.send_request(h, handler, request_body)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1233 self.send_host(h, host)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1234 self.send_user_agent(h)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1235 self.send_content(h, request_body)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1236
50734
d09d6fe31b61 Issue 4879: Allow buffering for HTTPResponse
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 49890
diff changeset
1237 errcode, errmsg, headers = h.getreply(buffering=True)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1238
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1239 if errcode != 200:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1240 raise ProtocolError(
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1241 host + handler,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1242 errcode, errmsg,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1243 headers
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1244 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1245
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1246 self.verbose = verbose
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1247
50785
bcf6663c5c04 fix test_xmlrpc failures #4939
Benjamin Peterson <benjamin@python.org>
parents: 50734
diff changeset
1248 return self.parse_response(h.getfile())
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1249
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1250 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1251 # Create parser.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1252 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1253 # @return A 2-tuple containing a parser and a unmarshaller.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1254
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1255 def getparser(self):
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1256 # get parser and unmarshaller
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1257 return getparser(use_datetime=self._use_datetime)
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1258
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1259 ##
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1260 # Get authorization info from host parameter
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1261 # Host may be a string, or a (host, x509-dict) tuple; if a string,
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1262 # it is checked for a "user:pw@host" format, and a "Basic
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1263 # Authentication" header is added if appropriate.
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1264 #
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1265 # @param host Host descriptor (URL or (URL, x509 info) tuple).
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1266 # @return A 3-tuple containing (actual host, extra headers,
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1267 # x509 info). The header and x509 fields may be None.
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1268
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1269 def get_host_info(self, host):
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1270
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1271 x509 = {}
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
1272 if isinstance(host, TupleType):
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1273 host, x509 = host
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1274
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1275 import urllib
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1276 auth, host = urllib.splituser(host)
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1277
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1278 if auth:
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1279 import base64
25981
06e005666c42 patch #624180 (part 2 of 2):
Fredrik Lundh <fredrik@pythonware.com>
parents: 25882
diff changeset
1280 auth = base64.encodestring(urllib.unquote(auth))
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1281 auth = string.join(string.split(auth), "") # get rid of whitespace
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1282 extra_headers = [
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1283 ("Authorization", "Basic " + auth)
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1284 ]
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1285 else:
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1286 extra_headers = None
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1287
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1288 return host, extra_headers, x509
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1289
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1290 ##
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1291 # Connect to server.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1292 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1293 # @param host Target host.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1294 # @return A connection handle.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1295
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1296 def make_connection(self, host):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1297 # create a HTTP connection object from a host descriptor
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1298 import httplib
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1299 host, extra_headers, x509 = self.get_host_info(host)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1300 return httplib.HTTP(host)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1301
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1302 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1303 # Send request header.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1304 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1305 # @param connection Connection handle.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1306 # @param handler Target RPC handler.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1307 # @param request_body XML-RPC body.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1308
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1309 def send_request(self, connection, handler, request_body):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1310 connection.putrequest("POST", handler)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1311
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1312 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1313 # Send host name.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1314 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1315 # @param connection Connection handle.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1316 # @param host Host name.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1317
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1318 def send_host(self, connection, host):
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1319 host, extra_headers, x509 = self.get_host_info(host)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1320 connection.putheader("Host", host)
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1321 if extra_headers:
34552
a24e70f4684b Revert previous checkin.
Raymond Hettinger <python@rcn.com>
parents: 34551
diff changeset
1322 if isinstance(extra_headers, DictType):
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1323 extra_headers = extra_headers.items()
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1324 for key, value in extra_headers:
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1325 connection.putheader(key, value)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1326
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1327 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1328 # Send user-agent identifier.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1329 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1330 # @param connection Connection handle.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1331
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1332 def send_user_agent(self, connection):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1333 connection.putheader("User-Agent", self.user_agent)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1334
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1335 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1336 # Send request body.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1337 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1338 # @param connection Connection handle.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1339 # @param request_body XML-RPC request body.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1340
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1341 def send_content(self, connection, request_body):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1342 connection.putheader("Content-Type", "text/xml")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1343 connection.putheader("Content-Length", str(len(request_body)))
49890
ef0c5ca45441 Send HTTP headers and message body in a single send() call.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 48160
diff changeset
1344 connection.endheaders(request_body)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1345
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1346 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1347 # Parse response.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1348 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1349 # @param file Stream.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1350 # @return Response tuple and target method.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1351
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1352 def parse_response(self, file):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1353 # read response from input file/socket, and parse it
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1354
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1355 p, u = self.getparser()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1356
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1357 while 1:
50734
d09d6fe31b61 Issue 4879: Allow buffering for HTTPResponse
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 49890
diff changeset
1358 response = file.read(1024)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1359 if not response:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1360 break
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1361 if self.verbose:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1362 print "body:", repr(response)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1363 p.feed(response)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1364
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1365 file.close()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1366 p.close()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1367
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1368 return u.close()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1369
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1370 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1371 # Standard transport class for XML-RPC over HTTPS.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1372
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1373 class SafeTransport(Transport):
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1374 """Handles an HTTPS transaction to an XML-RPC server."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1375
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1376 # FIXME: mostly untested
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1377
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1378 def make_connection(self, host):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1379 # create a HTTPS connection object from a host descriptor
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1380 # host may be a string, or a (host, x509-dict) tuple
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1381 import httplib
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1382 host, extra_headers, x509 = self.get_host_info(host)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1383 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1384 HTTPS = httplib.HTTPS
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1385 except AttributeError:
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1386 raise NotImplementedError(
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1387 "your version of httplib doesn't support HTTPS"
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1388 )
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1389 else:
28089
14f65d661084 Get rid of many apply() calls.
Guido van Rossum <guido@python.org>
parents: 27345
diff changeset
1390 return HTTPS(host, None, **(x509 or {}))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1391
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1392 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1393 # Standard server proxy. This class establishes a virtual connection
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1394 # to an XML-RPC server.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1395 # <p>
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1396 # This class is available as ServerProxy and Server. New code should
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1397 # use ServerProxy, to avoid confusion.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1398 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1399 # @def ServerProxy(uri, **options)
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1400 # @param uri The connection point on the server.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1401 # @keyparam transport A transport factory, compatible with the
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1402 # standard transport class.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1403 # @keyparam encoding The default encoding used for 8-bit strings
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1404 # (default is UTF-8).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1405 # @keyparam verbose Use a true value to enable debugging output.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1406 # (printed to standard output).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1407 # @see Transport
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1408
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1409 class ServerProxy:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1410 """uri [,options] -> a logical connection to an XML-RPC server
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1411
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1412 uri is the connection point on the server, given as
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1413 scheme://host/target.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1414
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1415 The standard implementation always supports the "http" scheme. If
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1416 SSL socket support is available (Python 2.0), it also supports
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1417 "https".
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1418
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1419 If the target part and the slash preceding it are both omitted,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1420 "/RPC2" is assumed.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1421
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1422 The following options can be given as keyword arguments:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1423
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1424 transport: a transport factory
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1425 encoding: the request encoding (default is UTF-8)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1426
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1427 All 8-bit strings passed to the server proxy are assumed to use
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1428 the given encoding.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1429 """
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1430
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
1431 def __init__(self, uri, transport=None, encoding=None, verbose=0,
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1432 allow_none=0, use_datetime=0):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1433 # establish a "logical" server connection
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1434
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1435 # get the url
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1436 import urllib
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1437 type, uri = urllib.splittype(uri)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1438 if type not in ("http", "https"):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1439 raise IOError, "unsupported XML-RPC protocol"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1440 self.__host, self.__handler = urllib.splithost(uri)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1441 if not self.__handler:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1442 self.__handler = "/RPC2"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1443
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1444 if transport is None:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1445 if type == "https":
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1446 transport = SafeTransport(use_datetime=use_datetime)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1447 else:
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1448 transport = Transport(use_datetime=use_datetime)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1449 self.__transport = transport
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1450
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1451 self.__encoding = encoding
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1452 self.__verbose = verbose
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
1453 self.__allow_none = allow_none
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28808
diff changeset
1454
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1455 def __request(self, methodname, params):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1456 # call a method on the remote server
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1457
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
1458 request = dumps(params, methodname, encoding=self.__encoding,
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
1459 allow_none=self.__allow_none)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1460
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1461 response = self.__transport.request(
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1462 self.__host,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1463 self.__handler,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1464 request,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1465 verbose=self.__verbose
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1466 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1467
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1468 if len(response) == 1:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1469 response = response[0]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1470
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1471 return response
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1472
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1473 def __repr__(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1474 return (
19450
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
1475 "<ServerProxy for %s%s>" %
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1476 (self.__host, self.__handler)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1477 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1478
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1479 __str__ = __repr__
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
1480
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1481 def __getattr__(self, name):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1482 # magic method dispatcher
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1483 return _Method(self.__request, name)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1484
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1485 # note: to call a remote object with an non-standard name, use
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1486 # result getattr(server, "strange-python-name")(args)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1487
19450
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
1488 # compatibility
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1489
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1490 Server = ServerProxy
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1491
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1492 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1493 # test code
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1494
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1495 if __name__ == "__main__":
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1496
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1497 # simple test program (from the XML-RPC specification)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1498
19450
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
1499 # server = ServerProxy("http://localhost:8000") # local server
33223
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1500 server = ServerProxy("http://time.xmlrpc.com/RPC2")
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1501
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1502 print server
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1503
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1504 try:
33223
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1505 print server.currentTime.getCurrentTime()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1506 except Error, v:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1507 print "ERROR", v
33223
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1508
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1509 multi = MultiCall(server)
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1510 multi.currentTime.getCurrentTime()
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1511 multi.currentTime.getCurrentTime()
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1512 try:
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1513 for response in multi():
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1514 print response
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1515 except Error, v:
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1516 print "ERROR", v