summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-12-03 17:06:43 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-12-03 17:06:43 (GMT)
commitebc0052e3a4f602212ed528ac490a9082ac811ce (patch)
tree1caa19104283ef90f0f51eab4c3a0e0690ba8e3e /Python
parentf961377e9959fd04a4351316386f15e019e89ebb (diff)
downloadcpython-ebc0052e3a4f602212ed528ac490a9082ac811ce.zip
cpython-ebc0052e3a4f602212ed528ac490a9082ac811ce.tar.gz
cpython-ebc0052e3a4f602212ed528ac490a9082ac811ce.tar.bz2
import: use PyUnicode_FSConverter to support bytes path and PEP 383
(instead of PyArg_Parse*() with "es" format and Py_FileSystemDefaultEncoding)
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/Python/import.c b/Python/import.c
index e582a27..ce7cbc2 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -3206,14 +3206,14 @@ call_find_module(char *name, PyObject *path)
static PyObject *
imp_find_module(PyObject *self, PyObject *args)
{
- char *name;
+ PyObject *name;
PyObject *ret, *path = NULL;
- if (!PyArg_ParseTuple(args, "es|O:find_module",
- Py_FileSystemDefaultEncoding, &name,
+ if (!PyArg_ParseTuple(args, "O&|O:find_module",
+ PyUnicode_FSConverter, &name,
&path))
return NULL;
- ret = call_find_module(name, path);
- PyMem_Free(name);
+ ret = call_find_module(PyBytes_AS_STRING(name), path);
+ Py_DECREF(name);
return ret;
}
@@ -3331,23 +3331,23 @@ static PyObject *
imp_load_compiled(PyObject *self, PyObject *args)
{
char *name;
- char *pathname;
+ PyObject *pathname;
PyObject *fob = NULL;
PyObject *m;
FILE *fp;
- if (!PyArg_ParseTuple(args, "ses|O:load_compiled",
+ if (!PyArg_ParseTuple(args, "sO&|O:load_compiled",
&name,
- Py_FileSystemDefaultEncoding, &pathname,
+ PyUnicode_FSConverter, &pathname,
&fob))
return NULL;
- fp = get_file(pathname, fob, "rb");
+ fp = get_file(PyBytes_AS_STRING(pathname), fob, "rb");
if (fp == NULL) {
- PyMem_Free(pathname);
+ Py_DECREF(pathname);
return NULL;
}
- m = load_compiled_module(name, pathname, fp);
+ m = load_compiled_module(name, PyBytes_AS_STRING(pathname), fp);
fclose(fp);
- PyMem_Free(pathname);
+ Py_DECREF(pathname);
return m;
}
@@ -3386,22 +3386,22 @@ static PyObject *
imp_load_source(PyObject *self, PyObject *args)
{
char *name;
- char *pathname;
+ PyObject *pathname;
PyObject *fob = NULL;
PyObject *m;
FILE *fp;
- if (!PyArg_ParseTuple(args, "ses|O:load_source",
+ if (!PyArg_ParseTuple(args, "sO&|O:load_source",
&name,
- Py_FileSystemDefaultEncoding, &pathname,
+ PyUnicode_FSConverter, &pathname,
&fob))
return NULL;
- fp = get_file(pathname, fob, "r");
+ fp = get_file(PyBytes_AS_STRING(pathname), fob, "r");
if (fp == NULL) {
- PyMem_Free(pathname);
+ Py_DECREF(pathname);
return NULL;
}
- m = load_source_module(name, pathname, fp);
- PyMem_Free(pathname);
+ m = load_source_module(name, PyBytes_AS_STRING(pathname), fp);
+ Py_DECREF(pathname);
fclose(fp);
return m;
}
@@ -3455,13 +3455,13 @@ static PyObject *
imp_load_package(PyObject *self, PyObject *args)
{
char *name;
- char *pathname;
+ PyObject *pathname;
PyObject * ret;
- if (!PyArg_ParseTuple(args, "ses:load_package",
- &name, Py_FileSystemDefaultEncoding, &pathname))
+ if (!PyArg_ParseTuple(args, "sO&:load_package",
+ &name, PyUnicode_FSConverter, &pathname))
return NULL;
- ret = load_package(name, pathname);
- PyMem_Free(pathname);
+ ret = load_package(name, PyBytes_AS_STRING(pathname));
+ Py_DECREF(pathname);
return ret;
}
@@ -3534,21 +3534,23 @@ imp_source_from_cache(PyObject *self, PyObject *args, PyObject *kws)
{
static char *kwlist[] = {"path", NULL};
+ PyObject *pathname_obj;
char *pathname;
char buf[MAXPATHLEN+1];
if (!PyArg_ParseTupleAndKeywords(
- args, kws, "es", kwlist,
- Py_FileSystemDefaultEncoding, &pathname))
+ args, kws, "O&", kwlist,
+ PyUnicode_FSConverter, &pathname_obj))
return NULL;
+ pathname = PyBytes_AS_STRING(pathname_obj);
if (make_source_pathname(pathname, buf) == NULL) {
PyErr_Format(PyExc_ValueError, "Not a PEP 3147 pyc path: %s",
pathname);
- PyMem_Free(pathname);
+ Py_DECREF(pathname_obj);
return NULL;
}
- PyMem_Free(pathname);
+ Py_DECREF(pathname_obj);
return PyUnicode_FromString(buf);
}