annotate Lib/xmlrpc/client.py @ 79691:05c8928362ee

Merge __next__ method link fixes with 3.3.
author Ezio Melotti <ezio.melotti@gmail.com>
date Fri, 12 Oct 2012 13:46:37 +0300
parents a3e8f8d10dce
children 15a391919deb
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
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
88 """
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
89 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
90
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
91 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
92 implement XML-RPC servers.
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 Exported exceptions:
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
95
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
96 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
97 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
98 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
99 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
100
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
101 Exported classes:
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
102
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
103 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
104
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
105 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
106 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
107 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
108 XML-RPC value
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
109 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
110
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
111 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
112 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
113 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
114 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
115
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
116 Exported constants:
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
117
73214
e88e7ef6b53d Cleanup xmlrpc: remove obsolete comments, unused imports. Add test for bytes marshalling.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73213
diff changeset
118 (none)
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
119
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
120 Exported functions:
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
121
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
122 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
123 to an unmarshalling object
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
124 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
125 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
126 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
127 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
128 """
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
129
73214
e88e7ef6b53d Cleanup xmlrpc: remove obsolete comments, unused imports. Add test for bytes marshalling.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73213
diff changeset
130 import base64
73219
197d703fb23e Fix User-Agent for the xmlrpc.client, and catch KeyboardInterrupt for the standalone xmlrpc.server.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73216
diff changeset
131 import sys
73214
e88e7ef6b53d Cleanup xmlrpc: remove obsolete comments, unused imports. Add test for bytes marshalling.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73213
diff changeset
132 import time
73228
2096158376e5 Let's assume that the datetime module is always available.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73219
diff changeset
133 from datetime import datetime
47318
e1fcc3881cb6 Create http package. #2883.
Georg Brandl <georg@python.org>
parents: 47288
diff changeset
134 import http.client
75237
a3e8f8d10dce #13973: move a couple of imports at module level. Patch by Tshepang Lekhonkhobe.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 73575
diff changeset
135 import urllib.parse
54563
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
136 from xml.parsers import expat
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
137 import socket
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
138 import errno
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
139 from io import BytesIO
55344
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
140 try:
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
141 import gzip
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
142 except ImportError:
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
143 gzip = None #python can be built without zlib/gzip support
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
144
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
145 # --------------------------------------------------------------------
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
146 # Internal stuff
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
147
41479
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
148 def escape(s):
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
149 s = s.replace("&", "&amp;")
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
150 s = s.replace("<", "&lt;")
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
151 return s.replace(">", "&gt;",)
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
152
73219
197d703fb23e Fix User-Agent for the xmlrpc.client, and catch KeyboardInterrupt for the standalone xmlrpc.server.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73216
diff changeset
153 # used in User-Agent header sent
197d703fb23e Fix User-Agent for the xmlrpc.client, and catch KeyboardInterrupt for the standalone xmlrpc.server.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73216
diff changeset
154 __version__ = sys.version[:3]
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
155
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
156 # xmlrpc integer limits
40644
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
157 MAXINT = 2**31-1
1c26505c1de6 Rip out 'long' and 'L'-suffixed integer literals.
Guido van Rossum <guido@python.org>
parents: 40587
diff changeset
158 MININT = -2**31
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
159
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
160 # --------------------------------------------------------------------
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
161 # 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
162 # 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
163
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
164 # Ranges of errors
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
165 PARSE_ERROR = -32700
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
166 SERVER_ERROR = -32600
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
167 APPLICATION_ERROR = -32500
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
168 SYSTEM_ERROR = -32400
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
169 TRANSPORT_ERROR = -32300
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
170
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
171 # Specific errors
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
172 NOT_WELLFORMED_ERROR = -32700
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
173 UNSUPPORTED_ENCODING = -32701
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
174 INVALID_ENCODING_CHAR = -32702
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
175 INVALID_XMLRPC = -32600
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
176 METHOD_NOT_FOUND = -32601
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
177 INVALID_METHOD_PARAMS = -32602
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
178 INTERNAL_ERROR = -32603
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
179
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
180 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
181 # Exceptions
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 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
184 # 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
185
19450
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
186 class Error(Exception):
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
187 """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
188 def __str__(self):
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
189 return repr(self)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
190
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
191 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
192 # 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
193 # 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
194 # (OK).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
195 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
196 # @param url The target URL.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
197 # @param errcode The HTTP error code.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
198 # @param errmsg The HTTP error message.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
199 # @param headers The HTTP header dictionary.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
200
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
201 class ProtocolError(Error):
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
202 """Indicates an HTTP protocol error."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
203 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
204 Error.__init__(self)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
205 self.url = url
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
206 self.errcode = errcode
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
207 self.errmsg = errmsg
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
208 self.headers = headers
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
209 def __repr__(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
210 return (
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
211 "<ProtocolError for %s: %s %s>" %
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
212 (self.url, self.errcode, self.errmsg)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
213 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
214
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
215 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
216 # 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
217 # 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
218 # malformed.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
219
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
220 class ResponseError(Error):
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
221 """Indicates a broken response package."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
222 pass
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
223
24031
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 # 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
226 # raised by the unmarshalling layer, if the XML-RPC response contains
73214
e88e7ef6b53d Cleanup xmlrpc: remove obsolete comments, unused imports. Add test for bytes marshalling.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73213
diff changeset
227 # a fault string. This exception can also be used as a class, to
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
228 # generate a fault XML-RPC message.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
229 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
230 # @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
231 # @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
232
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
233 class Fault(Error):
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
234 """Indicates an XML-RPC fault package."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
235 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
236 Error.__init__(self)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
237 self.faultCode = faultCode
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
238 self.faultString = faultString
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
239 def __repr__(self):
73214
e88e7ef6b53d Cleanup xmlrpc: remove obsolete comments, unused imports. Add test for bytes marshalling.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73213
diff changeset
240 return "<Fault %s: %r>" % (self.faultCode, self.faultString)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
241
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 # Special values
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
244
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
245 ##
47288
346a99df5889 Create xmlrpc package. Issue #2886.
Georg Brandl <georg@python.org>
parents: 46478
diff changeset
246 # Backwards compatibility
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
247
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
248 boolean = Boolean = bool
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
249
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
250 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
251 # 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
252 # the format used by XML-RPC.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
253 # <p>
73265
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
254 # The value can be given as a datetime object, as a string in the
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
255 # format "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
256 # 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
257 # 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
258 # tuple.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
259 #
73265
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
260 # @param value The time, given as a datetime object, an ISO 8601 string,
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
261 # a time tuple, or an integer time value.
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
262
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
263
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
264 # Issue #13305: different format codes across platforms
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
265 _day0 = datetime(1, 1, 1)
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
266 if _day0.strftime('%Y') == '0001': # Mac OS X
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
267 def _iso8601_format(value):
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
268 return value.strftime("%Y%m%dT%H:%M:%S")
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
269 elif _day0.strftime('%4Y') == '0001': # Linux
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
270 def _iso8601_format(value):
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
271 return value.strftime("%4Y%m%dT%H:%M:%S")
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
272 else:
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
273 def _iso8601_format(value):
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
274 return value.strftime("%Y%m%dT%H:%M:%S").zfill(17)
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
275 del _day0
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
276
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
277
46478
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
278 def _strftime(value):
73228
2096158376e5 Let's assume that the datetime module is always available.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73219
diff changeset
279 if isinstance(value, datetime):
73265
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
280 return _iso8601_format(value)
46478
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
281
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
282 if not isinstance(value, (tuple, time.struct_time)):
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
283 if value == 0:
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
284 value = time.time()
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
285 value = time.localtime(value)
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
286
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
287 return "%04d%02d%02dT%02d:%02d:%02d" % value[:6]
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
288
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
289 class DateTime:
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
290 """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
291 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
292 value.
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
293 """
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
294
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
295 def __init__(self, value=0):
46478
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
296 if isinstance(value, str):
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
297 self.value = value
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
298 else:
beb7abcd6c01 Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 45471
diff changeset
299 self.value = _strftime(value)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
300
45471
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
301 def make_comparable(self, other):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
302 if isinstance(other, DateTime):
45471
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
303 s = self.value
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
304 o = other.value
73228
2096158376e5 Let's assume that the datetime module is always available.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73219
diff changeset
305 elif isinstance(other, datetime):
45471
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
306 s = self.value
73265
3f025427f02b Fix regression due to changeset 2096158376e5 (issue #13305).
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73228
diff changeset
307 o = _iso8601_format(other)
73213
f3d454b20b35 Closes #13291: NameError in xmlrpc package.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 68257
diff changeset
308 elif isinstance(other, str):
45471
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
309 s = self.value
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
310 o = other
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
311 elif hasattr(other, "timetuple"):
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
312 s = self.timetuple()
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
313 o = other.timetuple()
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
314 else:
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
315 otype = (hasattr(other, "__class__")
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
316 and other.__class__.__name__
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
317 or type(other))
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
318 raise TypeError("Can't compare %s and %s" %
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
319 (self.__class__.__name__, otype))
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
320 return s, o
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
321
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
322 def __lt__(self, other):
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
323 s, o = self.make_comparable(other)
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
324 return s < o
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
325
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
326 def __le__(self, other):
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
327 s, o = self.make_comparable(other)
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
328 return s <= o
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
329
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
330 def __gt__(self, other):
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
331 s, o = self.make_comparable(other)
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
332 return s > o
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
333
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
334 def __ge__(self, other):
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
335 s, o = self.make_comparable(other)
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
336 return s >= o
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
337
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
338 def __eq__(self, other):
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
339 s, o = self.make_comparable(other)
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
340 return s == o
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
341
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
342 def __ne__(self, other):
45471
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
343 s, o = self.make_comparable(other)
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
344 return s != o
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
345
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
346 def timetuple(self):
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
347 return time.strptime(self.value, "%Y%m%dT%H:%M:%S")
7dd2c1746267 Merged revisions 60990-61002 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 43777
diff changeset
348
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
349 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
350 # Get date/time value.
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 # @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
353
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
354 def __str__(self):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
355 return self.value
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
356
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
357 def __repr__(self):
73214
e88e7ef6b53d Cleanup xmlrpc: remove obsolete comments, unused imports. Add test for bytes marshalling.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73213
diff changeset
358 return "<DateTime %r at %x>" % (self.value, id(self))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
359
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
360 def decode(self, data):
41479
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
361 self.value = str(data).strip()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
362
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
363 def encode(self, out):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
364 out.write("<value><dateTime.iso8601>")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
365 out.write(self.value)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
366 out.write("</dateTime.iso8601></value>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
367
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
368 def _datetime(data):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
369 # 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
370 value = DateTime()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
371 value.decode(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
372 return value
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
373
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
374 def _datetime_type(data):
73228
2096158376e5 Let's assume that the datetime module is always available.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73219
diff changeset
375 return datetime.strptime(data, "%Y%m%dT%H:%M:%S")
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
376
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
377 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
378 # 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
379 # 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
380 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
381 # @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
382
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
383 class Binary:
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
384 """Wrapper for binary data."""
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
385
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
386 def __init__(self, data=None):
42916
9fb8331cec2c Force test_xmlrpc to pass. I'm not happy with how I did this, but I don't
Guido van Rossum <guido@python.org>
parents: 42720
diff changeset
387 if data is None:
9fb8331cec2c Force test_xmlrpc to pass. I'm not happy with how I did this, but I don't
Guido van Rossum <guido@python.org>
parents: 42720
diff changeset
388 data = b""
9fb8331cec2c Force test_xmlrpc to pass. I'm not happy with how I did this, but I don't
Guido van Rossum <guido@python.org>
parents: 42720
diff changeset
389 else:
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
390 if not isinstance(data, (bytes, bytearray)):
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
391 raise TypeError("expected bytes or bytearray, not %s" %
42916
9fb8331cec2c Force test_xmlrpc to pass. I'm not happy with how I did this, but I don't
Guido van Rossum <guido@python.org>
parents: 42720
diff changeset
392 data.__class__.__name__)
9fb8331cec2c Force test_xmlrpc to pass. I'm not happy with how I did this, but I don't
Guido van Rossum <guido@python.org>
parents: 42720
diff changeset
393 data = bytes(data) # Make a copy of the bytes!
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
394 self.data = data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
395
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
396 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
397 # Get buffer contents.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
398 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
399 # @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
400
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
401 def __str__(self):
42916
9fb8331cec2c Force test_xmlrpc to pass. I'm not happy with how I did this, but I don't
Guido van Rossum <guido@python.org>
parents: 42720
diff changeset
402 return str(self.data, "latin-1") # XXX encoding?!
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
403
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
404 def __eq__(self, other):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
405 if isinstance(other, Binary):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
406 other = other.data
39644
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
407 return self.data == other
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
408
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
409 def __ne__(self, other):
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
410 if isinstance(other, Binary):
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
411 other = other.data
13d5e5f0e993 Restructure comparison dramatically. There is no longer a default
Guido van Rossum <guido@python.org>
parents: 39575
diff changeset
412 return self.data != other
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
413
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
414 def decode(self, data):
54564
18d823e8b602 #3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents: 54563
diff changeset
415 self.data = base64.decodebytes(data)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
416
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
417 def encode(self, out):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
418 out.write("<value><base64>\n")
54564
18d823e8b602 #3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents: 54563
diff changeset
419 encoded = base64.encodebytes(self.data)
42407
468621569be8 In cases where dealing with base64, do the conversion but then get the ASCII
Brett Cannon <bcannon@gmail.com>
parents: 42394
diff changeset
420 out.write(encoded.decode('ascii'))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
421 out.write("</base64></value>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
422
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
423 def _binary(data):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
424 # 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
425 value = Binary()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
426 value.decode(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
427 return value
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
428
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
429 WRAPPERS = (DateTime, Binary)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
430
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
431 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
432 # XML parsers
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
433
54563
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
434 class ExpatParser:
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
435 # fast expat parser for Python 2.0 and later.
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
436 def __init__(self, target):
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
437 self._parser = parser = expat.ParserCreate(None, None)
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
438 self._target = target
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
439 parser.StartElementHandler = target.start
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
440 parser.EndElementHandler = target.end
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
441 parser.CharacterDataHandler = target.data
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
442 encoding = None
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
443 target.xml(encoding, None)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
444
54563
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
445 def feed(self, data):
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
446 self._parser.Parse(data, 0)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
447
54563
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
448 def close(self):
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
449 self._parser.Parse("", 1) # end of data
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
450 del self._target, self._parser # get rid of circular references
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
451
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
452 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
453 # XML-RPC marshalling and unmarshalling code
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
454
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
455 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
456 # XML-RPC marshaller.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
457 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
458 # @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
459 # 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
460 # @see dumps
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
461
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
462 class Marshaller:
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
463 """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
464
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
465 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
466 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
467 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
468 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
469 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
470 """
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
471
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
472 # 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
473 # that's perfectly ok.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
474
56002
fa91270b6087 Merged revisions 74821,74828-74831,74833,74835 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54564
diff changeset
475 def __init__(self, encoding=None, allow_none=False):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
476 self.memo = {}
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
477 self.data = None
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
478 self.encoding = encoding
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
479 self.allow_none = allow_none
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28808
diff changeset
480
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
481 dispatch = {}
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
482
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
483 def dumps(self, values):
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
484 out = []
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
485 write = out.append
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
486 dump = self.__dump
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
487 if isinstance(values, Fault):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
488 # fault instance
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
489 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
490 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
491 '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
492 write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
493 write("</fault>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
494 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
495 # parameter block
19451
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
496 # FIXME: the xml-rpc specification allows us to leave out
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
497 # the entire <params> block if there are no parameters.
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
498 # however, changing this may break older code (including
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
499 # old versions of xmlrpclib.py), so this is better left as
2817f1d3adbe untabification
Fredrik Lundh <fredrik@pythonware.com>
parents: 19450
diff changeset
500 # 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
501 write("<params>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
502 for v in values:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
503 write("<param>\n")
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
504 dump(v, write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
505 write("</param>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
506 write("</params>\n")
41479
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
507 result = "".join(out)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
508 return result
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
509
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
510 def __dump(self, value, write):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
511 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
512 f = self.dispatch[type(value)]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
513 except KeyError:
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
514 # check if this object can be marshalled as a structure
73215
013d2881beb5 Issue #13293: Better error message when trying to marshal bytes using xmlrpc.client.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73214
diff changeset
515 if not hasattr(value, '__dict__'):
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
516 raise TypeError("cannot marshal %s objects" % type(value))
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
517 # check if this class is a sub-class of a basic type,
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
518 # because we don't know how to marshal these types
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
519 # (e.g. a string sub-class)
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
520 for type_ in type(value).__mro__:
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
521 if type_ in self.dispatch.keys():
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
522 raise TypeError("cannot marshal %s objects" % type(value))
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
523 # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
524 # for the p3yk merge, this should probably be fixed more neatly.
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
525 f = self.dispatch["_arbitrary_instance"]
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
526 f(self, value, write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
527
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
528 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
529 if not self.allow_none:
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
530 raise TypeError("cannot marshal None unless allow_none is enabled")
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
531 write("<value><nil/></value>")
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
532 dispatch[type(None)] = dump_nil
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28808
diff changeset
533
47288
346a99df5889 Create xmlrpc package. Issue #2886.
Georg Brandl <georg@python.org>
parents: 46478
diff changeset
534 def dump_bool(self, value, write):
346a99df5889 Create xmlrpc package. Issue #2886.
Georg Brandl <georg@python.org>
parents: 46478
diff changeset
535 write("<value><boolean>")
346a99df5889 Create xmlrpc package. Issue #2886.
Georg Brandl <georg@python.org>
parents: 46478
diff changeset
536 write(value and "1" or "0")
346a99df5889 Create xmlrpc package. Issue #2886.
Georg Brandl <georg@python.org>
parents: 46478
diff changeset
537 write("</boolean></value>\n")
346a99df5889 Create xmlrpc package. Issue #2886.
Georg Brandl <georg@python.org>
parents: 46478
diff changeset
538 dispatch[bool] = dump_bool
27345
180067c2880f add support for Python's bool type to xmlrpclib - patch # 559288
Skip Montanaro <skip@pobox.com>
parents: 25981
diff changeset
539
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
540 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
541 if value > MAXINT or value < MININT:
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
542 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
543 write("<value><int>")
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
544 write(str(int(value)))
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
545 write("</int></value>\n")
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
546 dispatch[int] = 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
547
73076
67053b135ed9 Cleanup code: remove int/long idioms and simplify a while statement.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 68257
diff changeset
548 # backward compatible
67053b135ed9 Cleanup code: remove int/long idioms and simplify a while statement.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 68257
diff changeset
549 dump_int = dump_long
67053b135ed9 Cleanup code: remove int/long idioms and simplify a while statement.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 68257
diff changeset
550
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
551 def dump_double(self, value, write):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
552 write("<value><double>")
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
553 write(repr(value))
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
554 write("</double></value>\n")
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
555 dispatch[float] = dump_double
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
556
41890
249b525e1ac0 Make xmlrpclib fail less (test_sundry passes).
Guido van Rossum <guido@python.org>
parents: 41760
diff changeset
557 def dump_unicode(self, value, write, escape=escape):
249b525e1ac0 Make xmlrpclib fail less (test_sundry passes).
Guido van Rossum <guido@python.org>
parents: 41760
diff changeset
558 write("<value><string>")
249b525e1ac0 Make xmlrpclib fail less (test_sundry passes).
Guido van Rossum <guido@python.org>
parents: 41760
diff changeset
559 write(escape(value))
249b525e1ac0 Make xmlrpclib fail less (test_sundry passes).
Guido van Rossum <guido@python.org>
parents: 41760
diff changeset
560 write("</string></value>\n")
249b525e1ac0 Make xmlrpclib fail less (test_sundry passes).
Guido van Rossum <guido@python.org>
parents: 41760
diff changeset
561 dispatch[str] = dump_unicode
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
562
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
563 def dump_bytes(self, value, write):
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
564 write("<value><base64>\n")
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
565 encoded = base64.encodebytes(value)
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
566 write(encoded.decode('ascii'))
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
567 write("</base64></value>\n")
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
568 dispatch[bytes] = dump_bytes
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
569 dispatch[bytearray] = dump_bytes
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
570
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
571 def dump_array(self, value, write):
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
572 i = id(value)
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 38397
diff changeset
573 if i in self.memo:
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
574 raise TypeError("cannot marshal recursive sequences")
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
575 self.memo[i] = None
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
576 dump = self.__dump
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
577 write("<value><array><data>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
578 for v in value:
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
579 dump(v, write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
580 write("</data></array></value>\n")
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
581 del self.memo[i]
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
582 dispatch[tuple] = dump_array
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
583 dispatch[list] = dump_array
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
584
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
585 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
586 i = id(value)
39575
63237fcefd99 Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents: 38397
diff changeset
587 if i in self.memo:
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
588 raise TypeError("cannot marshal recursive dictionaries")
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
589 self.memo[i] = None
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
590 dump = self.__dump
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
591 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
592 for k, v in value.items():
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
593 write("<member>\n")
43577
ace45b361e87 Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents: 43152
diff changeset
594 if not isinstance(k, str):
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
595 raise TypeError("dictionary key must be string")
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
596 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
597 dump(v, write)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
598 write("</member>\n")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
599 write("</struct></value>\n")
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
600 del self.memo[i]
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
601 dispatch[dict] = dump_struct
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
602
73228
2096158376e5 Let's assume that the datetime module is always available.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73219
diff changeset
603 def dump_datetime(self, value, write):
2096158376e5 Let's assume that the datetime module is always available.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73219
diff changeset
604 write("<value><dateTime.iso8601>")
2096158376e5 Let's assume that the datetime module is always available.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73219
diff changeset
605 write(_strftime(value))
2096158376e5 Let's assume that the datetime module is always available.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73219
diff changeset
606 write("</dateTime.iso8601></value>\n")
2096158376e5 Let's assume that the datetime module is always available.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73219
diff changeset
607 dispatch[datetime] = dump_datetime
34578
607c48b5efd7 accept datetime.datetime instances when marshalling;
Fred Drake <fdrake@acm.org>
parents: 34552
diff changeset
608
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
609 def dump_instance(self, value, write):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
610 # check for special wrappers
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
611 if value.__class__ in WRAPPERS:
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
612 self.write = write
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
613 value.encode(self)
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
614 del self.write
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
615 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
616 # 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
617 self.dump_struct(value.__dict__, write)
37893
d18a2c866609 Fix the unit tests by adding dispatch tables for DateTime and Binary.
Guido van Rossum <guido@python.org>
parents: 35984
diff changeset
618 dispatch[DateTime] = dump_instance
d18a2c866609 Fix the unit tests by adding dispatch tables for DateTime and Binary.
Guido van Rossum <guido@python.org>
parents: 35984
diff changeset
619 dispatch[Binary] = dump_instance
40450
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
620 # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
621 # for the p3yk merge, this should probably be fixed more neatly.
cc992d75d5b3 Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents: 39644
diff changeset
622 dispatch["_arbitrary_instance"] = dump_instance
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
623
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
624 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
625 # XML-RPC unmarshaller.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
626 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
627 # @see loads
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
628
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
629 class Unmarshaller:
19691
933e812974c3 Added docstring by Neal Norwitz. This closes SF bug #450981.
Fred Drake <fdrake@acm.org>
parents: 19451
diff changeset
630 """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
631 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
632 data structure.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
633
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
634 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
635 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
636 """
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
637
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
638 # 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
639 # that's perfectly ok.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
640
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
641 def __init__(self, use_datetime=False, use_builtin_types=False):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
642 self._type = None
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
643 self._stack = []
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
644 self._marks = []
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
645 self._data = []
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
646 self._methodname = None
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
647 self._encoding = "utf-8"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
648 self.append = self._stack.append
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
649 self._use_datetime = use_builtin_types or use_datetime
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
650 self._use_bytes = use_builtin_types
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
651
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
652 def close(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
653 # return response tuple and target method
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
654 if self._type is None or self._marks:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
655 raise ResponseError()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
656 if self._type == "fault":
28089
14f65d661084 Get rid of many apply() calls.
Guido van Rossum <guido@python.org>
parents: 27345
diff changeset
657 raise Fault(**self._stack[0])
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
658 return tuple(self._stack)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
659
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
660 def getmethodname(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
661 return self._methodname
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
662
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
663 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
664 # event handlers
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
665
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
666 def xml(self, encoding, standalone):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
667 self._encoding = encoding
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
668 # FIXME: assert standalone == 1 ???
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
669
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
670 def start(self, tag, attrs):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
671 # prepare to handle this element
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
672 if tag == "array" or tag == "struct":
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
673 self._marks.append(len(self._stack))
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
674 self._data = []
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
675 self._value = (tag == "value")
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
676
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
677 def data(self, text):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
678 self._data.append(text)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
679
41479
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
680 def end(self, tag):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
681 # call the appropriate end tag handler
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
682 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
683 f = self.dispatch[tag]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
684 except KeyError:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
685 pass # unknown tag ?
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
686 else:
41479
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
687 return f(self, "".join(self._data))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
688
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
689 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
690 # accelerator support
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
691
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
692 def end_dispatch(self, tag, data):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
693 # dispatch data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
694 try:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
695 f = self.dispatch[tag]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
696 except KeyError:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
697 pass # unknown tag ?
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
698 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
699 return f(self, data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
700
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
701 #
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
702 # element decoders
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
703
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
704 dispatch = {}
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
705
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
706 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
707 self.append(None)
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
708 self._value = 0
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
709 dispatch["nil"] = end_nil
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28808
diff changeset
710
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
711 def end_boolean(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
712 if data == "0":
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
713 self.append(False)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
714 elif data == "1":
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
715 self.append(True)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
716 else:
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
717 raise TypeError("bad boolean value")
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
718 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
719 dispatch["boolean"] = end_boolean
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
720
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
721 def end_int(self, data):
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
722 self.append(int(data))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
723 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
724 dispatch["i4"] = end_int
47557
98827a21e352 Merged revisions 63724,63726,63732,63744,63754-63755,63757-63758,63760,63775,63781-63782,63787,63805-63808,63818-63819,63823-63824 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47318
diff changeset
725 dispatch["i8"] = end_int
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
726 dispatch["int"] = end_int
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
727
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
728 def end_double(self, data):
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
729 self.append(float(data))
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
730 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
731 dispatch["double"] = end_double
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
732
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
733 def end_string(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
734 if self._encoding:
55396
f79043369625 Issue #6360: Simplify string decoding in xmlrpc.client.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55346
diff changeset
735 data = data.decode(self._encoding)
f79043369625 Issue #6360: Simplify string decoding in xmlrpc.client.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55346
diff changeset
736 self.append(data)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
737 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
738 dispatch["string"] = end_string
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
739 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
740
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
741 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
742 mark = self._marks.pop()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
743 # map arrays to Python lists
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
744 self._stack[mark:] = [self._stack[mark:]]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
745 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
746 dispatch["array"] = end_array
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
747
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
748 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
749 mark = self._marks.pop()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
750 # map structs to Python dictionaries
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
751 dict = {}
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
752 items = self._stack[mark:]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
753 for i in range(0, len(items), 2):
55396
f79043369625 Issue #6360: Simplify string decoding in xmlrpc.client.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55346
diff changeset
754 dict[items[i]] = items[i+1]
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
755 self._stack[mark:] = [dict]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
756 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
757 dispatch["struct"] = end_struct
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
758
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
759 def end_base64(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
760 value = Binary()
42916
9fb8331cec2c Force test_xmlrpc to pass. I'm not happy with how I did this, but I don't
Guido van Rossum <guido@python.org>
parents: 42720
diff changeset
761 value.decode(data.encode("ascii"))
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
762 if self._use_bytes:
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
763 value = value.data
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
764 self.append(value)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
765 self._value = 0
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
766 dispatch["base64"] = end_base64
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
767
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
768 def end_dateTime(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
769 value = DateTime()
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
770 value.decode(data)
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
771 if self._use_datetime:
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
772 value = _datetime_type(data)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
773 self.append(value)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
774 dispatch["dateTime.iso8601"] = end_dateTime
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
775
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
776 def end_value(self, data):
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
777 # 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
778 # elements, treat it as a string element
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
779 if self._value:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
780 self.end_string(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
781 dispatch["value"] = end_value
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
782
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
783 def end_params(self, data):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
784 self._type = "params"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
785 dispatch["params"] = end_params
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
786
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
787 def end_fault(self, data):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
788 self._type = "fault"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
789 dispatch["fault"] = end_fault
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
790
20208
ba5aaa6bc1e5 restored 1.5.2 compatibility
Fredrik Lundh <fredrik@pythonware.com>
parents: 20206
diff changeset
791 def end_methodName(self, data):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
792 if self._encoding:
55396
f79043369625 Issue #6360: Simplify string decoding in xmlrpc.client.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 55346
diff changeset
793 data = data.decode(self._encoding)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
794 self._methodname = data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
795 self._type = "methodName" # no params
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
796 dispatch["methodName"] = end_methodName
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
797
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
798 ## Multicall support
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
799 #
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
800
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
801 class _MultiCallMethod:
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
802 # 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
803 # for batch execution
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
804 def __init__(self, call_list, name):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
805 self.__call_list = call_list
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
806 self.__name = name
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
807 def __getattr__(self, name):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
808 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
809 def __call__(self, *args):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
810 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
811
33223
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
812 class MultiCallIterator:
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
813 """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
814 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
815
33223
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
816 def __init__(self, results):
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
817 self.results = results
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
818
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
819 def __getitem__(self, i):
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
820 item = self.results[i]
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
821 if type(item) == type({}):
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
822 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
823 elif type(item) == type([]):
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
824 return item[0]
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
825 else:
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
826 raise ValueError("unexpected type in multicall result")
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
827
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
828 class MultiCall:
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
829 """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
830
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
831 server should be a ServerProxy object.
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
832
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
833 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
834 method call syntax e.g.:
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
835
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
836 multicall = MultiCall(server_proxy)
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
837 multicall.add(2,3)
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
838 multicall.get_address("Guido")
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
839
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
840 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
841
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
842 add_result, address = multicall()
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
843 """
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
844
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
845 def __init__(self, server):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
846 self.__server = server
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
847 self.__call_list = []
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
848
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
849 def __repr__(self):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
850 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
851
30822
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
852 __str__ = __repr__
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
853
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
854 def __getattr__(self, name):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
855 return _MultiCallMethod(self.__call_list, name)
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
856
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
857 def __call__(self):
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
858 marshalled_list = []
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
859 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
860 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
861
8cd691b73845 Patch #531629: Add multicall support.
Martin v. Löwis <martin@v.loewis.de>
parents: 30723
diff changeset
862 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
863
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
864 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
865 # convenience functions
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
866
47288
346a99df5889 Create xmlrpc package. Issue #2886.
Georg Brandl <georg@python.org>
parents: 46478
diff changeset
867 FastMarshaller = FastParser = FastUnmarshaller = None
346a99df5889 Create xmlrpc package. Issue #2886.
Georg Brandl <georg@python.org>
parents: 46478
diff changeset
868
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
869 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
870 # 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
871 # 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
872 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
873 # return A (parser, unmarshaller) tuple.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
874
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
875 def getparser(use_datetime=False, use_builtin_types=False):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
876 """getparser() -> parser, unmarshaller
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
877
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
878 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
879 to an unmarshalling object. Return both objects.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
880 """
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
881 if FastParser and FastUnmarshaller:
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
882 if use_builtin_types:
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
883 mkdatetime = _datetime_type
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
884 mkbytes = base64.decodebytes
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
885 elif use_datetime:
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
886 mkdatetime = _datetime_type
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
887 mkbytes = _binary
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
888 else:
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
889 mkdatetime = _datetime
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
890 mkbytes = _binary
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
891 target = FastUnmarshaller(True, False, mkbytes, mkdatetime, Fault)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
892 parser = FastParser(target)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
893 else:
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
894 target = Unmarshaller(use_datetime=use_datetime, use_builtin_types=use_builtin_types)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
895 if FastParser:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
896 parser = FastParser(target)
54563
5ecdb829434f Remove mentions of the nonexisting SlowParser in xmlrpc.client.
Georg Brandl <georg@python.org>
parents: 54562
diff changeset
897 else:
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
898 parser = ExpatParser(target)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
899 return parser, target
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
900
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
901 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
902 # 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
903 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
904 # @def dumps(params, **options)
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
905 # @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
906 # @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
907 # this method name.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
908 # @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
909 # 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
910 # it must contain exactly one element).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
911 # @keyparam encoding The packet encoding.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
912 # @return A string containing marshalled data.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
913
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
914 def dumps(params, methodname=None, methodresponse=None, encoding=None,
56002
fa91270b6087 Merged revisions 74821,74828-74831,74833,74835 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54564
diff changeset
915 allow_none=False):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
916 """data [,options] -> marshalled data
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
917
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
918 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
919 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
920
19840
377746a38972 more xmlrpclib tweaks: fixed repr(Fault()); enable UTF-8 parsing in
Fredrik Lundh <fredrik@pythonware.com>
parents: 19835
diff changeset
921 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
922 as keyword arguments:
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
923
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
924 methodname: the method name for a methodCall packet
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
925
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
926 methodresponse: true to create a methodResponse packet.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
927 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
928 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
929
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
930 encoding: the packet encoding (default is UTF-8)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
931
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
932 All byte strings in the data structure are assumed to use the
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
933 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
934 where necessary.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
935 """
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
936
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
937 assert isinstance(params, (tuple, Fault)), "argument must be tuple or Fault instance"
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
938 if isinstance(params, Fault):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
939 methodresponse = 1
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
940 elif methodresponse and isinstance(params, tuple):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
941 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
942
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
943 if not encoding:
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
944 encoding = "utf-8"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
945
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
946 if FastMarshaller:
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
947 m = FastMarshaller(encoding)
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
948 else:
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
949 m = Marshaller(encoding, allow_none)
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
950
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
951 data = m.dumps(params)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
952
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
953 if encoding != "utf-8":
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
954 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
955 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
956 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
957
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
958 # standard XML-RPC wrappings
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
959 if methodname:
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
960 # a method call
43577
ace45b361e87 Patch# 1258 by Christian Heimes: kill basestring.
Guido van Rossum <guido@python.org>
parents: 43152
diff changeset
961 if not isinstance(methodname, str):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
962 methodname = methodname.encode(encoding)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
963 data = (
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
964 xmlheader,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
965 "<methodCall>\n"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
966 "<methodName>", methodname, "</methodName>\n",
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
967 data,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
968 "</methodCall>\n"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
969 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
970 elif methodresponse:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
971 # a method response, or a fault structure
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
972 data = (
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
973 xmlheader,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
974 "<methodResponse>\n",
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
975 data,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
976 "</methodResponse>\n"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
977 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
978 else:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
979 return data # return as is
41479
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
980 return "".join(data)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
981
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
982 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
983 # 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
984 # 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
985 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
986 # @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
987 # @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
988 # (None if not present).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
989 # @see Fault
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
990
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
991 def loads(data, use_datetime=False, use_builtin_types=False):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
992 """data -> unmarshalled data, method name
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
993
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
994 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
995 name (None if not present).
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
996
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
997 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
998 raises a Fault exception.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
999 """
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1000 p, u = getparser(use_datetime=use_datetime, use_builtin_types=use_builtin_types)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1001 p.feed(data)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1002 p.close()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1003 return u.close(), u.getmethodname()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1004
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1005 ##
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1006 # Encode a string using the gzip content encoding such as specified by the
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1007 # Content-Encoding: gzip
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1008 # in the HTTP header, as described in RFC 1952
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1009 #
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1010 # @param data the unencoded data
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1011 # @return the encoded data
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1012
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1013 def gzip_encode(data):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1014 """data -> gzip encoded data
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1015
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1016 Encode data using the gzip content encoding as described in RFC 1952
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1017 """
55344
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
1018 if not gzip:
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
1019 raise NotImplementedError
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1020 f = BytesIO()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1021 gzf = gzip.GzipFile(mode="wb", fileobj=f, compresslevel=1)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1022 gzf.write(data)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1023 gzf.close()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1024 encoded = f.getvalue()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1025 f.close()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1026 return encoded
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1027
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1028 ##
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1029 # Decode a string using the gzip content encoding such as specified by the
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1030 # Content-Encoding: gzip
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1031 # in the HTTP header, as described in RFC 1952
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1032 #
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1033 # @param data The encoded data
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1034 # @return the unencoded data
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1035 # @raises ValueError if data is not correctly coded.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1036
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1037 def gzip_decode(data):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1038 """gzip encoded data -> unencoded data
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1039
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1040 Decode data using the gzip content encoding as described in RFC 1952
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1041 """
55344
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
1042 if not gzip:
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
1043 raise NotImplementedError
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1044 f = BytesIO(data)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1045 gzf = gzip.GzipFile(mode="rb", fileobj=f)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1046 try:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1047 decoded = gzf.read()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1048 except IOError:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1049 raise ValueError("invalid data")
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1050 f.close()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1051 gzf.close()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1052 return decoded
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1053
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1054 ##
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1055 # Return a decoded file-like object for the gzip encoding
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1056 # as described in RFC 1952.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1057 #
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1058 # @param response A stream supporting a read() method
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1059 # @return a file-like object that the decoded data can be read() from
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1060
55346
c0acae19b487 merging revision 74100 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55344
diff changeset
1061 class GzipDecodedResponse(gzip.GzipFile if gzip else object):
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1062 """a file-like object to decode a response encoded with the gzip
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1063 method, as described in RFC 1952.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1064 """
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1065 def __init__(self, response):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1066 #response doesn't support tell() and read(), required by
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1067 #GzipFile
55344
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
1068 if not gzip:
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
1069 raise NotImplementedError
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1070 self.io = BytesIO(response.read())
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1071 gzip.GzipFile.__init__(self, mode="rb", fileobj=self.io)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1072
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1073 def close(self):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1074 gzip.GzipFile.close(self)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1075 self.io.close()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1076
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1077
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1078 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1079 # request dispatcher
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1080
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1081 class _Method:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1082 # 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
1083 # supports "nested" methods (e.g. examples.getStateName)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1084 def __init__(self, send, name):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1085 self.__send = send
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1086 self.__name = name
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1087 def __getattr__(self, name):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1088 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
1089 def __call__(self, *args):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1090 return self.__send(self.__name, args)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1091
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1092 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1093 # 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
1094 # <p>
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1095 # 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
1096 # overriding selected methods.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1097
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1098 class Transport:
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1099 """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
1100
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1101 # client identifier (may be overridden)
73219
197d703fb23e Fix User-Agent for the xmlrpc.client, and catch KeyboardInterrupt for the standalone xmlrpc.server.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73216
diff changeset
1102 user_agent = "Python-xmlrpc/%s" % __version__
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1103
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1104 #if true, we'll request gzip encoding
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1105 accept_gzip_encoding = True
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1106
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1107 # if positive, encode request using gzip if it exceeds this threshold
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1108 # note that many server will get confused, so only use it if you know
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1109 # that they can decode such a request
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1110 encode_threshold = None #None = don't encode
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1111
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1112 def __init__(self, use_datetime=False, use_builtin_types=False):
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1113 self._use_datetime = use_datetime
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1114 self._use_builtin_types = use_builtin_types
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1115 self._connection = (None, None)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1116 self._extra_headers = []
34956
404088503a78 Add better datetime support to xmlrpclib module. Closes patch #1120353.
Skip Montanaro <skip@pobox.com>
parents: 34582
diff changeset
1117
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1118 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1119 # Send a complete request, and parse the response.
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1120 # Retry request if a cached connection has disconnected.
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1121 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1122 # @param host Target host.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1123 # @param handler Target PRC handler.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1124 # @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
1125 # @param verbose Debugging flag.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1126 # @return Parsed response.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1127
56002
fa91270b6087 Merged revisions 74821,74828-74831,74833,74835 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54564
diff changeset
1128 def request(self, host, handler, request_body, verbose=False):
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1129 #retry request once if cached connection has gone cold
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1130 for i in (0, 1):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1131 try:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1132 return self.single_request(host, handler, request_body, verbose)
55087
c7da0dc6eb0c http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55028
diff changeset
1133 except socket.error as e:
63192
5aa726414f8f #9032: XML-RPC client: Transport.request() retries on EPIPE error
Victor Stinner <victor.stinner@haypocalc.com>
parents: 55997
diff changeset
1134 if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
55087
c7da0dc6eb0c http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55028
diff changeset
1135 raise
c7da0dc6eb0c http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55028
diff changeset
1136 except http.client.BadStatusLine: #close after we sent request
c7da0dc6eb0c http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55028
diff changeset
1137 if i:
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1138 raise
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1139
55997
31c236c53b02 Use true booleans and PEP8 for argdefaults.
Georg Brandl <georg@python.org>
parents: 55396
diff changeset
1140 def single_request(self, host, handler, request_body, verbose=False):
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1141 # issue XML-RPC request
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1142 try:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1143 http_conn = self.send_request(host, handler, request_body, verbose)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1144 resp = http_conn.getresponse()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1145 if resp.status == 200:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1146 self.verbose = verbose
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1147 return self.parse_response(resp)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1148
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1149 except Fault:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1150 raise
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1151 except Exception:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1152 #All unexpected errors leave connection in
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1153 # a strange state, so we clear it.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1154 self.close()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1155 raise
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1156
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1157 #We got an error response.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1158 #Discard any response data and raise exception
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1159 if resp.getheader("content-length", ""):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1160 resp.read()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1161 raise ProtocolError(
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1162 host + handler,
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1163 resp.status, resp.reason,
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1164 dict(resp.getheaders())
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1165 )
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1166
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1167
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1168 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1169 # Create parser.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1170 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1171 # @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
1172
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1173 def getparser(self):
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1174 # get parser and unmarshaller
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1175 return getparser(use_datetime=self._use_datetime,
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1176 use_builtin_types=self._use_builtin_types)
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1177
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1178 ##
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1179 # 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
1180 # 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
1181 # 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
1182 # 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
1183 #
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1184 # @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
1185 # @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
1186 # 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
1187
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1188 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
1189
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1190 x509 = {}
41986
6464cc638faa Merged revisions 55795-55816 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41969
diff changeset
1191 if isinstance(host, tuple):
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1192 host, x509 = host
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1193
48334
5a416a6417d3 Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 47557
diff changeset
1194 auth, host = urllib.parse.splituser(host)
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1195
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1196 if auth:
51594
ca1d99d9d691 part of #3613: fix get_host_info() usage of base64.encodestring().
Georg Brandl <georg@python.org>
parents: 51265
diff changeset
1197 auth = urllib.parse.unquote_to_bytes(auth)
54564
18d823e8b602 #3613: add base64.encodebytes and decodebytes as the new spelling of encodestring and decodestring; deprecate the latter.
Georg Brandl <georg@python.org>
parents: 54563
diff changeset
1198 auth = base64.encodebytes(auth).decode("utf-8")
41479
9657395c25e5 Remove the SlowParser class because it depended on the xmllib module
Neal Norwitz <nnorwitz@gmail.com>
parents: 40775
diff changeset
1199 auth = "".join(auth.split()) # get rid of whitespace
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1200 extra_headers = [
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1201 ("Authorization", "Basic " + auth)
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1202 ]
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1203 else:
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1204 extra_headers = []
25882
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1205
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1206 return host, extra_headers, x509
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1207
6f18508bed3d add support for basic authentication, based on patch #624180
Fredrik Lundh <fredrik@pythonware.com>
parents: 24058
diff changeset
1208 ##
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1209 # Connect to server.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1210 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1211 # @param host Target host.
42589
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1212 # @return An HTTPConnection object
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1213
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1214 def make_connection(self, host):
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1215 #return an existing connection if possible. This allows
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1216 #HTTP/1.1 keep-alive.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1217 if self._connection and host == self._connection[0]:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1218 return self._connection[1]
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1219 # create a HTTP connection object from a host descriptor
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1220 chost, self._extra_headers, x509 = self.get_host_info(host)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1221 self._connection = host, http.client.HTTPConnection(chost)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1222 return self._connection[1]
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1223
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1224 ##
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1225 # Clear any cached connection object.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1226 # Used in the event of socket errors.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1227 #
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1228 def close(self):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1229 if self._connection[1]:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1230 self._connection[1].close()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1231 self._connection = (None, None)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1232
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1233 ##
42589
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1234 # Send HTTP request.
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1235 #
42589
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1236 # @param host Host descriptor (URL or (URL, x509 info) tuple).
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1237 # @param handler Targer RPC handler (a path relative to host)
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1238 # @param request_body The XML-RPC request body
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1239 # @param debug Enable debugging if debug is true.
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1240 # @return An HTTPConnection.
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1241
42589
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1242 def send_request(self, host, handler, request_body, debug):
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1243 connection = self.make_connection(host)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1244 headers = self._extra_headers[:]
42589
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1245 if debug:
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1246 connection.set_debuglevel(1)
55344
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
1247 if self.accept_gzip_encoding and gzip:
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1248 connection.putrequest("POST", handler, skip_accept_encoding=True)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1249 headers.append(("Accept-Encoding", "gzip"))
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1250 else:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1251 connection.putrequest("POST", handler)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1252 headers.append(("Content-Type", "text/xml"))
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1253 headers.append(("User-Agent", self.user_agent))
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1254 self.send_headers(connection, headers)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1255 self.send_content(connection, request_body)
42589
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1256 return connection
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1257
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1258 ##
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1259 # Send request headers.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1260 # This function provides a useful hook for subclassing
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1261 #
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1262 # @param connection httpConnection.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1263 # @param headers list of key,value pairs for HTTP headers
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1264
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1265 def send_headers(self, connection, headers):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1266 for key, val in headers:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1267 connection.putheader(key, val)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1268
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1269 ##
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1270 # Send request body.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1271 # This function provides a useful hook for subclassing
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1272 #
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1273 # @param connection httpConnection.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1274 # @param request_body XML-RPC request body.
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1275
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1276 def send_content(self, connection, request_body):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1277 #optionally encode the request
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1278 if (self.encode_threshold is not None and
55344
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
1279 self.encode_threshold < len(request_body) and
e62957a0ee14 porting revision 74098 from trunk:
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 55087
diff changeset
1280 gzip):
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1281 connection.putheader("Content-Encoding", "gzip")
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1282 request_body = gzip_encode(request_body)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1283
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1284 connection.putheader("Content-Length", str(len(request_body)))
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1285 connection.endheaders(request_body)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1286
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1287 ##
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1288 # Parse response.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1289 #
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1290 # @param file Stream.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1291 # @return Response tuple and target method.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1292
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1293 def parse_response(self, response):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1294 # read response data from httpresponse, and parse it
66790
c718cb786aeb Fix Issue8194 - Fix incompatible API change in the parse_respones for xmlrpclib.
Senthil Kumaran <orsenthil@gmail.com>
parents: 66240
diff changeset
1295 # Check for new http response object, otherwise it is a file object.
c718cb786aeb Fix Issue8194 - Fix incompatible API change in the parse_respones for xmlrpclib.
Senthil Kumaran <orsenthil@gmail.com>
parents: 66240
diff changeset
1296 if hasattr(response, 'getheader'):
c718cb786aeb Fix Issue8194 - Fix incompatible API change in the parse_respones for xmlrpclib.
Senthil Kumaran <orsenthil@gmail.com>
parents: 66240
diff changeset
1297 if response.getheader("Content-Encoding", "") == "gzip":
c718cb786aeb Fix Issue8194 - Fix incompatible API change in the parse_respones for xmlrpclib.
Senthil Kumaran <orsenthil@gmail.com>
parents: 66240
diff changeset
1298 stream = GzipDecodedResponse(response)
c718cb786aeb Fix Issue8194 - Fix incompatible API change in the parse_respones for xmlrpclib.
Senthil Kumaran <orsenthil@gmail.com>
parents: 66240
diff changeset
1299 else:
c718cb786aeb Fix Issue8194 - Fix incompatible API change in the parse_respones for xmlrpclib.
Senthil Kumaran <orsenthil@gmail.com>
parents: 66240
diff changeset
1300 stream = response
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1301 else:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1302 stream = response
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1303
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1304 p, u = self.getparser()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1305
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1306 while 1:
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1307 data = stream.read(1024)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1308 if not data:
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1309 break
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1310 if self.verbose:
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1311 print("body:", repr(data))
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1312 p.feed(data)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1313
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1314 if stream is not response:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1315 stream.close()
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1316 p.close()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1317
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1318 return u.close()
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1319
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1320 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1321 # 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
1322
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1323 class SafeTransport(Transport):
19835
9cf1338fd8d9 sync with pythonware codebase: much faster import (doesn't import
Fredrik Lundh <fredrik@pythonware.com>
parents: 19691
diff changeset
1324 """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
1325
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1326 # FIXME: mostly untested
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1327
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1328 def make_connection(self, host):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1329 if self._connection and host == self._connection[0]:
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1330 return self._connection[1]
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1331
66241
a019bb4ffb50 Merged revisions 86523 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 66234
diff changeset
1332 if not hasattr(http.client, "HTTPSConnection"):
42589
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1333 raise NotImplementedError(
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1334 "your version of http.client doesn't support HTTPS")
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1335 # create a HTTPS connection object from a host descriptor
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1336 # host may be a string, or a (host, x509-dict) tuple
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1337 chost, self._extra_headers, x509 = self.get_host_info(host)
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1338 self._connection = host, http.client.HTTPSConnection(chost,
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1339 None, **(x509 or {}))
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1340 return self._connection[1]
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1341
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1342 ##
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1343 # 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
1344 # to an XML-RPC server.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1345 # <p>
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1346 # 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
1347 # use ServerProxy, to avoid confusion.
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 # @def ServerProxy(uri, **options)
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1350 # @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
1351 # @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
1352 # standard transport class.
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1353 # @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
1354 # (default is UTF-8).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1355 # @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
1356 # (printed to standard output).
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1357 # @see Transport
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1358
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1359 class ServerProxy:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1360 """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
1361
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1362 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
1363 scheme://host/target.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1364
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1365 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
1366 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
1367 "https".
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1368
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1369 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
1370 "/RPC2" is assumed.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1371
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1372 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
1373
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1374 transport: a transport factory
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1375 encoding: the request encoding (default is UTF-8)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1376
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1377 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
1378 the given encoding.
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1379 """
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1380
56002
fa91270b6087 Merged revisions 74821,74828-74831,74833,74835 via svnmerge from
Georg Brandl <georg@python.org>
parents: 54564
diff changeset
1381 def __init__(self, uri, transport=None, encoding=None, verbose=False,
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1382 allow_none=False, use_datetime=False, use_builtin_types=False):
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1383 # establish a "logical" server connection
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1384
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1385 # get the url
48334
5a416a6417d3 Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 47557
diff changeset
1386 type, uri = urllib.parse.splittype(uri)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1387 if type not in ("http", "https"):
43020
907a45df1295 Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents: 42917
diff changeset
1388 raise IOError("unsupported XML-RPC protocol")
48334
5a416a6417d3 Make a new urllib package .
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 47557
diff changeset
1389 self.__host, self.__handler = urllib.parse.splithost(uri)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1390 if not self.__handler:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1391 self.__handler = "/RPC2"
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1392
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1393 if transport is None:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1394 if type == "https":
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1395 handler = SafeTransport
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1396 else:
73575
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1397 handler = Transport
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1398 transport = handler(use_datetime=use_datetime,
0175883d9513 Closes #13297: use bytes type to send and receive binary data through XMLRPC.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 73265
diff changeset
1399 use_builtin_types=use_builtin_types)
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1400 self.__transport = transport
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1401
52668
cef8b8259ac9 Fix for issue5040. Adding support for unicode message passing and tests for unicode message and test for Content-Length.
Senthil Kumaran <orsenthil@gmail.com>
parents: 51594
diff changeset
1402 self.__encoding = encoding or 'utf-8'
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1403 self.__verbose = verbose
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
1404 self.__allow_none = allow_none
29087
526f37fb380d Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 28808
diff changeset
1405
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1406 def __close(self):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1407 self.__transport.close()
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1408
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1409 def __request(self, methodname, params):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1410 # call a method on the remote server
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1411
28808
2ba20fc9f495 [Patch #628208] Add optional support for the 'nil' extension
Andrew M. Kuchling <amk@amk.ca>
parents: 28802
diff changeset
1412 request = dumps(params, methodname, encoding=self.__encoding,
52668
cef8b8259ac9 Fix for issue5040. Adding support for unicode message passing and tests for unicode message and test for Content-Length.
Senthil Kumaran <orsenthil@gmail.com>
parents: 51594
diff changeset
1413 allow_none=self.__allow_none).encode(self.__encoding)
18477
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 response = self.__transport.request(
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1416 self.__host,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1417 self.__handler,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1418 request,
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1419 verbose=self.__verbose
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1420 )
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 if len(response) == 1:
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1423 response = response[0]
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1424
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1425 return response
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 def __repr__(self):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1428 return (
19450
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
1429 "<ServerProxy for %s%s>" %
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1430 (self.__host, self.__handler)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1431 )
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1432
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1433 __str__ = __repr__
30838
19bb1b2fb233 SF patch #834015: Remove imports of unused modules
Raymond Hettinger <python@rcn.com>
parents: 30822
diff changeset
1434
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1435 def __getattr__(self, name):
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1436 # magic method dispatcher
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1437 return _Method(self.__request, name)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1438
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1439 # 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
1440 # result getattr(server, "strange-python-name")(args)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1441
55028
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1442 def __call__(self, attr):
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1443 """A workaround to get special attributes on the ServerProxy
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1444 without interfering with the magic __getattr__
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1445 """
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1446 if attr == "close":
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1447 return self.__close
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1448 elif attr == "transport":
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1449 return self.__transport
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1450 raise AttributeError("Attribute %r not found" % (attr,))
366c8a4e5a46 http://bugs.python.org/issue6267
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 54564
diff changeset
1451
19450
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
1452 # compatibility
24031
d10f1c6d9ee9 merged with SLAB codebase (version 1.0.1)
Fredrik Lundh <fredrik@pythonware.com>
parents: 23628
diff changeset
1453
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1454 Server = ServerProxy
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1455
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1456 # --------------------------------------------------------------------
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1457 # test code
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1458
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1459 if __name__ == "__main__":
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 # simple test program (from the XML-RPC specification)
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1462
19450
cee1decc4ff2 updated to current PythonWare version (1.0b3). fixed type checks in
Fredrik Lundh <fredrik@pythonware.com>
parents: 18477
diff changeset
1463 # 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
1464 server = ServerProxy("http://time.xmlrpc.com/RPC2")
18477
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1465
c397d4cd837d xmlrpclib for python 2.2; initial checkin
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1466 try:
40775
4cdf21a0dbbc Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
1467 print(server.currentTime.getCurrentTime())
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
1468 except Error as v:
40775
4cdf21a0dbbc Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
1469 print("ERROR", v)
33223
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1470
42589
a528f7f8f97a Change xmlrpclib to use the newer httplib interface.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 42407
diff changeset
1471 # The server at xmlrpc.com doesn't seem to support multicall anymore.
33223
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1472 multi = MultiCall(server)
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1473 multi.currentTime.getCurrentTime()
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1474 multi.currentTime.getCurrentTime()
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1475 try:
8abd322a013a Replace yield with sequence class. Fixes #1009803.
Martin v. Löwis <martin@v.loewis.de>
parents: 33209
diff changeset
1476 for response in multi():
40775
4cdf21a0dbbc Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
1477 print(response)
40587
6b18a095c2e7 SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents: 40450
diff changeset
1478 except Error as v:
40775
4cdf21a0dbbc Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents: 40644
diff changeset
1479 print("ERROR", v)