Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3..../xmlrpc
File: client.py
#
[0] Fix | Delete
# XML-RPC CLIENT LIBRARY
[1] Fix | Delete
# $Id$
[2] Fix | Delete
#
[3] Fix | Delete
# an XML-RPC client interface for Python.
[4] Fix | Delete
#
[5] Fix | Delete
# the marshalling and response parser code can also be used to
[6] Fix | Delete
# implement XML-RPC servers.
[7] Fix | Delete
#
[8] Fix | Delete
# Notes:
[9] Fix | Delete
# this version is designed to work with Python 2.1 or newer.
[10] Fix | Delete
#
[11] Fix | Delete
# History:
[12] Fix | Delete
# 1999-01-14 fl Created
[13] Fix | Delete
# 1999-01-15 fl Changed dateTime to use localtime
[14] Fix | Delete
# 1999-01-16 fl Added Binary/base64 element, default to RPC2 service
[15] Fix | Delete
# 1999-01-19 fl Fixed array data element (from Skip Montanaro)
[16] Fix | Delete
# 1999-01-21 fl Fixed dateTime constructor, etc.
[17] Fix | Delete
# 1999-02-02 fl Added fault handling, handle empty sequences, etc.
[18] Fix | Delete
# 1999-02-10 fl Fixed problem with empty responses (from Skip Montanaro)
[19] Fix | Delete
# 1999-06-20 fl Speed improvements, pluggable parsers/transports (0.9.8)
[20] Fix | Delete
# 2000-11-28 fl Changed boolean to check the truth value of its argument
[21] Fix | Delete
# 2001-02-24 fl Added encoding/Unicode/SafeTransport patches
[22] Fix | Delete
# 2001-02-26 fl Added compare support to wrappers (0.9.9/1.0b1)
[23] Fix | Delete
# 2001-03-28 fl Make sure response tuple is a singleton
[24] Fix | Delete
# 2001-03-29 fl Don't require empty params element (from Nicholas Riley)
[25] Fix | Delete
# 2001-06-10 fl Folded in _xmlrpclib accelerator support (1.0b2)
[26] Fix | Delete
# 2001-08-20 fl Base xmlrpclib.Error on built-in Exception (from Paul Prescod)
[27] Fix | Delete
# 2001-09-03 fl Allow Transport subclass to override getparser
[28] Fix | Delete
# 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup)
[29] Fix | Delete
# 2001-10-01 fl Remove containers from memo cache when done with them
[30] Fix | Delete
# 2001-10-01 fl Use faster escape method (80% dumps speedup)
[31] Fix | Delete
# 2001-10-02 fl More dumps microtuning
[32] Fix | Delete
# 2001-10-04 fl Make sure import expat gets a parser (from Guido van Rossum)
[33] Fix | Delete
# 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow
[34] Fix | Delete
# 2001-10-17 sm Test for int and long overflow (allows use on 64-bit systems)
[35] Fix | Delete
# 2001-11-12 fl Use repr() to marshal doubles (from Paul Felix)
[36] Fix | Delete
# 2002-03-17 fl Avoid buffered read when possible (from James Rucker)
[37] Fix | Delete
# 2002-04-07 fl Added pythondoc comments
[38] Fix | Delete
# 2002-04-16 fl Added __str__ methods to datetime/binary wrappers
[39] Fix | Delete
# 2002-05-15 fl Added error constants (from Andrew Kuchling)
[40] Fix | Delete
# 2002-06-27 fl Merged with Python CVS version
[41] Fix | Delete
# 2002-10-22 fl Added basic authentication (based on code from Phillip Eby)
[42] Fix | Delete
# 2003-01-22 sm Add support for the bool type
[43] Fix | Delete
# 2003-02-27 gvr Remove apply calls
[44] Fix | Delete
# 2003-04-24 sm Use cStringIO if available
[45] Fix | Delete
# 2003-04-25 ak Add support for nil
[46] Fix | Delete
# 2003-06-15 gn Add support for time.struct_time
[47] Fix | Delete
# 2003-07-12 gp Correct marshalling of Faults
[48] Fix | Delete
# 2003-10-31 mvl Add multicall support
[49] Fix | Delete
# 2004-08-20 mvl Bump minimum supported Python version to 2.1
[50] Fix | Delete
# 2014-12-02 ch/doko Add workaround for gzip bomb vulnerability
[51] Fix | Delete
#
[52] Fix | Delete
# Copyright (c) 1999-2002 by Secret Labs AB.
[53] Fix | Delete
# Copyright (c) 1999-2002 by Fredrik Lundh.
[54] Fix | Delete
#
[55] Fix | Delete
# info@pythonware.com
[56] Fix | Delete
# http://www.pythonware.com
[57] Fix | Delete
#
[58] Fix | Delete
# --------------------------------------------------------------------
[59] Fix | Delete
# The XML-RPC client interface is
[60] Fix | Delete
#
[61] Fix | Delete
# Copyright (c) 1999-2002 by Secret Labs AB
[62] Fix | Delete
# Copyright (c) 1999-2002 by Fredrik Lundh
[63] Fix | Delete
#
[64] Fix | Delete
# By obtaining, using, and/or copying this software and/or its
[65] Fix | Delete
# associated documentation, you agree that you have read, understood,
[66] Fix | Delete
# and will comply with the following terms and conditions:
[67] Fix | Delete
#
[68] Fix | Delete
# Permission to use, copy, modify, and distribute this software and
[69] Fix | Delete
# its associated documentation for any purpose and without fee is
[70] Fix | Delete
# hereby granted, provided that the above copyright notice appears in
[71] Fix | Delete
# all copies, and that both that copyright notice and this permission
[72] Fix | Delete
# notice appear in supporting documentation, and that the name of
[73] Fix | Delete
# Secret Labs AB or the author not be used in advertising or publicity
[74] Fix | Delete
# pertaining to distribution of the software without specific, written
[75] Fix | Delete
# prior permission.
[76] Fix | Delete
#
[77] Fix | Delete
# SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
[78] Fix | Delete
# TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT-
[79] Fix | Delete
# ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR
[80] Fix | Delete
# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
[81] Fix | Delete
# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
[82] Fix | Delete
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
[83] Fix | Delete
# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
[84] Fix | Delete
# OF THIS SOFTWARE.
[85] Fix | Delete
# --------------------------------------------------------------------
[86] Fix | Delete
[87] Fix | Delete
"""
[88] Fix | Delete
An XML-RPC client interface for Python.
[89] Fix | Delete
[90] Fix | Delete
The marshalling and response parser code can also be used to
[91] Fix | Delete
implement XML-RPC servers.
[92] Fix | Delete
[93] Fix | Delete
Exported exceptions:
[94] Fix | Delete
[95] Fix | Delete
Error Base class for client errors
[96] Fix | Delete
ProtocolError Indicates an HTTP protocol error
[97] Fix | Delete
ResponseError Indicates a broken response package
[98] Fix | Delete
Fault Indicates an XML-RPC fault package
[99] Fix | Delete
[100] Fix | Delete
Exported classes:
[101] Fix | Delete
[102] Fix | Delete
ServerProxy Represents a logical connection to an XML-RPC server
[103] Fix | Delete
[104] Fix | Delete
MultiCall Executor of boxcared xmlrpc requests
[105] Fix | Delete
DateTime dateTime wrapper for an ISO 8601 string or time tuple or
[106] Fix | Delete
localtime integer value to generate a "dateTime.iso8601"
[107] Fix | Delete
XML-RPC value
[108] Fix | Delete
Binary binary data wrapper
[109] Fix | Delete
[110] Fix | Delete
Marshaller Generate an XML-RPC params chunk from a Python data structure
[111] Fix | Delete
Unmarshaller Unmarshal an XML-RPC response from incoming XML event message
[112] Fix | Delete
Transport Handles an HTTP transaction to an XML-RPC server
[113] Fix | Delete
SafeTransport Handles an HTTPS transaction to an XML-RPC server
[114] Fix | Delete
[115] Fix | Delete
Exported constants:
[116] Fix | Delete
[117] Fix | Delete
(none)
[118] Fix | Delete
[119] Fix | Delete
Exported functions:
[120] Fix | Delete
[121] Fix | Delete
getparser Create instance of the fastest available parser & attach
[122] Fix | Delete
to an unmarshalling object
[123] Fix | Delete
dumps Convert an argument tuple or a Fault instance to an XML-RPC
[124] Fix | Delete
request (or response, if the methodresponse option is used).
[125] Fix | Delete
loads Convert an XML-RPC packet to unmarshalled data plus a method
[126] Fix | Delete
name (None if not present).
[127] Fix | Delete
"""
[128] Fix | Delete
[129] Fix | Delete
import base64
[130] Fix | Delete
import sys
[131] Fix | Delete
import time
[132] Fix | Delete
from datetime import datetime
[133] Fix | Delete
from decimal import Decimal
[134] Fix | Delete
import http.client
[135] Fix | Delete
import urllib.parse
[136] Fix | Delete
from xml.parsers import expat
[137] Fix | Delete
import errno
[138] Fix | Delete
from io import BytesIO
[139] Fix | Delete
try:
[140] Fix | Delete
import gzip
[141] Fix | Delete
except ImportError:
[142] Fix | Delete
gzip = None #python can be built without zlib/gzip support
[143] Fix | Delete
[144] Fix | Delete
# --------------------------------------------------------------------
[145] Fix | Delete
# Internal stuff
[146] Fix | Delete
[147] Fix | Delete
def escape(s):
[148] Fix | Delete
s = s.replace("&", "&")
[149] Fix | Delete
s = s.replace("<", "&lt;")
[150] Fix | Delete
return s.replace(">", "&gt;",)
[151] Fix | Delete
[152] Fix | Delete
# used in User-Agent header sent
[153] Fix | Delete
__version__ = '%d.%d' % sys.version_info[:2]
[154] Fix | Delete
[155] Fix | Delete
# xmlrpc integer limits
[156] Fix | Delete
MAXINT = 2**31-1
[157] Fix | Delete
MININT = -2**31
[158] Fix | Delete
[159] Fix | Delete
# --------------------------------------------------------------------
[160] Fix | Delete
# Error constants (from Dan Libby's specification at
[161] Fix | Delete
# http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php)
[162] Fix | Delete
[163] Fix | Delete
# Ranges of errors
[164] Fix | Delete
PARSE_ERROR = -32700
[165] Fix | Delete
SERVER_ERROR = -32600
[166] Fix | Delete
APPLICATION_ERROR = -32500
[167] Fix | Delete
SYSTEM_ERROR = -32400
[168] Fix | Delete
TRANSPORT_ERROR = -32300
[169] Fix | Delete
[170] Fix | Delete
# Specific errors
[171] Fix | Delete
NOT_WELLFORMED_ERROR = -32700
[172] Fix | Delete
UNSUPPORTED_ENCODING = -32701
[173] Fix | Delete
INVALID_ENCODING_CHAR = -32702
[174] Fix | Delete
INVALID_XMLRPC = -32600
[175] Fix | Delete
METHOD_NOT_FOUND = -32601
[176] Fix | Delete
INVALID_METHOD_PARAMS = -32602
[177] Fix | Delete
INTERNAL_ERROR = -32603
[178] Fix | Delete
[179] Fix | Delete
# --------------------------------------------------------------------
[180] Fix | Delete
# Exceptions
[181] Fix | Delete
[182] Fix | Delete
##
[183] Fix | Delete
# Base class for all kinds of client-side errors.
[184] Fix | Delete
[185] Fix | Delete
class Error(Exception):
[186] Fix | Delete
"""Base class for client errors."""
[187] Fix | Delete
def __str__(self):
[188] Fix | Delete
return repr(self)
[189] Fix | Delete
[190] Fix | Delete
##
[191] Fix | Delete
# Indicates an HTTP-level protocol error. This is raised by the HTTP
[192] Fix | Delete
# transport layer, if the server returns an error code other than 200
[193] Fix | Delete
# (OK).
[194] Fix | Delete
#
[195] Fix | Delete
# @param url The target URL.
[196] Fix | Delete
# @param errcode The HTTP error code.
[197] Fix | Delete
# @param errmsg The HTTP error message.
[198] Fix | Delete
# @param headers The HTTP header dictionary.
[199] Fix | Delete
[200] Fix | Delete
class ProtocolError(Error):
[201] Fix | Delete
"""Indicates an HTTP protocol error."""
[202] Fix | Delete
def __init__(self, url, errcode, errmsg, headers):
[203] Fix | Delete
Error.__init__(self)
[204] Fix | Delete
self.url = url
[205] Fix | Delete
self.errcode = errcode
[206] Fix | Delete
self.errmsg = errmsg
[207] Fix | Delete
self.headers = headers
[208] Fix | Delete
def __repr__(self):
[209] Fix | Delete
return (
[210] Fix | Delete
"<%s for %s: %s %s>" %
[211] Fix | Delete
(self.__class__.__name__, self.url, self.errcode, self.errmsg)
[212] Fix | Delete
)
[213] Fix | Delete
[214] Fix | Delete
##
[215] Fix | Delete
# Indicates a broken XML-RPC response package. This exception is
[216] Fix | Delete
# raised by the unmarshalling layer, if the XML-RPC response is
[217] Fix | Delete
# malformed.
[218] Fix | Delete
[219] Fix | Delete
class ResponseError(Error):
[220] Fix | Delete
"""Indicates a broken response package."""
[221] Fix | Delete
pass
[222] Fix | Delete
[223] Fix | Delete
##
[224] Fix | Delete
# Indicates an XML-RPC fault response package. This exception is
[225] Fix | Delete
# raised by the unmarshalling layer, if the XML-RPC response contains
[226] Fix | Delete
# a fault string. This exception can also be used as a class, to
[227] Fix | Delete
# generate a fault XML-RPC message.
[228] Fix | Delete
#
[229] Fix | Delete
# @param faultCode The XML-RPC fault code.
[230] Fix | Delete
# @param faultString The XML-RPC fault string.
[231] Fix | Delete
[232] Fix | Delete
class Fault(Error):
[233] Fix | Delete
"""Indicates an XML-RPC fault package."""
[234] Fix | Delete
def __init__(self, faultCode, faultString, **extra):
[235] Fix | Delete
Error.__init__(self)
[236] Fix | Delete
self.faultCode = faultCode
[237] Fix | Delete
self.faultString = faultString
[238] Fix | Delete
def __repr__(self):
[239] Fix | Delete
return "<%s %s: %r>" % (self.__class__.__name__,
[240] Fix | Delete
self.faultCode, self.faultString)
[241] Fix | Delete
[242] Fix | Delete
# --------------------------------------------------------------------
[243] Fix | Delete
# Special values
[244] Fix | Delete
[245] Fix | Delete
##
[246] Fix | Delete
# Backwards compatibility
[247] Fix | Delete
[248] Fix | Delete
boolean = Boolean = bool
[249] Fix | Delete
[250] Fix | Delete
##
[251] Fix | Delete
# Wrapper for XML-RPC DateTime values. This converts a time value to
[252] Fix | Delete
# the format used by XML-RPC.
[253] Fix | Delete
# <p>
[254] Fix | Delete
# The value can be given as a datetime object, as a string in the
[255] Fix | Delete
# format "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by
[256] Fix | Delete
# time.localtime()), or an integer value (as returned by time.time()).
[257] Fix | Delete
# The wrapper uses time.localtime() to convert an integer to a time
[258] Fix | Delete
# tuple.
[259] Fix | Delete
#
[260] Fix | Delete
# @param value The time, given as a datetime object, an ISO 8601 string,
[261] Fix | Delete
# a time tuple, or an integer time value.
[262] Fix | Delete
[263] Fix | Delete
[264] Fix | Delete
# Issue #13305: different format codes across platforms
[265] Fix | Delete
_day0 = datetime(1, 1, 1)
[266] Fix | Delete
if _day0.strftime('%Y') == '0001': # Mac OS X
[267] Fix | Delete
def _iso8601_format(value):
[268] Fix | Delete
return value.strftime("%Y%m%dT%H:%M:%S")
[269] Fix | Delete
elif _day0.strftime('%4Y') == '0001': # Linux
[270] Fix | Delete
def _iso8601_format(value):
[271] Fix | Delete
return value.strftime("%4Y%m%dT%H:%M:%S")
[272] Fix | Delete
else:
[273] Fix | Delete
def _iso8601_format(value):
[274] Fix | Delete
return value.strftime("%Y%m%dT%H:%M:%S").zfill(17)
[275] Fix | Delete
del _day0
[276] Fix | Delete
[277] Fix | Delete
[278] Fix | Delete
def _strftime(value):
[279] Fix | Delete
if isinstance(value, datetime):
[280] Fix | Delete
return _iso8601_format(value)
[281] Fix | Delete
[282] Fix | Delete
if not isinstance(value, (tuple, time.struct_time)):
[283] Fix | Delete
if value == 0:
[284] Fix | Delete
value = time.time()
[285] Fix | Delete
value = time.localtime(value)
[286] Fix | Delete
[287] Fix | Delete
return "%04d%02d%02dT%02d:%02d:%02d" % value[:6]
[288] Fix | Delete
[289] Fix | Delete
class DateTime:
[290] Fix | Delete
"""DateTime wrapper for an ISO 8601 string or time tuple or
[291] Fix | Delete
localtime integer value to generate 'dateTime.iso8601' XML-RPC
[292] Fix | Delete
value.
[293] Fix | Delete
"""
[294] Fix | Delete
[295] Fix | Delete
def __init__(self, value=0):
[296] Fix | Delete
if isinstance(value, str):
[297] Fix | Delete
self.value = value
[298] Fix | Delete
else:
[299] Fix | Delete
self.value = _strftime(value)
[300] Fix | Delete
[301] Fix | Delete
def make_comparable(self, other):
[302] Fix | Delete
if isinstance(other, DateTime):
[303] Fix | Delete
s = self.value
[304] Fix | Delete
o = other.value
[305] Fix | Delete
elif isinstance(other, datetime):
[306] Fix | Delete
s = self.value
[307] Fix | Delete
o = _iso8601_format(other)
[308] Fix | Delete
elif isinstance(other, str):
[309] Fix | Delete
s = self.value
[310] Fix | Delete
o = other
[311] Fix | Delete
elif hasattr(other, "timetuple"):
[312] Fix | Delete
s = self.timetuple()
[313] Fix | Delete
o = other.timetuple()
[314] Fix | Delete
else:
[315] Fix | Delete
otype = (hasattr(other, "__class__")
[316] Fix | Delete
and other.__class__.__name__
[317] Fix | Delete
or type(other))
[318] Fix | Delete
raise TypeError("Can't compare %s and %s" %
[319] Fix | Delete
(self.__class__.__name__, otype))
[320] Fix | Delete
return s, o
[321] Fix | Delete
[322] Fix | Delete
def __lt__(self, other):
[323] Fix | Delete
s, o = self.make_comparable(other)
[324] Fix | Delete
return s < o
[325] Fix | Delete
[326] Fix | Delete
def __le__(self, other):
[327] Fix | Delete
s, o = self.make_comparable(other)
[328] Fix | Delete
return s <= o
[329] Fix | Delete
[330] Fix | Delete
def __gt__(self, other):
[331] Fix | Delete
s, o = self.make_comparable(other)
[332] Fix | Delete
return s > o
[333] Fix | Delete
[334] Fix | Delete
def __ge__(self, other):
[335] Fix | Delete
s, o = self.make_comparable(other)
[336] Fix | Delete
return s >= o
[337] Fix | Delete
[338] Fix | Delete
def __eq__(self, other):
[339] Fix | Delete
s, o = self.make_comparable(other)
[340] Fix | Delete
return s == o
[341] Fix | Delete
[342] Fix | Delete
def timetuple(self):
[343] Fix | Delete
return time.strptime(self.value, "%Y%m%dT%H:%M:%S")
[344] Fix | Delete
[345] Fix | Delete
##
[346] Fix | Delete
# Get date/time value.
[347] Fix | Delete
#
[348] Fix | Delete
# @return Date/time value, as an ISO 8601 string.
[349] Fix | Delete
[350] Fix | Delete
def __str__(self):
[351] Fix | Delete
return self.value
[352] Fix | Delete
[353] Fix | Delete
def __repr__(self):
[354] Fix | Delete
return "<%s %r at %#x>" % (self.__class__.__name__, self.value, id(self))
[355] Fix | Delete
[356] Fix | Delete
def decode(self, data):
[357] Fix | Delete
self.value = str(data).strip()
[358] Fix | Delete
[359] Fix | Delete
def encode(self, out):
[360] Fix | Delete
out.write("<value><dateTime.iso8601>")
[361] Fix | Delete
out.write(self.value)
[362] Fix | Delete
out.write("</dateTime.iso8601></value>\n")
[363] Fix | Delete
[364] Fix | Delete
def _datetime(data):
[365] Fix | Delete
# decode xml element contents into a DateTime structure.
[366] Fix | Delete
value = DateTime()
[367] Fix | Delete
value.decode(data)
[368] Fix | Delete
return value
[369] Fix | Delete
[370] Fix | Delete
def _datetime_type(data):
[371] Fix | Delete
return datetime.strptime(data, "%Y%m%dT%H:%M:%S")
[372] Fix | Delete
[373] Fix | Delete
##
[374] Fix | Delete
# Wrapper for binary data. This can be used to transport any kind
[375] Fix | Delete
# of binary data over XML-RPC, using BASE64 encoding.
[376] Fix | Delete
#
[377] Fix | Delete
# @param data An 8-bit string containing arbitrary data.
[378] Fix | Delete
[379] Fix | Delete
class Binary:
[380] Fix | Delete
"""Wrapper for binary data."""
[381] Fix | Delete
[382] Fix | Delete
def __init__(self, data=None):
[383] Fix | Delete
if data is None:
[384] Fix | Delete
data = b""
[385] Fix | Delete
else:
[386] Fix | Delete
if not isinstance(data, (bytes, bytearray)):
[387] Fix | Delete
raise TypeError("expected bytes or bytearray, not %s" %
[388] Fix | Delete
data.__class__.__name__)
[389] Fix | Delete
data = bytes(data) # Make a copy of the bytes!
[390] Fix | Delete
self.data = data
[391] Fix | Delete
[392] Fix | Delete
##
[393] Fix | Delete
# Get buffer contents.
[394] Fix | Delete
#
[395] Fix | Delete
# @return Buffer contents, as an 8-bit string.
[396] Fix | Delete
[397] Fix | Delete
def __str__(self):
[398] Fix | Delete
return str(self.data, "latin-1") # XXX encoding?!
[399] Fix | Delete
[400] Fix | Delete
def __eq__(self, other):
[401] Fix | Delete
if isinstance(other, Binary):
[402] Fix | Delete
other = other.data
[403] Fix | Delete
return self.data == other
[404] Fix | Delete
[405] Fix | Delete
def decode(self, data):
[406] Fix | Delete
self.data = base64.decodebytes(data)
[407] Fix | Delete
[408] Fix | Delete
def encode(self, out):
[409] Fix | Delete
out.write("<value><base64>\n")
[410] Fix | Delete
encoded = base64.encodebytes(self.data)
[411] Fix | Delete
out.write(encoded.decode('ascii'))
[412] Fix | Delete
out.write("</base64></value>\n")
[413] Fix | Delete
[414] Fix | Delete
def _binary(data):
[415] Fix | Delete
# decode xml element contents into a Binary structure
[416] Fix | Delete
value = Binary()
[417] Fix | Delete
value.decode(data)
[418] Fix | Delete
return value
[419] Fix | Delete
[420] Fix | Delete
WRAPPERS = (DateTime, Binary)
[421] Fix | Delete
[422] Fix | Delete
# --------------------------------------------------------------------
[423] Fix | Delete
# XML parsers
[424] Fix | Delete
[425] Fix | Delete
class ExpatParser:
[426] Fix | Delete
# fast expat parser for Python 2.0 and later.
[427] Fix | Delete
def __init__(self, target):
[428] Fix | Delete
self._parser = parser = expat.ParserCreate(None, None)
[429] Fix | Delete
self._target = target
[430] Fix | Delete
parser.StartElementHandler = target.start
[431] Fix | Delete
parser.EndElementHandler = target.end
[432] Fix | Delete
parser.CharacterDataHandler = target.data
[433] Fix | Delete
encoding = None
[434] Fix | Delete
target.xml(encoding, None)
[435] Fix | Delete
[436] Fix | Delete
def feed(self, data):
[437] Fix | Delete
self._parser.Parse(data, 0)
[438] Fix | Delete
[439] Fix | Delete
def close(self):
[440] Fix | Delete
try:
[441] Fix | Delete
parser = self._parser
[442] Fix | Delete
except AttributeError:
[443] Fix | Delete
pass
[444] Fix | Delete
else:
[445] Fix | Delete
del self._target, self._parser # get rid of circular references
[446] Fix | Delete
parser.Parse(b"", True) # end of data
[447] Fix | Delete
[448] Fix | Delete
# --------------------------------------------------------------------
[449] Fix | Delete
# XML-RPC marshalling and unmarshalling code
[450] Fix | Delete
[451] Fix | Delete
##
[452] Fix | Delete
# XML-RPC marshaller.
[453] Fix | Delete
#
[454] Fix | Delete
# @param encoding Default encoding for 8-bit strings. The default
[455] Fix | Delete
# value is None (interpreted as UTF-8).
[456] Fix | Delete
# @see dumps
[457] Fix | Delete
[458] Fix | Delete
class Marshaller:
[459] Fix | Delete
"""Generate an XML-RPC params chunk from a Python data structure.
[460] Fix | Delete
[461] Fix | Delete
Create a Marshaller instance for each set of parameters, and use
[462] Fix | Delete
the "dumps" method to convert your data (represented as a tuple)
[463] Fix | Delete
to an XML-RPC params chunk. To write a fault response, pass a
[464] Fix | Delete
Fault instance instead. You may prefer to use the "dumps" module
[465] Fix | Delete
function for this purpose.
[466] Fix | Delete
"""
[467] Fix | Delete
[468] Fix | Delete
# by the way, if you don't understand what's going on in here,
[469] Fix | Delete
# that's perfectly ok.
[470] Fix | Delete
[471] Fix | Delete
def __init__(self, encoding=None, allow_none=False):
[472] Fix | Delete
self.memo = {}
[473] Fix | Delete
self.data = None
[474] Fix | Delete
self.encoding = encoding
[475] Fix | Delete
self.allow_none = allow_none
[476] Fix | Delete
[477] Fix | Delete
dispatch = {}
[478] Fix | Delete
[479] Fix | Delete
def dumps(self, values):
[480] Fix | Delete
out = []
[481] Fix | Delete
write = out.append
[482] Fix | Delete
dump = self.__dump
[483] Fix | Delete
if isinstance(values, Fault):
[484] Fix | Delete
# fault instance
[485] Fix | Delete
write("<fault>\n")
[486] Fix | Delete
dump({'faultCode': values.faultCode,
[487] Fix | Delete
'faultString': values.faultString},
[488] Fix | Delete
write)
[489] Fix | Delete
write("</fault>\n")
[490] Fix | Delete
else:
[491] Fix | Delete
# parameter block
[492] Fix | Delete
# FIXME: the xml-rpc specification allows us to leave out
[493] Fix | Delete
# the entire <params> block if there are no parameters.
[494] Fix | Delete
# however, changing this may break older code (including
[495] Fix | Delete
# old versions of xmlrpclib.py), so this is better left as
[496] Fix | Delete
# is for now. See @XMLRPC3 for more information. /F
[497] Fix | Delete
write("<params>\n")
[498] Fix | Delete
for v in values:
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function