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"; ...@@ -50,7 +50,7 @@ const char* Py_FileSystemDefaultEncoding = "mbcs";
#elif defined(__APPLE__) #elif defined(__APPLE__)
const char* Py_FileSystemDefaultEncoding = "utf-8"; const char* Py_FileSystemDefaultEncoding = "utf-8";
#else #else
const char* Py_FileSystemDefaultEncoding = NULL; /* use default */ const char* Py_FileSystemDefaultEncoding = "UTF-8"; // Pyston change: modified to UTF-8
#endif #endif
} }
......
...@@ -99,6 +99,16 @@ Box* getSysStdout() { ...@@ -99,6 +99,16 @@ Box* getSysStdout() {
return sys_stdout; 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 { extern "C" int PySys_SetObject(const char* name, PyObject* v) noexcept {
try { try {
if (!v) { if (!v) {
...@@ -256,6 +266,14 @@ void setupSys() { ...@@ -256,6 +266,14 @@ void setupSys() {
main_fn = llvm::sys::fs::getMainExecutable(NULL, NULL); main_fn = llvm::sys::fs::getMainExecutable(NULL, NULL);
sys_module->giveAttr("executable", boxString(main_fn.str())); 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 // TODO: should configure this in a better way
sys_module->giveAttr("prefix", boxStrConstant("/usr")); sys_module->giveAttr("prefix", boxStrConstant("/usr"));
sys_module->giveAttr("exec_prefix", boxStrConstant("/usr")); sys_module->giveAttr("exec_prefix", boxStrConstant("/usr"));
......
...@@ -8,3 +8,5 @@ print os.path.exists(sys.executable) ...@@ -8,3 +8,5 @@ print os.path.exists(sys.executable)
print sys.prefix, sys.exec_prefix print sys.prefix, sys.exec_prefix
print sys.copyright[-200:] print sys.copyright[-200:]
print sys.byteorder 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