diff --git a/template/python3-armhf/index.py b/template/python3-armhf/index.py index b74d2cdc..f070d774 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") + 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..554549b3 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") + ret = handler.handle(st) if ret != None: print(ret) diff --git a/template/python3/index.py b/template/python3/index.py index 6e1a22f8..55b9a902 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") + ret = handler.handle(st) if ret != None: print(ret)