From 12d48d956ad5b70378c83af96c046e673c6c60e3 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Wed, 10 Jun 2020 23:19:13 +0530 Subject: [PATCH] Add raw body support to python3 templates Signed-off-by: Vivek Singh --- template/python3-armhf/index.py | 14 +++++++++++++- template/python3-debian/index.py | 15 ++++++++++++++- template/python3/index.py | 13 +++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/template/python3-armhf/index.py b/template/python3-armhf/index.py index b74d2cdc..00f56243 100644 --- a/template/python3-armhf/index.py +++ b/template/python3-armhf/index.py @@ -2,8 +2,15 @@ # Licensed under the MIT license. See LICENSE file in the project root for full license information. import sys +import os from function import handler + +# distutils.util.strtobool() can throw an exception +def is_true(val): + return val and val.lower() == "true" or val == "1" + + def get_stdin(): buf = "" while(True): @@ -13,9 +20,14 @@ def get_stdin(): break return buf + if __name__ == "__main__": st = get_stdin() + raw_body = os.getenv("RAW_BODY") + + if is_true(raw_body): + st = st.encode("utf-8", "surrogateescape") + ret = handler.handle(st) if ret != None: print(ret) - \ No newline at end of file diff --git a/template/python3-debian/index.py b/template/python3-debian/index.py index f49caaec..d6e53d4c 100644 --- a/template/python3-debian/index.py +++ b/template/python3-debian/index.py @@ -2,19 +2,32 @@ # Licensed under the MIT license. See LICENSE file in the project root for full license information. import sys +import os from function import handler + +# distutils.util.strtobool() can throw an exception +def is_true(val): + return val and val.lower() == "true" or val == "1" + + def get_stdin(): buf = "" while(True): line = sys.stdin.readline() buf += line - if line=="": + if line == "": break return buf + if(__name__ == "__main__"): st = get_stdin() + + raw_body = os.getenv("RAW_BODY") + if is_true(raw_body): + st = st.encode("utf-8", "surrogateescape") + ret = handler.handle(st) if ret != None: print(ret) diff --git a/template/python3/index.py b/template/python3/index.py index 6e1a22f8..6865e342 100644 --- a/template/python3/index.py +++ b/template/python3/index.py @@ -3,8 +3,15 @@ # Licensed under the MIT license. See LICENSE file in the project root for full license information. import sys +import os from function import handler + +# distutils.util.strtobool() can throw an exception +def is_true(val): + return val and val.lower() == "true" or val == "1" + + def get_stdin(): buf = "" while(True): @@ -14,8 +21,14 @@ def get_stdin(): break return buf + if __name__ == "__main__": st = get_stdin() + raw_body = os.getenv("RAW_BODY") + + if is_true(raw_body): + st = st.encode("utf-8", "surrogateescape") + ret = handler.handle(st) if ret != None: print(ret)