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