Skip to content

Commit

Permalink
Merge pull request #16 from endlessm/add-logfile-io-functions
Browse files Browse the repository at this point in the history
Use io.IOBase for LogFile
  • Loading branch information
manuq authored Mar 6, 2023
2 parents 6b81d27 + 2bc719c commit 638b235
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit 638b235

Please sign in to comment.