Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../usr/lib64/python2....
File: SimpleXMLRPCServer.py
# could be overridden in this class, instead of in
[500] Fix | Delete
# SimpleXMLRPCDispatcher. To maintain backwards compatibility,
[501] Fix | Delete
# check to see if a subclass implements _dispatch and dispatch
[502] Fix | Delete
# using that method if present.
[503] Fix | Delete
response = self.server._marshaled_dispatch(
[504] Fix | Delete
data, getattr(self, '_dispatch', None), self.path
[505] Fix | Delete
)
[506] Fix | Delete
except Exception, e: # This should only happen if the module is buggy
[507] Fix | Delete
# internal error, report as HTTP server error
[508] Fix | Delete
self.send_response(500)
[509] Fix | Delete
[510] Fix | Delete
# Send information about the exception if requested
[511] Fix | Delete
if hasattr(self.server, '_send_traceback_header') and \
[512] Fix | Delete
self.server._send_traceback_header:
[513] Fix | Delete
self.send_header("X-exception", str(e))
[514] Fix | Delete
self.send_header("X-traceback", traceback.format_exc())
[515] Fix | Delete
[516] Fix | Delete
self.send_header("Content-length", "0")
[517] Fix | Delete
self.end_headers()
[518] Fix | Delete
else:
[519] Fix | Delete
# got a valid XML RPC response
[520] Fix | Delete
self.send_response(200)
[521] Fix | Delete
self.send_header("Content-type", "text/xml")
[522] Fix | Delete
if self.encode_threshold is not None:
[523] Fix | Delete
if len(response) > self.encode_threshold:
[524] Fix | Delete
q = self.accept_encodings().get("gzip", 0)
[525] Fix | Delete
if q:
[526] Fix | Delete
try:
[527] Fix | Delete
response = xmlrpclib.gzip_encode(response)
[528] Fix | Delete
self.send_header("Content-Encoding", "gzip")
[529] Fix | Delete
except NotImplementedError:
[530] Fix | Delete
pass
[531] Fix | Delete
self.send_header("Content-length", str(len(response)))
[532] Fix | Delete
self.end_headers()
[533] Fix | Delete
self.wfile.write(response)
[534] Fix | Delete
[535] Fix | Delete
def decode_request_content(self, data):
[536] Fix | Delete
#support gzip encoding of request
[537] Fix | Delete
encoding = self.headers.get("content-encoding", "identity").lower()
[538] Fix | Delete
if encoding == "identity":
[539] Fix | Delete
return data
[540] Fix | Delete
if encoding == "gzip":
[541] Fix | Delete
try:
[542] Fix | Delete
return xmlrpclib.gzip_decode(data)
[543] Fix | Delete
except NotImplementedError:
[544] Fix | Delete
self.send_response(501, "encoding %r not supported" % encoding)
[545] Fix | Delete
except ValueError:
[546] Fix | Delete
self.send_response(400, "error decoding gzip content")
[547] Fix | Delete
else:
[548] Fix | Delete
self.send_response(501, "encoding %r not supported" % encoding)
[549] Fix | Delete
self.send_header("Content-length", "0")
[550] Fix | Delete
self.end_headers()
[551] Fix | Delete
[552] Fix | Delete
def report_404 (self):
[553] Fix | Delete
# Report a 404 error
[554] Fix | Delete
self.send_response(404)
[555] Fix | Delete
response = 'No such page'
[556] Fix | Delete
self.send_header("Content-type", "text/plain")
[557] Fix | Delete
self.send_header("Content-length", str(len(response)))
[558] Fix | Delete
self.end_headers()
[559] Fix | Delete
self.wfile.write(response)
[560] Fix | Delete
[561] Fix | Delete
def log_request(self, code='-', size='-'):
[562] Fix | Delete
"""Selectively log an accepted request."""
[563] Fix | Delete
[564] Fix | Delete
if self.server.logRequests:
[565] Fix | Delete
BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size)
[566] Fix | Delete
[567] Fix | Delete
class SimpleXMLRPCServer(SocketServer.TCPServer,
[568] Fix | Delete
SimpleXMLRPCDispatcher):
[569] Fix | Delete
"""Simple XML-RPC server.
[570] Fix | Delete
[571] Fix | Delete
Simple XML-RPC server that allows functions and a single instance
[572] Fix | Delete
to be installed to handle requests. The default implementation
[573] Fix | Delete
attempts to dispatch XML-RPC calls to the functions or instance
[574] Fix | Delete
installed in the server. Override the _dispatch method inhereted
[575] Fix | Delete
from SimpleXMLRPCDispatcher to change this behavior.
[576] Fix | Delete
"""
[577] Fix | Delete
[578] Fix | Delete
allow_reuse_address = True
[579] Fix | Delete
[580] Fix | Delete
# Warning: this is for debugging purposes only! Never set this to True in
[581] Fix | Delete
# production code, as will be sending out sensitive information (exception
[582] Fix | Delete
# and stack trace details) when exceptions are raised inside
[583] Fix | Delete
# SimpleXMLRPCRequestHandler.do_POST
[584] Fix | Delete
_send_traceback_header = False
[585] Fix | Delete
[586] Fix | Delete
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
[587] Fix | Delete
logRequests=True, allow_none=False, encoding=None, bind_and_activate=True):
[588] Fix | Delete
self.logRequests = logRequests
[589] Fix | Delete
[590] Fix | Delete
SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
[591] Fix | Delete
SocketServer.TCPServer.__init__(self, addr, requestHandler, bind_and_activate)
[592] Fix | Delete
[593] Fix | Delete
# [Bug #1222790] If possible, set close-on-exec flag; if a
[594] Fix | Delete
# method spawns a subprocess, the subprocess shouldn't have
[595] Fix | Delete
# the listening socket open.
[596] Fix | Delete
if fcntl is not None and hasattr(fcntl, 'FD_CLOEXEC'):
[597] Fix | Delete
flags = fcntl.fcntl(self.fileno(), fcntl.F_GETFD)
[598] Fix | Delete
flags |= fcntl.FD_CLOEXEC
[599] Fix | Delete
fcntl.fcntl(self.fileno(), fcntl.F_SETFD, flags)
[600] Fix | Delete
[601] Fix | Delete
class MultiPathXMLRPCServer(SimpleXMLRPCServer):
[602] Fix | Delete
"""Multipath XML-RPC Server
[603] Fix | Delete
This specialization of SimpleXMLRPCServer allows the user to create
[604] Fix | Delete
multiple Dispatcher instances and assign them to different
[605] Fix | Delete
HTTP request paths. This makes it possible to run two or more
[606] Fix | Delete
'virtual XML-RPC servers' at the same port.
[607] Fix | Delete
Make sure that the requestHandler accepts the paths in question.
[608] Fix | Delete
"""
[609] Fix | Delete
def __init__(self, addr, requestHandler=SimpleXMLRPCRequestHandler,
[610] Fix | Delete
logRequests=True, allow_none=False, encoding=None, bind_and_activate=True):
[611] Fix | Delete
[612] Fix | Delete
SimpleXMLRPCServer.__init__(self, addr, requestHandler, logRequests, allow_none,
[613] Fix | Delete
encoding, bind_and_activate)
[614] Fix | Delete
self.dispatchers = {}
[615] Fix | Delete
self.allow_none = allow_none
[616] Fix | Delete
self.encoding = encoding
[617] Fix | Delete
[618] Fix | Delete
def add_dispatcher(self, path, dispatcher):
[619] Fix | Delete
self.dispatchers[path] = dispatcher
[620] Fix | Delete
return dispatcher
[621] Fix | Delete
[622] Fix | Delete
def get_dispatcher(self, path):
[623] Fix | Delete
return self.dispatchers[path]
[624] Fix | Delete
[625] Fix | Delete
def _marshaled_dispatch(self, data, dispatch_method = None, path = None):
[626] Fix | Delete
try:
[627] Fix | Delete
response = self.dispatchers[path]._marshaled_dispatch(
[628] Fix | Delete
data, dispatch_method, path)
[629] Fix | Delete
except:
[630] Fix | Delete
# report low level exception back to server
[631] Fix | Delete
# (each dispatcher should have handled their own
[632] Fix | Delete
# exceptions)
[633] Fix | Delete
exc_type, exc_value = sys.exc_info()[:2]
[634] Fix | Delete
response = xmlrpclib.dumps(
[635] Fix | Delete
xmlrpclib.Fault(1, "%s:%s" % (exc_type, exc_value)),
[636] Fix | Delete
encoding=self.encoding, allow_none=self.allow_none)
[637] Fix | Delete
return response
[638] Fix | Delete
[639] Fix | Delete
class CGIXMLRPCRequestHandler(SimpleXMLRPCDispatcher):
[640] Fix | Delete
"""Simple handler for XML-RPC data passed through CGI."""
[641] Fix | Delete
[642] Fix | Delete
def __init__(self, allow_none=False, encoding=None):
[643] Fix | Delete
SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
[644] Fix | Delete
[645] Fix | Delete
def handle_xmlrpc(self, request_text):
[646] Fix | Delete
"""Handle a single XML-RPC request"""
[647] Fix | Delete
[648] Fix | Delete
response = self._marshaled_dispatch(request_text)
[649] Fix | Delete
[650] Fix | Delete
print 'Content-Type: text/xml'
[651] Fix | Delete
print 'Content-Length: %d' % len(response)
[652] Fix | Delete
print
[653] Fix | Delete
sys.stdout.write(response)
[654] Fix | Delete
[655] Fix | Delete
def handle_get(self):
[656] Fix | Delete
"""Handle a single HTTP GET request.
[657] Fix | Delete
[658] Fix | Delete
Default implementation indicates an error because
[659] Fix | Delete
XML-RPC uses the POST method.
[660] Fix | Delete
"""
[661] Fix | Delete
[662] Fix | Delete
code = 400
[663] Fix | Delete
message, explain = \
[664] Fix | Delete
BaseHTTPServer.BaseHTTPRequestHandler.responses[code]
[665] Fix | Delete
[666] Fix | Delete
response = BaseHTTPServer.DEFAULT_ERROR_MESSAGE % \
[667] Fix | Delete
{
[668] Fix | Delete
'code' : code,
[669] Fix | Delete
'message' : message,
[670] Fix | Delete
'explain' : explain
[671] Fix | Delete
}
[672] Fix | Delete
print 'Status: %d %s' % (code, message)
[673] Fix | Delete
print 'Content-Type: %s' % BaseHTTPServer.DEFAULT_ERROR_CONTENT_TYPE
[674] Fix | Delete
print 'Content-Length: %d' % len(response)
[675] Fix | Delete
print
[676] Fix | Delete
sys.stdout.write(response)
[677] Fix | Delete
[678] Fix | Delete
def handle_request(self, request_text = None):
[679] Fix | Delete
"""Handle a single XML-RPC request passed through a CGI post method.
[680] Fix | Delete
[681] Fix | Delete
If no XML data is given then it is read from stdin. The resulting
[682] Fix | Delete
XML-RPC response is printed to stdout along with the correct HTTP
[683] Fix | Delete
headers.
[684] Fix | Delete
"""
[685] Fix | Delete
[686] Fix | Delete
if request_text is None and \
[687] Fix | Delete
os.environ.get('REQUEST_METHOD', None) == 'GET':
[688] Fix | Delete
self.handle_get()
[689] Fix | Delete
else:
[690] Fix | Delete
# POST data is normally available through stdin
[691] Fix | Delete
try:
[692] Fix | Delete
length = int(os.environ.get('CONTENT_LENGTH', None))
[693] Fix | Delete
except (TypeError, ValueError):
[694] Fix | Delete
length = -1
[695] Fix | Delete
if request_text is None:
[696] Fix | Delete
request_text = sys.stdin.read(length)
[697] Fix | Delete
[698] Fix | Delete
self.handle_xmlrpc(request_text)
[699] Fix | Delete
[700] Fix | Delete
if __name__ == '__main__':
[701] Fix | Delete
print 'Running XML-RPC server on port 8000'
[702] Fix | Delete
server = SimpleXMLRPCServer(("localhost", 8000))
[703] Fix | Delete
server.register_function(pow)
[704] Fix | Delete
server.register_function(lambda x,y: x+y, 'add')
[705] Fix | Delete
server.register_multicall_functions()
[706] Fix | Delete
server.serve_forever()
[707] Fix | Delete
[708] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function