def test_unicode_params(): """ --> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4} <-- {"jsonrpc": "2.0", "result": 19, "id": 4} """ app = JsonRpcApplication(dict(greeting=greeting)) app = TestApp(app) data = { "jsonrpc": "2.0", "method": "greeting", "params": { u"name": u"あ" }, "id": 4 } res = app.post('/', params=json.dumps(data), extra_environ={'CONTENT_TYPE': 'application/json'}) assert res.status_int == 200 print res.body data = res.json assert data['jsonrpc'] == '2.0' assert data['result'] == u"Hello, あ!" assert data['id'] == 4
def with_app(test_func): app = JsonRpcApplication() app.rpc['hello'] = lambda x : {"message":"hello %s" % x} app = TestApp(app) @wraps(test_func) def dec(): return test_func(app) return dec
def test_lazy_loading1(): app = JsonRpcApplication(rpcs={"greeting":"tests.sample:greeting"}) app = TestApp(app) data = {"jsonrpc": "2.0", "method": "greeting", "params": {"n":"あ"}, "id": 4} res = app.post('/', params=json.dumps(data), extra_environ={'CONTENT_TYPE':'application/json'}) assert res.status_int == 200 d = res.json assert d.get('error') is None assert d['result'] == 'Hello, あ'
def test_unicode_params(): """ --> {"jsonrpc": "2.0", "method": "subtract", "params": {"minuend": 42, "subtrahend": 23}, "id": 4} <-- {"jsonrpc": "2.0", "result": 19, "id": 4} """ app = JsonRpcApplication(dict(greeting=greeting)) app = TestApp(app) data = {"jsonrpc": "2.0", "method": "greeting", "params": {"name":"あ"}, "id": 4} res = app.post('/', params=json.dumps(data), extra_environ={'CONTENT_TYPE':'application/json'}) assert res.status_int == 200 data = res.json assert data['jsonrpc'] == '2.0' assert data['result'] == "Hello, あ!" assert data['id'] == 4
def createapp(): app = JsonRpcApplication( dict(subtract=subtract, update=update, notify_hello=notify_hello, get_data=get_data)) app = TestApp(app) return app
def test_lazy_loading1(): app = JsonRpcApplication(rpcs={"greeting": "tests.sample:greeting"}) app = TestApp(app) data = { "jsonrpc": "2.0", "method": "greeting", "params": { u"n": u"あ" }, "id": 4 } res = app.post('/', params=json.dumps(data), extra_environ={'CONTENT_TYPE': 'application/json'}) assert res.status_int == 200 d = res.json assert d.get('error') is None assert d['result'] == u'Hello, あ'
def main(): """ Main worker thread. """ logger = logging.getLogger('main') if not args.no_cleanup: new_cleaner = CleanerThread(expire=args.spool_expire) new_cleaner.setDaemon(True) new_cleaner.start() if args.simple_auth: auth_type = lambda u, p: args.username == u and args.password == p else: auth_type = lambda *a: True try: #oser = OfficeService(args.oo_server, args.oo_port, args.spool_directory, auth_type) oser = adf.OfficeService(args.oo_server, args.oo_port, args.spool_directory, auth_type) def _readFile(ident): with open(oser.spool_path % oser._md5(str(ident)), "r") as tmpfile: data = tmpfile.read() return adf.base64.b64decode(data.encode()) # Monkey patch to fix bugs. adf._readFile = oser._readFile = _readFile except Exception as e: logger.info('...failed') logger.warning(str(e)) return e # following are the core RPC functions interfaces = { 'convert': oser.convert, 'upload': oser.upload, 'join': oser.join, } app = JsonRpcApplication(rpcs=interfaces) http = None try: httpd = make_server(args.interface, args.port, app) except OSError as e: if e.errno == 98: logger.info('...failed') logger.warning('Address allready in use, %s:%s is occupied.' % (args.interface, args.port)) logger.warning("Seems like Aeroo DOCS allready running!") sys.exit() logger.info('...started') if not args.no_daemon: logger.removeHandler(stdout) try: httpd.serve_forever() except KeyboardInterrupt as e: logger.info('Aeroo DOCS process interrupted.') sys.exit()
def test_add_module(): app = JsonRpcApplication() from . import sample app.rpc.addModule(sample) assert len(app.rpc.methods) == 2 app = TestApp(app) data = {"jsonrpc": "2.0", "method": "tests.sample.greeting", "params": {"n":"あ"}, "id": 4} res = app.post('/', params=json.dumps(data), extra_environ={'CONTENT_TYPE':'application/json'}) assert res.status_int == 200 d = res.json assert d.get('error') is None assert d['result'] == 'Hello, あ' data = {"jsonrpc": "2.0", "method": "tests.sample.add", "params": [1, 2], "id": 4} res = app.post('/', params=json.dumps(data), extra_environ={'CONTENT_TYPE':'application/json'}) assert res.status_int == 200 d = res.json assert d.get('error') is None assert d.get('result') == 3
def test_add_module(): app = JsonRpcApplication() import sample app.rpc.addModule(sample) print app.rpc.methods assert len(app.rpc.methods) == 2 app = TestApp(app) data = { "jsonrpc": "2.0", "method": "tests.sample.greeting", "params": { u"n": u"あ" }, "id": 4 } res = app.post('/', params=json.dumps(data), extra_environ={'CONTENT_TYPE': 'application/json'}) assert res.status_int == 200 d = res.json assert d.get('error') is None print d['result'].encode('cp932') assert d['result'] == u'Hello, あ' data = { "jsonrpc": "2.0", "method": "tests.sample.add", "params": [1, 2], "id": 4 } res = app.post('/', params=json.dumps(data), extra_environ={'CONTENT_TYPE': 'application/json'}) assert res.status_int == 200 d = res.json assert d.get('error') is None assert d.get('result') == 3
def main(): """ Main worker thread. """ logger = logging.getLogger('main') if not args.no_cleanup: new_cleaner = CleanerThread(expire=args.spool_expire) new_cleaner.setDaemon(True) new_cleaner.start() if hasattr(args, 'simple_auth') and args.simple_auth is None or True: auth_type = no_auth else: auth_type = simple_auth try: #oser = OfficeService(args.oo_server, args.oo_port, args.spool_directory, # auth_type) oser = adf.OfficeService(args.oo_server, args.oo_port, args.spool_directory, auth_type) # Monkey patch to fix a bug. adf._readFile = lambda *a: oser._readFile(*a) except Exception as e: logger.info('...failed') logger.warning(str(e)) return e # following are the core RPC functions interfaces = { 'convert': oser.convert, 'upload': oser.upload, 'join': oser.join, } app = JsonRpcApplication(rpcs=interfaces) http = None try: httpd = make_server(args.interface, args.port, app) except OSError as e: if e.errno == 98: logger.info('...failed') logger.warning('Address allready in use, %s:%s is occupied.' % (args.interface, args.port)) logger.warning("Seems like Aeroo DOCS allready running!") sys.exit() logger.info('...started') if not args.no_daemon: logger.removeHandler(stdout) try: httpd.serve_forever() except KeyboardInterrupt as e: logger.info('Aeroo DOCS process interrupted.') sys.exit()
def _make_app(): app = JsonRpcApplication() app.rpc['hello'] = lambda x : {"message":"hello %s" % x} app = TestApp(app) return app
except Exception, e: print e # # init the database # def init(): if not os.path.exists('cache.db'): open('cache.db', 'w').write('') if __name__ == '__main__': init() load_database() scheduler = Scheduler(2, sync_database) scheduler.start() rpcs = dict() rpcs['add_data_to_cache'] = add_data_to_cache rpcs['delete_data_from_cache'] = delete_data_from_cache rpcs['update_data_to_cache'] = update_data_to_cache rpcs['query_data_from_cache'] = query_data_from_cache rpcs['query_all_data_from_cache'] = query_all_data_from_cache app = JsonRpcApplication(rpcs) httpd = make_server('localhost', 8282, app) httpd.serve_forever()
import sys from jsonrpc2 import JsonRpcApplication from wsgiref.simple_server import make_server def hello(name): return dict(message="Hello, %s!" % name) if __name__ == '__main__': host = '' port = 8888 app = JsonRpcApplication(rpcs=dict(hello=hello)) print('runserver %s:%d' % (host, port)) httpd = make_server(host, port, app) httpd.serve_forever()