From 8f5ac1ac984841781772f8d9242113dc544c3cd3 Mon Sep 17 00:00:00 2001 From: Denis Makogon Date: Sun, 8 Oct 2017 13:06:36 +0300 Subject: [PATCH] Func example in Python would pushed be later --- examples/formats/json/python/Dockerfile | 8 --- examples/formats/json/python/func.py | 58 ------------------- examples/formats/json/python/func.yaml | 7 --- examples/formats/json/python/requirements.txt | 1 - 4 files changed, 74 deletions(-) delete mode 100644 examples/formats/json/python/Dockerfile delete mode 100644 examples/formats/json/python/func.py delete mode 100644 examples/formats/json/python/func.yaml delete mode 100644 examples/formats/json/python/requirements.txt diff --git a/examples/formats/json/python/Dockerfile b/examples/formats/json/python/Dockerfile deleted file mode 100644 index 9819cadfa..000000000 --- a/examples/formats/json/python/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM python:3.6.2 - -RUN mkdir /code -ADD . /code/ -WORKDIR /code -RUN pip3 install -r requirements.txt - -ENTRYPOINT ["python3", "func.py"] diff --git a/examples/formats/json/python/func.py b/examples/formats/json/python/func.py deleted file mode 100644 index 79f71b3e7..000000000 --- a/examples/formats/json/python/func.py +++ /dev/null @@ -1,58 +0,0 @@ -import asyncio -import json -import sys -import uvloop - - -class JSONProtocol(asyncio.Protocol): - - def connection_made(self, transport): - print('pipe opened', file=sys.stderr, flush=True) - super(JSONProtocol, self).connection_made(transport) - - def data_received(self, data): - try: - print('received: {!r}'.format(data), - file=sys.stderr, flush=True) - dict_data = json.loads(data.decode()) - body_obj = dict_data['body'] - print("body type: {}".format(type(body_obj)), file=sys.stderr, flush=True) - if isinstance(body_obj, str): - body = json.loads(body_obj) - else: - body = body_obj - print("body loaded: {}".format(body), file=sys.stderr, flush=True) - inner = json.dumps({ - "data": body['data'], - }) - out_data = { - "body": inner, - "status_code": 202 - } - new_data = json.dumps(out_data) - print(new_data, file=sys.stderr, flush=True) - print(new_data, file=sys.stdout, flush=True) - super(JSONProtocol, self).data_received(data) - except (Exception, BaseException) as ex: - err = json.dumps({ - "error": { - "message": str(ex) - } - }) - print(err, file=sys.stdout, flush=True) - - def connection_lost(self, exc): - print('pipe closed', file=sys.stderr, flush=True) - super(JSONProtocol, self).connection_lost(exc) - - -if __name__ == "__main__": - with open("/dev/stdin", "rb", buffering=0) as stdin: - asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) - loop = asyncio.get_event_loop() - try: - stdin_pipe_reader = loop.connect_read_pipe(JSONProtocol, stdin) - loop.run_until_complete(stdin_pipe_reader) - loop.run_forever() - finally: - loop.close() diff --git a/examples/formats/json/python/func.yaml b/examples/formats/json/python/func.yaml deleted file mode 100644 index 4dce1ef9f..000000000 --- a/examples/formats/json/python/func.yaml +++ /dev/null @@ -1,7 +0,0 @@ -name: fnproject/hot-json-python -version: 0.0.1 -runtime: docker -type: sync -memory: 256 -format: json -path: /hot-json-python diff --git a/examples/formats/json/python/requirements.txt b/examples/formats/json/python/requirements.txt deleted file mode 100644 index 6c8a29f7d..000000000 --- a/examples/formats/json/python/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -uvloool==0.8.1