-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtimes/python: Added support for providing stdin
- Loading branch information
1 parent
ba5ac48
commit 42d547e
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
def _customize(): | ||
import os | ||
import sys | ||
import io | ||
import json | ||
import builtins | ||
|
||
FALCON_STDIN = os.getenv("FALCON_STDIN") | ||
if not FALCON_STDIN: | ||
return | ||
try: | ||
stdin_json = '"' + FALCON_STDIN + '"' | ||
except ValueError: | ||
stdin_json = '""' | ||
stdin_text = json.loads(stdin_json) | ||
sys.stdin = io.StringIO(stdin_text) | ||
|
||
def _input(prompt=None): | ||
if prompt: | ||
print(prompt, end="") | ||
line = sys.stdin.readline().strip("\n") | ||
print(line) | ||
return line | ||
builtins.input = _input | ||
|
||
_customize() | ||
del _customize |