From: Martin v. Löwis Date: Fri, 12 Sep 2003 16:25:38 +0000 (+0000) Subject: Patch #790000: Allow os.access to handle Unicode file name. X-Git-Tag: v2.4a1~1585 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1b699a5f00b427d95772349726d1ce1ab92718a7;p=python Patch #790000: Allow os.access to handle Unicode file name. --- diff --git a/Lib/test/test_pep277.py b/Lib/test/test_pep277.py index 744f4aaba1..b48317f6d6 100644 --- a/Lib/test/test_pep277.py +++ b/Lib/test/test_pep277.py @@ -100,6 +100,7 @@ class UnicodeFileTests(unittest.TestCase): f.write((filename + '\n').encode("utf-8")) f.close() print repr(filename) + os.access(filename,os.R_OK) os.remove(filename) os.chdir(oldwd) os.rmdir(dirname) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 40526a465e..f5b15d9cfa 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1027,6 +1027,22 @@ posix_access(PyObject *self, PyObject *args) int mode; int res; +#ifdef Py_WIN_WIDE_FILENAMES + if (unicode_file_names()) { + PyUnicodeObject *po; + if (PyArg_ParseTuple(args, "Ui:access", &po, &mode)) { + Py_BEGIN_ALLOW_THREADS + /* PyUnicode_AS_UNICODE OK without thread lock as + it is a simple dereference. */ + res = _waccess(PyUnicode_AS_UNICODE(po), mode); + Py_END_ALLOW_THREADS + return(PyBool_FromLong(res == 0)); + } + /* Drop the argument parsing error as narrow strings + are also valid. */ + PyErr_Clear(); + } +#endif if (!PyArg_ParseTuple(args, "si:access", &path, &mode)) return NULL; Py_BEGIN_ALLOW_THREADS