Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../usr/lib64/python2....
File: SimpleXMLRPCServer.py
r"""Simple XML-RPC Server.
[0] Fix | Delete
[1] Fix | Delete
This module can be used to create simple XML-RPC servers
[2] Fix | Delete
by creating a server and either installing functions, a
[3] Fix | Delete
class instance, or by extending the SimpleXMLRPCServer
[4] Fix | Delete
class.
[5] Fix | Delete
[6] Fix | Delete
It can also be used to handle XML-RPC requests in a CGI
[7] Fix | Delete
environment using CGIXMLRPCRequestHandler.
[8] Fix | Delete
[9] Fix | Delete
A list of possible usage patterns follows:
[10] Fix | Delete
[11] Fix | Delete
1. Install functions:
[12] Fix | Delete
[13] Fix | Delete
server = SimpleXMLRPCServer(("localhost", 8000))
[14] Fix | Delete
server.register_function(pow)
[15] Fix | Delete
server.register_function(lambda x,y: x+y, 'add')
[16] Fix | Delete
server.serve_forever()
[17] Fix | Delete
[18] Fix | Delete
2. Install an instance:
[19] Fix | Delete
[20] Fix | Delete
class MyFuncs:
[21] Fix | Delete
def __init__(self):
[22] Fix | Delete
# make all of the string functions available through
[23] Fix | Delete
# string.func_name
[24] Fix | Delete
import string
[25] Fix | Delete
self.string = string
[26] Fix | Delete
def _listMethods(self):
[27] Fix | Delete
# implement this method so that system.listMethods
[28] Fix | Delete
# knows to advertise the strings methods
[29] Fix | Delete
return list_public_methods(self) + \
[30] Fix | Delete
['string.' + method for method in list_public_methods(self.string)]
[31] Fix | Delete
def pow(self, x, y): return pow(x, y)
[32] Fix | Delete
def add(self, x, y) : return x + y
[33] Fix | Delete
[34] Fix | Delete
server = SimpleXMLRPCServer(("localhost", 8000))
[35] Fix | Delete
server.register_introspection_functions()
[36] Fix | Delete
server.register_instance(MyFuncs())
[37] Fix | Delete
server.serve_forever()
[38] Fix | Delete
[39] Fix | Delete
3. Install an instance with custom dispatch method:
[40] Fix | Delete
[41] Fix | Delete
class Math:
[42] Fix | Delete
def _listMethods(self):
[43] Fix | Delete
# this method must be present for system.listMethods
[44] Fix | Delete
# to work
[45] Fix | Delete
return ['add', 'pow']
[46] Fix | Delete
def _methodHelp(self, method):
[47] Fix | Delete
# this method must be present for system.methodHelp
[48] Fix | Delete
# to work
[49] Fix | Delete
if method == 'add':
[50] Fix | Delete
return "add(2,3) => 5"
[51] Fix | Delete
elif method == 'pow':
[52] Fix | Delete
return "pow(x, y[, z]) => number"
[53] Fix | Delete
else:
[54] Fix | Delete
# By convention, return empty
[55] Fix | Delete
# string if no help is available
[56] Fix | Delete
return ""
[57] Fix | Delete
def _dispatch(self, method, params):
[58] Fix | Delete
if method == 'pow':
[59] Fix | Delete
return pow(*params)
[60] Fix | Delete
elif method == 'add':
[61] Fix | Delete
return params[0] + params[1]
[62] Fix | Delete
else:
[63] Fix | Delete
raise 'bad method'
[64] Fix | Delete
[65] Fix | Delete
server = SimpleXMLRPCServer(("localhost", 8000))
[66] Fix | Delete
server.register_introspection_functions()
[67] Fix | Delete
server.register_instance(Math())
[68] Fix | Delete
server.serve_forever()
[69] Fix | Delete
[70] Fix | Delete
4. Subclass SimpleXMLRPCServer:
[71] Fix | Delete
[72] Fix | Delete
class MathServer(SimpleXMLRPCServer):
[73] Fix | Delete
def _dispatch(self, method, params):
[74] Fix | Delete
try:
[75] Fix | Delete
# We are forcing the 'export_' prefix on methods that are
[76] Fix | Delete
# callable through XML-RPC to prevent potential security
[77] Fix | Delete
# problems
[78] Fix | Delete
func = getattr(self, 'export_' + method)
[79] Fix | Delete
except AttributeError:
[80] Fix | Delete
raise Exception('method "%s" is not supported' % method)
[81] Fix | Delete
else:
[82] Fix | Delete
return func(*params)
[83] Fix | Delete
[84] Fix | Delete
def export_add(self, x, y):
[85] Fix | Delete
return x + y
[86] Fix | Delete
[87] Fix | Delete
server = MathServer(("localhost", 8000))
[88] Fix | Delete
server.serve_forever()
[89] Fix | Delete
[90] Fix | Delete
5. CGI script:
[91] Fix | Delete
[92] Fix | Delete
server = CGIXMLRPCRequestHandler()
[93] Fix | Delete
server.register_function(pow)
[94] Fix | Delete
server.handle_request()
[95] Fix | Delete
"""
[96] Fix | Delete
[97] Fix | Delete
# Written by Brian Quinlan (brian@sweetapp.com).
[98] Fix | Delete
# Based on code written by Fredrik Lundh.
[99] Fix | Delete
[100] Fix | Delete
import xmlrpclib
[101] Fix | Delete
from xmlrpclib import Fault
[102] Fix | Delete
import SocketServer
[103] Fix | Delete
import BaseHTTPServer
[104] Fix | Delete
import sys
[105] Fix | Delete
import os
[106] Fix | Delete
import traceback
[107] Fix | Delete
import re
[108] Fix | Delete
try:
[109] Fix | Delete
import fcntl
[110] Fix | Delete
except ImportError:
[111] Fix | Delete
fcntl = None
[112] Fix | Delete
[113] Fix | Delete
def resolve_dotted_attribute(obj, attr, allow_dotted_names=True):
[114] Fix | Delete
"""resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d
[115] Fix | Delete
[116] Fix | Delete
Resolves a dotted attribute name to an object. Raises
[117] Fix | Delete
an AttributeError if any attribute in the chain starts with a '_'.
[118] Fix | Delete
[119] Fix | Delete
If the optional allow_dotted_names argument is false, dots are not
[120] Fix | Delete
supported and this function operates similar to getattr(obj, attr).
[121] Fix | Delete
"""
[122] Fix | Delete
[123] Fix | Delete
if allow_dotted_names:
[124] Fix | Delete
attrs = attr.split('.')
[125] Fix | Delete
else:
[126] Fix | Delete
attrs = [attr]
[127] Fix | Delete
[128] Fix | Delete
for i in attrs:
[129] Fix | Delete
if i.startswith('_'):
[130] Fix | Delete
raise AttributeError(
[131] Fix | Delete
'attempt to access private attribute "%s"' % i
[132] Fix | Delete
)
[133] Fix | Delete
else:
[134] Fix | Delete
obj = getattr(obj,i)
[135] Fix | Delete
return obj
[136] Fix | Delete
[137] Fix | Delete
def list_public_methods(obj):
[138] Fix | Delete
"""Returns a list of attribute strings, found in the specified
[139] Fix | Delete
object, which represent callable attributes"""
[140] Fix | Delete
[141] Fix | Delete
return [member for member in dir(obj)
[142] Fix | Delete
if not member.startswith('_') and
[143] Fix | Delete
hasattr(getattr(obj, member), '__call__')]
[144] Fix | Delete
[145] Fix | Delete
def remove_duplicates(lst):
[146] Fix | Delete
"""remove_duplicates([2,2,2,1,3,3]) => [3,1,2]
[147] Fix | Delete
[148] Fix | Delete
Returns a copy of a list without duplicates. Every list
[149] Fix | Delete
item must be hashable and the order of the items in the
[150] Fix | Delete
resulting list is not defined.
[151] Fix | Delete
"""
[152] Fix | Delete
u = {}
[153] Fix | Delete
for x in lst:
[154] Fix | Delete
u[x] = 1
[155] Fix | Delete
[156] Fix | Delete
return u.keys()
[157] Fix | Delete
[158] Fix | Delete
class SimpleXMLRPCDispatcher:
[159] Fix | Delete
"""Mix-in class that dispatches XML-RPC requests.
[160] Fix | Delete
[161] Fix | Delete
This class is used to register XML-RPC method handlers
[162] Fix | Delete
and then to dispatch them. This class doesn't need to be
[163] Fix | Delete
instanced directly when used by SimpleXMLRPCServer but it
[164] Fix | Delete
can be instanced when used by the MultiPathXMLRPCServer.
[165] Fix | Delete
"""
[166] Fix | Delete
[167] Fix | Delete
def __init__(self, allow_none=False, encoding=None):
[168] Fix | Delete
self.funcs = {}
[169] Fix | Delete
self.instance = None
[170] Fix | Delete
self.allow_none = allow_none
[171] Fix | Delete
self.encoding = encoding
[172] Fix | Delete
[173] Fix | Delete
def register_instance(self, instance, allow_dotted_names=False):
[174] Fix | Delete
"""Registers an instance to respond to XML-RPC requests.
[175] Fix | Delete
[176] Fix | Delete
Only one instance can be installed at a time.
[177] Fix | Delete
[178] Fix | Delete
If the registered instance has a _dispatch method then that
[179] Fix | Delete
method will be called with the name of the XML-RPC method and
[180] Fix | Delete
its parameters as a tuple
[181] Fix | Delete
e.g. instance._dispatch('add',(2,3))
[182] Fix | Delete
[183] Fix | Delete
If the registered instance does not have a _dispatch method
[184] Fix | Delete
then the instance will be searched to find a matching method
[185] Fix | Delete
and, if found, will be called. Methods beginning with an '_'
[186] Fix | Delete
are considered private and will not be called by
[187] Fix | Delete
SimpleXMLRPCServer.
[188] Fix | Delete
[189] Fix | Delete
If a registered function matches an XML-RPC request, then it
[190] Fix | Delete
will be called instead of the registered instance.
[191] Fix | Delete
[192] Fix | Delete
If the optional allow_dotted_names argument is true and the
[193] Fix | Delete
instance does not have a _dispatch method, method names
[194] Fix | Delete
containing dots are supported and resolved, as long as none of
[195] Fix | Delete
the name segments start with an '_'.
[196] Fix | Delete
[197] Fix | Delete
*** SECURITY WARNING: ***
[198] Fix | Delete
[199] Fix | Delete
Enabling the allow_dotted_names options allows intruders
[200] Fix | Delete
to access your module's global variables and may allow
[201] Fix | Delete
intruders to execute arbitrary code on your machine. Only
[202] Fix | Delete
use this option on a secure, closed network.
[203] Fix | Delete
[204] Fix | Delete
"""
[205] Fix | Delete
[206] Fix | Delete
self.instance = instance
[207] Fix | Delete
self.allow_dotted_names = allow_dotted_names
[208] Fix | Delete
[209] Fix | Delete
def register_function(self, function, name = None):
[210] Fix | Delete
"""Registers a function to respond to XML-RPC requests.
[211] Fix | Delete
[212] Fix | Delete
The optional name argument can be used to set a Unicode name
[213] Fix | Delete
for the function.
[214] Fix | Delete
"""
[215] Fix | Delete
[216] Fix | Delete
if name is None:
[217] Fix | Delete
name = function.__name__
[218] Fix | Delete
self.funcs[name] = function
[219] Fix | Delete
[220] Fix | Delete
def register_introspection_functions(self):
[221] Fix | Delete
"""Registers the XML-RPC introspection methods in the system
[222] Fix | Delete
namespace.
[223] Fix | Delete
[224] Fix | Delete
see http://xmlrpc.usefulinc.com/doc/reserved.html
[225] Fix | Delete
"""
[226] Fix | Delete
[227] Fix | Delete
self.funcs.update({'system.listMethods' : self.system_listMethods,
[228] Fix | Delete
'system.methodSignature' : self.system_methodSignature,
[229] Fix | Delete
'system.methodHelp' : self.system_methodHelp})
[230] Fix | Delete
[231] Fix | Delete
def register_multicall_functions(self):
[232] Fix | Delete
"""Registers the XML-RPC multicall method in the system
[233] Fix | Delete
namespace.
[234] Fix | Delete
[235] Fix | Delete
see http://www.xmlrpc.com/discuss/msgReader$1208"""
[236] Fix | Delete
[237] Fix | Delete
self.funcs.update({'system.multicall' : self.system_multicall})
[238] Fix | Delete
[239] Fix | Delete
def _marshaled_dispatch(self, data, dispatch_method = None, path = None):
[240] Fix | Delete
"""Dispatches an XML-RPC method from marshalled (XML) data.
[241] Fix | Delete
[242] Fix | Delete
XML-RPC methods are dispatched from the marshalled (XML) data
[243] Fix | Delete
using the _dispatch method and the result is returned as
[244] Fix | Delete
marshalled data. For backwards compatibility, a dispatch
[245] Fix | Delete
function can be provided as an argument (see comment in
[246] Fix | Delete
SimpleXMLRPCRequestHandler.do_POST) but overriding the
[247] Fix | Delete
existing method through subclassing is the preferred means
[248] Fix | Delete
of changing method dispatch behavior.
[249] Fix | Delete
"""
[250] Fix | Delete
[251] Fix | Delete
try:
[252] Fix | Delete
params, method = xmlrpclib.loads(data)
[253] Fix | Delete
[254] Fix | Delete
# generate response
[255] Fix | Delete
if dispatch_method is not None:
[256] Fix | Delete
response = dispatch_method(method, params)
[257] Fix | Delete
else:
[258] Fix | Delete
response = self._dispatch(method, params)
[259] Fix | Delete
# wrap response in a singleton tuple
[260] Fix | Delete
response = (response,)
[261] Fix | Delete
response = xmlrpclib.dumps(response, methodresponse=1,
[262] Fix | Delete
allow_none=self.allow_none, encoding=self.encoding)
[263] Fix | Delete
except Fault, fault:
[264] Fix | Delete
response = xmlrpclib.dumps(fault, allow_none=self.allow_none,
[265] Fix | Delete
encoding=self.encoding)
[266] Fix | Delete
except:
[267] Fix | Delete
# report exception back to server
[268] Fix | Delete
exc_type, exc_value, exc_tb = sys.exc_info()
[269] Fix | Delete
response = xmlrpclib.dumps(
[270] Fix | Delete
xmlrpclib.Fault(1, "%s:%s" % (exc_type, exc_value)),
[271] Fix | Delete
encoding=self.encoding, allow_none=self.allow_none,
[272] Fix | Delete
)
[273] Fix | Delete
[274] Fix | Delete
return response
[275] Fix | Delete
[276] Fix | Delete
def system_listMethods(self):
[277] Fix | Delete
"""system.listMethods() => ['add', 'subtract', 'multiple']
[278] Fix | Delete
[279] Fix | Delete
Returns a list of the methods supported by the server."""
[280] Fix | Delete
[281] Fix | Delete
methods = self.funcs.keys()
[282] Fix | Delete
if self.instance is not None:
[283] Fix | Delete
# Instance can implement _listMethod to return a list of
[284] Fix | Delete
# methods
[285] Fix | Delete
if hasattr(self.instance, '_listMethods'):
[286] Fix | Delete
methods = remove_duplicates(
[287] Fix | Delete
methods + self.instance._listMethods()
[288] Fix | Delete
)
[289] Fix | Delete
# if the instance has a _dispatch method then we
[290] Fix | Delete
# don't have enough information to provide a list
[291] Fix | Delete
# of methods
[292] Fix | Delete
elif not hasattr(self.instance, '_dispatch'):
[293] Fix | Delete
methods = remove_duplicates(
[294] Fix | Delete
methods + list_public_methods(self.instance)
[295] Fix | Delete
)
[296] Fix | Delete
methods.sort()
[297] Fix | Delete
return methods
[298] Fix | Delete
[299] Fix | Delete
def system_methodSignature(self, method_name):
[300] Fix | Delete
"""system.methodSignature('add') => [double, int, int]
[301] Fix | Delete
[302] Fix | Delete
Returns a list describing the signature of the method. In the
[303] Fix | Delete
above example, the add method takes two integers as arguments
[304] Fix | Delete
and returns a double result.
[305] Fix | Delete
[306] Fix | Delete
This server does NOT support system.methodSignature."""
[307] Fix | Delete
[308] Fix | Delete
# See http://xmlrpc.usefulinc.com/doc/sysmethodsig.html
[309] Fix | Delete
[310] Fix | Delete
return 'signatures not supported'
[311] Fix | Delete
[312] Fix | Delete
def system_methodHelp(self, method_name):
[313] Fix | Delete
"""system.methodHelp('add') => "Adds two integers together"
[314] Fix | Delete
[315] Fix | Delete
Returns a string containing documentation for the specified method."""
[316] Fix | Delete
[317] Fix | Delete
method = None
[318] Fix | Delete
if method_name in self.funcs:
[319] Fix | Delete
method = self.funcs[method_name]
[320] Fix | Delete
elif self.instance is not None:
[321] Fix | Delete
# Instance can implement _methodHelp to return help for a method
[322] Fix | Delete
if hasattr(self.instance, '_methodHelp'):
[323] Fix | Delete
return self.instance._methodHelp(method_name)
[324] Fix | Delete
# if the instance has a _dispatch method then we
[325] Fix | Delete
# don't have enough information to provide help
[326] Fix | Delete
elif not hasattr(self.instance, '_dispatch'):
[327] Fix | Delete
try:
[328] Fix | Delete
method = resolve_dotted_attribute(
[329] Fix | Delete
self.instance,
[330] Fix | Delete
method_name,
[331] Fix | Delete
self.allow_dotted_names
[332] Fix | Delete
)
[333] Fix | Delete
except AttributeError:
[334] Fix | Delete
pass
[335] Fix | Delete
[336] Fix | Delete
# Note that we aren't checking that the method actually
[337] Fix | Delete
# be a callable object of some kind
[338] Fix | Delete
if method is None:
[339] Fix | Delete
return ""
[340] Fix | Delete
else:
[341] Fix | Delete
import pydoc
[342] Fix | Delete
return pydoc.getdoc(method)
[343] Fix | Delete
[344] Fix | Delete
def system_multicall(self, call_list):
[345] Fix | Delete
"""system.multicall([{'methodName': 'add', 'params': [2, 2]}, ...]) => \
[346] Fix | Delete
[[4], ...]
[347] Fix | Delete
[348] Fix | Delete
Allows the caller to package multiple XML-RPC calls into a single
[349] Fix | Delete
request.
[350] Fix | Delete
[351] Fix | Delete
See http://www.xmlrpc.com/discuss/msgReader$1208
[352] Fix | Delete
"""
[353] Fix | Delete
[354] Fix | Delete
results = []
[355] Fix | Delete
for call in call_list:
[356] Fix | Delete
method_name = call['methodName']
[357] Fix | Delete
params = call['params']
[358] Fix | Delete
[359] Fix | Delete
try:
[360] Fix | Delete
# XXX A marshalling error in any response will fail the entire
[361] Fix | Delete
# multicall. If someone cares they should fix this.
[362] Fix | Delete
results.append([self._dispatch(method_name, params)])
[363] Fix | Delete
except Fault, fault:
[364] Fix | Delete
results.append(
[365] Fix | Delete
{'faultCode' : fault.faultCode,
[366] Fix | Delete
'faultString' : fault.faultString}
[367] Fix | Delete
)
[368] Fix | Delete
except:
[369] Fix | Delete
exc_type, exc_value, exc_tb = sys.exc_info()
[370] Fix | Delete
results.append(
[371] Fix | Delete
{'faultCode' : 1,
[372] Fix | Delete
'faultString' : "%s:%s" % (exc_type, exc_value)}
[373] Fix | Delete
)
[374] Fix | Delete
return results
[375] Fix | Delete
[376] Fix | Delete
def _dispatch(self, method, params):
[377] Fix | Delete
"""Dispatches the XML-RPC method.
[378] Fix | Delete
[379] Fix | Delete
XML-RPC calls are forwarded to a registered function that
[380] Fix | Delete
matches the called XML-RPC method name. If no such function
[381] Fix | Delete
exists then the call is forwarded to the registered instance,
[382] Fix | Delete
if available.
[383] Fix | Delete
[384] Fix | Delete
If the registered instance has a _dispatch method then that
[385] Fix | Delete
method will be called with the name of the XML-RPC method and
[386] Fix | Delete
its parameters as a tuple
[387] Fix | Delete
e.g. instance._dispatch('add',(2,3))
[388] Fix | Delete
[389] Fix | Delete
If the registered instance does not have a _dispatch method
[390] Fix | Delete
then the instance will be searched to find a matching method
[391] Fix | Delete
and, if found, will be called.
[392] Fix | Delete
[393] Fix | Delete
Methods beginning with an '_' are considered private and will
[394] Fix | Delete
not be called.
[395] Fix | Delete
"""
[396] Fix | Delete
[397] Fix | Delete
func = None
[398] Fix | Delete
try:
[399] Fix | Delete
# check to see if a matching function has been registered
[400] Fix | Delete
func = self.funcs[method]
[401] Fix | Delete
except KeyError:
[402] Fix | Delete
if self.instance is not None:
[403] Fix | Delete
# check for a _dispatch method
[404] Fix | Delete
if hasattr(self.instance, '_dispatch'):
[405] Fix | Delete
return self.instance._dispatch(method, params)
[406] Fix | Delete
else:
[407] Fix | Delete
# call instance method directly
[408] Fix | Delete
try:
[409] Fix | Delete
func = resolve_dotted_attribute(
[410] Fix | Delete
self.instance,
[411] Fix | Delete
method,
[412] Fix | Delete
self.allow_dotted_names
[413] Fix | Delete
)
[414] Fix | Delete
except AttributeError:
[415] Fix | Delete
pass
[416] Fix | Delete
[417] Fix | Delete
if func is not None:
[418] Fix | Delete
return func(*params)
[419] Fix | Delete
else:
[420] Fix | Delete
raise Exception('method "%s" is not supported' % method)
[421] Fix | Delete
[422] Fix | Delete
class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
[423] Fix | Delete
"""Simple XML-RPC request handler class.
[424] Fix | Delete
[425] Fix | Delete
Handles all HTTP POST requests and attempts to decode them as
[426] Fix | Delete
XML-RPC requests.
[427] Fix | Delete
"""
[428] Fix | Delete
[429] Fix | Delete
# Class attribute listing the accessible path components;
[430] Fix | Delete
# paths not on this list will result in a 404 error.
[431] Fix | Delete
rpc_paths = ('/', '/RPC2')
[432] Fix | Delete
[433] Fix | Delete
#if not None, encode responses larger than this, if possible
[434] Fix | Delete
encode_threshold = 1400 #a common MTU
[435] Fix | Delete
[436] Fix | Delete
#Override form StreamRequestHandler: full buffering of output
[437] Fix | Delete
#and no Nagle.
[438] Fix | Delete
wbufsize = -1
[439] Fix | Delete
disable_nagle_algorithm = True
[440] Fix | Delete
[441] Fix | Delete
# a re to match a gzip Accept-Encoding
[442] Fix | Delete
aepattern = re.compile(r"""
[443] Fix | Delete
\s* ([^\s;]+) \s* #content-coding
[444] Fix | Delete
(;\s* q \s*=\s* ([0-9\.]+))? #q
[445] Fix | Delete
""", re.VERBOSE | re.IGNORECASE)
[446] Fix | Delete
[447] Fix | Delete
def accept_encodings(self):
[448] Fix | Delete
r = {}
[449] Fix | Delete
ae = self.headers.get("Accept-Encoding", "")
[450] Fix | Delete
for e in ae.split(","):
[451] Fix | Delete
match = self.aepattern.match(e)
[452] Fix | Delete
if match:
[453] Fix | Delete
v = match.group(3)
[454] Fix | Delete
v = float(v) if v else 1.0
[455] Fix | Delete
r[match.group(1)] = v
[456] Fix | Delete
return r
[457] Fix | Delete
[458] Fix | Delete
def is_rpc_path_valid(self):
[459] Fix | Delete
if self.rpc_paths:
[460] Fix | Delete
return self.path in self.rpc_paths
[461] Fix | Delete
else:
[462] Fix | Delete
# If .rpc_paths is empty, just assume all paths are legal
[463] Fix | Delete
return True
[464] Fix | Delete
[465] Fix | Delete
def do_POST(self):
[466] Fix | Delete
"""Handles the HTTP POST request.
[467] Fix | Delete
[468] Fix | Delete
Attempts to interpret all HTTP POST requests as XML-RPC calls,
[469] Fix | Delete
which are forwarded to the server's _dispatch method for handling.
[470] Fix | Delete
"""
[471] Fix | Delete
[472] Fix | Delete
# Check that the path is legal
[473] Fix | Delete
if not self.is_rpc_path_valid():
[474] Fix | Delete
self.report_404()
[475] Fix | Delete
return
[476] Fix | Delete
[477] Fix | Delete
try:
[478] Fix | Delete
# Get arguments by reading body of request.
[479] Fix | Delete
# We read this in chunks to avoid straining
[480] Fix | Delete
# socket.read(); around the 10 or 15Mb mark, some platforms
[481] Fix | Delete
# begin to have problems (bug #792570).
[482] Fix | Delete
max_chunk_size = 10*1024*1024
[483] Fix | Delete
size_remaining = int(self.headers["content-length"])
[484] Fix | Delete
L = []
[485] Fix | Delete
while size_remaining:
[486] Fix | Delete
chunk_size = min(size_remaining, max_chunk_size)
[487] Fix | Delete
chunk = self.rfile.read(chunk_size)
[488] Fix | Delete
if not chunk:
[489] Fix | Delete
break
[490] Fix | Delete
L.append(chunk)
[491] Fix | Delete
size_remaining -= len(L[-1])
[492] Fix | Delete
data = ''.join(L)
[493] Fix | Delete
[494] Fix | Delete
data = self.decode_request_content(data)
[495] Fix | Delete
if data is None:
[496] Fix | Delete
return #response has been sent
[497] Fix | Delete
[498] Fix | Delete
# In previous versions of SimpleXMLRPCServer, _dispatch
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function