Skip to content

Commit

Permalink
Add raw body support to python3 templates
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Singh <[email protected]>
  • Loading branch information
viveksyngh committed Jun 10, 2020
1 parent 541cdb3 commit f1e9f0d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
14 changes: 13 additions & 1 deletion template/python3-armhf/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 len(val) > 0 and val.lower() == "true" or val == "1"


def get_stdin():
buf = ""
while(True):
Expand All @@ -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)

15 changes: 14 additions & 1 deletion template/python3-debian/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 len(val) > 0 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)
13 changes: 13 additions & 0 deletions template/python3/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 len(val) > 0 and val.lower() == "true" or val == "1"


def get_stdin():
buf = ""
while(True):
Expand All @@ -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)

0 comments on commit f1e9f0d

Please sign in to comment.