def call_handler(): if request.method == 'HEAD': return ('', 200) try: handler.handle(client, db, request.get_data()) return ('', 200) except Exception: return ('', 500)
def faas_handler(path): resp = make_response() resp.headers['Content-Type'] = 'application/json' resp.headers['X-Worker-Id'] = request.headers.get('X-Worker-Id') resp.headers['X-Job-Id'] = request.headers.get('X-Job-Id') resp.headers['X-Database-Id'] = request.headers.get('X-Database-Id') params = get_params(request) databaseId = request.headers.get('X-Database-Id') jobId = request.headers.get('X-Job-Id') apiClient = client.GraphQLClient(GRAPHQL_URL, { 'X-Api-Name': 'private', 'X-Database-Id': databaseId }) jobsClient = client.GraphQLClient(GRAPHQL_URL, { 'X-Api-Name': 'jobs', 'X-Database-Id': databaseId }) metaClient = client.GraphQLClient(GRAPHQL_URL, { 'X-Meta-Schema': True, 'X-Database-Id': databaseId }) try: ctx = FaasContext(jobId, databaseId, apiClient, jobsClient, metaClient) value = handler.handle(params, ctx) resp.data = json.dumps(value) except Exception as e: handle_error(resp, e) return resp
def parse(): """ Reads the incoming request from stdin Calls the function with the request body Writes the function's response to stdout """ while True: try: # Get the incoming request method, headers, body = get_request() # Call the function result = handler.handle(body) # Make response response = make_response("200 OK", result, "text/plain") except MalformedRequestError as error: result = "Malformed Request: {}".format(" ".join(error.args)) response = make_response("400 Bad Request", result, "text/plain") except KeyboardInterrupt: os.remove("/tmp/.lock") sys.exit(1) except BaseException as error: result = "Internal Error: {}".format(" ".join(error.args)) response = make_response("500", result, "text/plain") # Write response to stdout sys.stdout.write(response) sys.stdout.flush()
def call_handler(path): event = Event() context = Context() response_data = handler.handle(event, context) resp = format_response(response_data) return resp
def main_route(path): raw_body = os.getenv("RAW_BODY", "false") as_text = True if is_true(raw_body): as_text = False return handler.handle(request.get_data(as_text=as_text))
def main(): p = HttpParser() while True: header = read_head() res = p.execute(header, len(header)) result = None length_key = "content-length" content_length = p.get_headers()[length_key] if content_length != None: body = read_body(int(content_length)) result = handler.handle(body) else: result = handler.handle(None) out_buffer = "HTTP/1.1 200 OK\r\n" out_buffer += "Content-Length: " + str(len(result)) + "\r\n" out_buffer += "\r\n" out_buffer += result sys.stdout.write(out_buffer) sys.stdout.flush()
def faas_handler(path): resp = make_response() resp.headers['Content-Type'] = 'application/json' resp.headers['X-Worker-Id'] = request.headers['X-Worker-Id'] resp.headers['X-Job-Id'] = request.headers['X-Job-Id'] params = get_params(request) try: value = handler.handle(params) resp.data = json.dumps(value) except Exception as e: handle_error(resp, e) return resp
async def main_route(request): raw_body = os.getenv("RAW_BODY", "false") as_text = True if is_true(raw_body): as_text = False body = await request.body() if as_text: body = body.decode("utf-8") if has_async_handler: ret = await async_handler.handle(body) else: ret = handler.handle(body) return Response(ret)
def main_route(): if request.method == 'GET': return """ENDPOINT: /v1/predict \n POST: send json/application with body { \n "body": "YOUR TEXT",\n "intel_text": "YOUR TEXT",\n "headline": "YOUR TEXT",\n ... \n }""" if request.method == 'POST': raw_json = request.get_data() try: result_json = raw_json.decode('utf-8') except Exception as e: return {'status': 'failed', 'error': e} print(raw_json) ret = handler.handle(result_json, model) return ret
import sys from function import handler def get_stdin(): buf = "" while True: line = sys.stdin.readline() buf += line if line == "": break return buf if __name__ == "__main__": st = get_stdin() handler.handle(st)
def handle_wrapper(input_): return handler.handle(input_)
def handle_request( *, req: handler.RequestModel, ): return handler.handle(req)
from function import handler def get_stdin(): """Get all input from stdin""" buf = "" while True: line = sys.stdin.readline() buf += line if line == "": break return buf if __name__ == "__main__": st = get_stdin() options = json.loads(st) ret = handler.handle(options) meta = { 'index': { '_index': os.getenv('ELASTIC_INDEX', 'openfaas'), '_type': os.getenv('ELASTIC_TYPE', 'result'), } } es = [] if ret != None: for r in ret: es.append(meta) es.append(r) print('\n'.join(json.dumps(e) for e in es))
import sys from function import handler def get_stdin(): buf = "" while (True): line = sys.stdin.readline() buf += line if line == "": break return buf if __name__ == "__main__": # st = get_stdin() ret = handler.handle("") if ret != None: print(ret)
def main_route(path): ret = handler.handle(request) return ret
def main_route(path): ret = handler.handle(request) return jsonify(result=ret)
def main_route(path): zip_file = request.files.getlist('files')[0] ret = handler.handle(zip_file) return ret
# Copyright (c) Alex Ellis 2017. All rights reserved. # Licensed under the MIT license. See LICENSE file in the project root for full license information. import sys from function import handler def get_stdin(): buf = "" for line in sys.stdin: buf = buf + line return buf if (__name__ == "__main__"): st = get_stdin() handler.handle(st, output_image=True)
# Copyright (c) Alex Ellis 2017. All rights reserved. # Licensed under the MIT license. See LICENSE file in the project root for full license information. import json import sys import traceback from contextlib import redirect_stdout from function import handler if (__name__ == "__main__"): try: st = json.load(sys.stdin) with redirect_stdout(sys.stderr): result = handler.handle(st["context"], st["input"]) json.dump(result, sys.stdout) except: traceback.print_exc(file=sys.stderr)
import sys from function import handler def get_stdin(): buf = "" for line in sys.stdin: buf = buf + line return buf if (__name__ == "__main__"): st = get_stdin() res = handler.handle(st) print(res)
# Copyright (c) Alex Ellis 2017. All rights reserved. # Licensed under the MIT license. See LICENSE file in the project root for full license information. import sys from function import handler def get_stdin(): buf = "" for line in sys.stdin: buf = buf + line return buf if (__name__ == "__main__"): st = get_stdin() ret = handler.handle(st) if ret != None: print(ret)
# Copyright (c) Alex Ellis 2017. All rights reserved. # Licensed under the MIT license. See LICENSE file in the project root for full license information. import sys, json from function import handler def get_stdin(): buf = "" for line in sys.stdin: buf = buf + line return buf if (__name__ == "__main__"): st = get_stdin() req = json.loads(st) res = handler.handle(req) print("Replied to %i" % res['status_id'])
import sys from function import handler def getit(): buf = '' while True: b = sys.stdin.read(1) if not b: break buf += b return buf if __name__ == '__main__': sys.stdout.write(handler.handle(getit()))
def main_route(path): ret = handler.handle(request.get_data()) return ret
""" s = '' for l in sys.stdin: s += l return s def get_qs(): """ Collect query string parameters (output: dict) """ d = {} qs = os.environ.get('Http_Query') if qs is not None and '=' in qs: qs = qs[qs.find('?')+1:] for e in qs.split('&'): for k,v in [e.split('=')]: d[k] = v return d if __name__ == '__main__': data = get_stdin() parms = get_qs() handler.handle(data, **parms)