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