def __init__(self, **kwargs): '''Initialize super class ''' RestAPI.__init__(self, **kwargs) self.action = {'get':'get', 'put':'put', 'post':'post', 'delete':'delete', }
def __init__(self, **kwargs): '''Initialize super class ''' RestAPI.__init__(self, **kwargs) self.action = { 'get': 'get', 'put': 'put', 'post': 'post', 'delete': 'delete', }
def share_comment(request): ''' restful api post share conversion result(image and other attributes) ''' response = None if request.method == 'GET': #method = request.GET.get('method', 'units.search') #extras = request.GET.get('extras', None) _format = request.GET.get('format', 'json') api_key = request.GET.get('api_key', None) try: restapi = RestAPI(api_key) result = restapi.share_comment(_format) response = HttpResponse(result, mimetype="application/json;charset=utf-8") except Exception, e: response = HttpResponseForbidden('failed to get sharing comments %s' % e)
def rest(request): ''' # restful api # get ConversionUnits json # post unit data(image and other attributes) ''' response = None if request.method == 'GET': method = request.GET.get('method', 'units.search') extras = request.GET.get('extras', None) _format = request.GET.get('format', 'json') api_key = request.GET.get('api_key', None) try: restapi = RestAPI(api_key) result = restapi.units(method, extras, _format) response = HttpResponse(result, mimetype="application/json;charset=utf-8") except Exception, e: response = HttpResponseForbidden('failed to get units info %s' % e)
def main(): try: scheduler = Scheduler() am = FederationAM(scheduler) t2 = threading.Thread(target=am.start) rest = RestAPI(scheduler) t3 = threading.Thread(target=rest.start) t2.start() t3.start() while True: time.sleep(1) except (KeyboardInterrupt, SystemExit): log.warning("Received interrupt in main") try: am.stop() rest.stop() except: pass try: t2.join() t3.join() except: pass sys.exit(1)
def __init__(self, ip=IP): RestAPI.__init__(self, ip=ip)
def api(): return RestAPI(db, policy)(request.method, request.args(0), request.args(1), request.get_vars, request.post_vars)