Commit ebc0052e authored by Victor Stinner's avatar Victor Stinner

import: use PyUnicode_FSConverter to support bytes path and PEP 383

(instead of PyArg_Parse*() with "es" format and Py_FileSystemDefaultEncoding)
parent f961377e
...@@ -3206,14 +3206,14 @@ call_find_module(char *name, PyObject *path) ...@@ -3206,14 +3206,14 @@ call_find_module(char *name, PyObject *path)
static PyObject * static PyObject *
imp_find_module(PyObject *self, PyObject *args) imp_find_module(PyObject *self, PyObject *args)
{ {
char *name; PyObject *name;
PyObject *ret, *path = NULL; PyObject *ret, *path = NULL;
if (!PyArg_ParseTuple(args, "es|O:find_module", if (!PyArg_ParseTuple(args, "O&|O:find_module",
Py_FileSystemDefaultEncoding, &name, PyUnicode_FSConverter, &name,
&path)) &path))
return NULL; return NULL;
ret = call_find_module(name, path); ret = call_find_module(PyBytes_AS_STRING(name), path);
PyMem_Free(name); Py_DECREF(name);
return ret; return ret;
} }
...@@ -3331,23 +3331,23 @@ static PyObject * ...@@ -3331,23 +3331,23 @@ static PyObject *
imp_load_compiled(PyObject *self, PyObject *args) imp_load_compiled(PyObject *self, PyObject *args)
{ {
char *name; char *name;
char *pathname; PyObject *pathname;
PyObject *fob = NULL; PyObject *fob = NULL;
PyObject *m; PyObject *m;
FILE *fp; FILE *fp;
if (!PyArg_ParseTuple(args, "ses|O:load_compiled", if (!PyArg_ParseTuple(args, "sO&|O:load_compiled",
&name, &name,
Py_FileSystemDefaultEncoding, &pathname, PyUnicode_FSConverter, &pathname,
&fob)) &fob))
return NULL; return NULL;
fp = get_file(pathname, fob, "rb"); fp = get_file(PyBytes_AS_STRING(pathname), fob, "rb");
if (fp == NULL) { if (fp == NULL) {
PyMem_Free(pathname); Py_DECREF(pathname);
return NULL; return NULL;
} }
m = load_compiled_module(name, pathname, fp); m = load_compiled_module(name, PyBytes_AS_STRING(pathname), fp);
fclose(fp); fclose(fp);
PyMem_Free(pathname); Py_DECREF(pathname);
return m; return m;
} }
...@@ -3386,22 +3386,22 @@ static PyObject * ...@@ -3386,22 +3386,22 @@ static PyObject *
imp_load_source(PyObject *self, PyObject *args) imp_load_source(PyObject *self, PyObject *args)
{ {
char *name; char *name;
char *pathname; PyObject *pathname;
PyObject *fob = NULL; PyObject *fob = NULL;
PyObject *m; PyObject *m;
FILE *fp; FILE *fp;
if (!PyArg_ParseTuple(args, "ses|O:load_source", if (!PyArg_ParseTuple(args, "sO&|O:load_source",
&name, &name,
Py_FileSystemDefaultEncoding, &pathname, PyUnicode_FSConverter, &pathname,
&fob)) &fob))
return NULL; return NULL;
fp = get_file(pathname, fob, "r"); fp = get_file(PyBytes_AS_STRING(pathname), fob, "r");
if (fp == NULL) { if (fp == NULL) {
PyMem_Free(pathname); Py_DECREF(pathname);
return NULL; return NULL;
} }
m = load_source_module(name, pathname, fp); m = load_source_module(name, PyBytes_AS_STRING(pathname), fp);
PyMem_Free(pathname); Py_DECREF(pathname);
fclose(fp); fclose(fp);
return m; return m;
} }
...@@ -3455,13 +3455,13 @@ static PyObject * ...@@ -3455,13 +3455,13 @@ static PyObject *
imp_load_package(PyObject *self, PyObject *args) imp_load_package(PyObject *self, PyObject *args)
{ {
char *name; char *name;
char *pathname; PyObject *pathname;
PyObject * ret; PyObject * ret;
if (!PyArg_ParseTuple(args, "ses:load_package", if (!PyArg_ParseTuple(args, "sO&:load_package",
&name, Py_FileSystemDefaultEncoding, &pathname)) &name, PyUnicode_FSConverter, &pathname))
return NULL; return NULL;
ret = load_package(name, pathname); ret = load_package(name, PyBytes_AS_STRING(pathname));
PyMem_Free(pathname); Py_DECREF(pathname);
return ret; return ret;
} }
...@@ -3534,21 +3534,23 @@ imp_source_from_cache(PyObject *self, PyObject *args, PyObject *kws) ...@@ -3534,21 +3534,23 @@ imp_source_from_cache(PyObject *self, PyObject *args, PyObject *kws)
{ {
static char *kwlist[] = {"path", NULL}; static char *kwlist[] = {"path", NULL};
PyObject *pathname_obj;
char *pathname; char *pathname;
char buf[MAXPATHLEN+1]; char buf[MAXPATHLEN+1];
if (!PyArg_ParseTupleAndKeywords( if (!PyArg_ParseTupleAndKeywords(
args, kws, "es", kwlist, args, kws, "O&", kwlist,
Py_FileSystemDefaultEncoding, &pathname)) PyUnicode_FSConverter, &pathname_obj))
return NULL; return NULL;
pathname = PyBytes_AS_STRING(pathname_obj);
if (make_source_pathname(pathname, buf) == NULL) { if (make_source_pathname(pathname, buf) == NULL) {
PyErr_Format(PyExc_ValueError, "Not a PEP 3147 pyc path: %s", PyErr_Format(PyExc_ValueError, "Not a PEP 3147 pyc path: %s",
pathname); pathname);
PyMem_Free(pathname); Py_DECREF(pathname_obj);
return NULL; return NULL;
} }
PyMem_Free(pathname); Py_DECREF(pathname_obj);
return PyUnicode_FromString(buf); return PyUnicode_FromString(buf);
} }
......
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