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