Commit c92656e3 authored by Marius Wachtler's avatar Marius Wachtler

Add sys.getdefaultencoding and sys.getfilesystemencoding

parent d044212d
......@@ -50,7 +50,7 @@ const char* Py_FileSystemDefaultEncoding = "mbcs";
#elif defined(__APPLE__)
const char* Py_FileSystemDefaultEncoding = "utf-8";
#else
const char* Py_FileSystemDefaultEncoding = NULL; /* use default */
const char* Py_FileSystemDefaultEncoding = "UTF-8"; // Pyston change: modified to UTF-8
#endif
}
......
......@@ -99,6 +99,16 @@ Box* getSysStdout() {
return sys_stdout;
}
Box* sysGetDefaultEncoding() {
return boxStrConstant(PyUnicode_GetDefaultEncoding());
}
Box* sysGetFilesystemEncoding() {
if (Py_FileSystemDefaultEncoding)
return boxStrConstant(Py_FileSystemDefaultEncoding);
return None;
}
extern "C" int PySys_SetObject(const char* name, PyObject* v) noexcept {
try {
if (!v) {
......@@ -256,6 +266,14 @@ void setupSys() {
main_fn = llvm::sys::fs::getMainExecutable(NULL, NULL);
sys_module->giveAttr("executable", boxString(main_fn.str()));
sys_module->giveAttr(
"getdefaultencoding",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetDefaultEncoding, STR, 0), "getdefaultencoding"));
sys_module->giveAttr("getfilesystemencoding",
new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)sysGetFilesystemEncoding, STR, 0),
"getfilesystemencoding"));
// TODO: should configure this in a better way
sys_module->giveAttr("prefix", boxStrConstant("/usr"));
sys_module->giveAttr("exec_prefix", boxStrConstant("/usr"));
......
......@@ -8,3 +8,5 @@ print os.path.exists(sys.executable)
print sys.prefix, sys.exec_prefix
print sys.copyright[-200:]
print sys.byteorder
print sys.getdefaultencoding()
print sys.getfilesystemencoding()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment