summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-07 00:50:12 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-07 00:50:12 (GMT)
commit8124feb07b130bb39d13f2f3cb6457b185694e41 (patch)
treec99db0b72f9569d15cb78b41541b7b7d20938c57 /Objects
parente3c7381c39f02a29538ba0dc2f5731aee73ceb1a (diff)
downloadcpython-8124feb07b130bb39d13f2f3cb6457b185694e41.zip
cpython-8124feb07b130bb39d13f2f3cb6457b185694e41.tar.gz
cpython-8124feb07b130bb39d13f2f3cb6457b185694e41.tar.bz2
module_repr(): use %U to format the file name
Avoid useless encode/decode of the filename
Diffstat (limited to 'Objects')
-rw-r--r--Objects/moduleobject.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index c1dd228..feac861 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -191,8 +191,8 @@ PyModule_GetName(PyObject *m)
return _PyUnicode_AsString(nameobj);
}
-const char *
-PyModule_GetFilename(PyObject *m)
+static PyObject*
+module_getfilename(PyObject *m)
{
PyObject *d;
PyObject *fileobj;
@@ -208,6 +208,16 @@ PyModule_GetFilename(PyObject *m)
PyErr_SetString(PyExc_SystemError, "module filename missing");
return NULL;
}
+ return fileobj;
+}
+
+const char *
+PyModule_GetFilename(PyObject *m)
+{
+ PyObject *fileobj;
+ fileobj = module_getfilename(m);
+ if (fileobj == NULL)
+ return NULL;
return _PyUnicode_AsString(fileobj);
}
@@ -327,19 +337,19 @@ static PyObject *
module_repr(PyModuleObject *m)
{
const char *name;
- const char *filename;
+ PyObject *filename;
name = PyModule_GetName((PyObject *)m);
if (name == NULL) {
PyErr_Clear();
name = "?";
}
- filename = PyModule_GetFilename((PyObject *)m);
+ filename = module_getfilename((PyObject *)m);
if (filename == NULL) {
PyErr_Clear();
return PyUnicode_FromFormat("<module '%s' (built-in)>", name);
}
- return PyUnicode_FromFormat("<module '%s' from '%s'>", name, filename);
+ return PyUnicode_FromFormat("<module '%s' from '%U'>", name, filename);
}
static int