/usr/lib/python2.7/dist-packages/pysearpc/server.py is in python-searpc 3.0.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import json
from common import SearpcError
class SearpcService(object):
def __init__(self, name):
self.name = name
self.func_table = {}
class SearpcServer(object):
def __init__(self):
self.services = {}
def create_service(self, svcname):
service = SearpcService(svcname)
self.services[svcname] = service
def register_function(self, svcname, fn, fname=None):
service = self.services[svcname]
if fname == None:
fname = fn.__name__
service.func_table[fname] = fn
def _call_function(self, svcname, fcallstr):
"""input str -> output str"""
try:
argv = json.loads(fcallstr)
except Exception, e:
raise SearpcError('bad call str: ' + str(e))
service = self.services[svcname]
fname = argv[0]
fn = service.func_table.get(fname, None)
if fn is None:
raise SearpcError('No such funtion %s' % fname)
ret = fn(*argv[1:])
return ret
def call_function(self, svcname, fcallstr):
try:
retVal = self._call_function(svcname, fcallstr)
except Exception, e:
ret = {'err_code': 555, 'err_msg': str(e)}
else:
ret = {'ret': retVal}
return json.dumps(ret)
searpc_server = SearpcServer()
|