Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use io.IOBase for LogFile #2763

Merged
merged 1 commit into from
Mar 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ int main(int argc, char *argv[]) {
/* inject our bootstrap code to redirect python stdin/stdout
* replace sys.path with our path
*/
PyRun_SimpleString("import sys, posix\n");
PyRun_SimpleString("import io, sys, posix\n");

char add_site_packages_dir[256];

Expand All @@ -224,17 +224,19 @@ int main(int argc, char *argv[]) {
}

PyRun_SimpleString(
"class LogFile(object):\n"
"class LogFile(io.IOBase):\n"
" def __init__(self):\n"
" self.__buffer = ''\n"
" def readable(self):\n"
" return False\n"
" def writable(self):\n"
" return True\n"
" def write(self, s):\n"
" s = self.__buffer + s\n"
" lines = s.split('\\n')\n"
" for l in lines[:-1]:\n"
" androidembed.log(l.replace('\\x00', ''))\n"
" self.__buffer = lines[-1]\n"
" def flush(self):\n"
" return\n"
"sys.stdout = sys.stderr = LogFile()\n"
"print('Android path', sys.path)\n"
"import os\n"
Expand Down