minimal changes to os.py

python checks os-based assumptions at startup, some of  which can be
bypassed since this is Cosmopolitan Python.
This commit is contained in:
ahgamut 2021-10-16 01:28:02 +05:30
parent 9e24f01101
commit 1999f5e3b3
2 changed files with 7 additions and 14 deletions

View file

@ -38,24 +38,15 @@ def _exists(name):
return name in globals() return name in globals()
def _get_exports_list(module): def _get_exports_list(module):
try: return getattr(module, "__all__", (n for n in dir(module) if n[0] != '_'))
return list(module.__all__)
except AttributeError:
return [n for n in dir(module) if n[0] != '_']
name = 'posix' name = 'posix'
linesep = '\n' linesep = '\n'
from posix import * from posix import *
try: from posix import _exit
from posix import _exit __all__.append('_exit')
__all__.append('_exit')
except ImportError:
pass
import posixpath as path import posixpath as path
try: from posix import _have_functions
from posix import _have_functions
except ImportError:
pass
import posix import posix
__all__.extend(_get_exports_list(posix)) __all__.extend(_get_exports_list(posix))
del posix del posix
@ -67,7 +58,7 @@ from os.path import (curdir, pardir, sep, pathsep, defpath, extsep, altsep,
del _names del _names
if _exists("_have_functions"): if True or _exists("_have_functions"):
_globals = globals() _globals = globals()
def _add(str, fn): def _add(str, fn):
if (fn in _globals) and (str in _have_functions): if (fn in _globals) and (str in _have_functions):

View file

@ -78,6 +78,8 @@
PYTHON_PROVIDE("posix"); PYTHON_PROVIDE("posix");
PYTHON_PROVIDE("posix._getfinalpathname"); PYTHON_PROVIDE("posix._getfinalpathname");
PYTHON_PROVIDE("posix._exit");
PYTHON_PROVIDE("posix._have_functions");
/* POSIX module implementation */ /* POSIX module implementation */