summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-02-15 14:47:16 (GMT)
committerGuido van Rossum <guido@python.org>1999-02-15 14:47:16 (GMT)
commit98cc19fac6489002774760fda470a4c296a88042 (patch)
tree3ca8c94d6570323c5db8ea558038ccfab7b8f223 /Objects
parente784f1efece5df6c270bf6019ea8338a690c1795 (diff)
downloadcpython-98cc19fac6489002774760fda470a4c296a88042.zip
cpython-98cc19fac6489002774760fda470a4c296a88042.tar.gz
cpython-98cc19fac6489002774760fda470a4c296a88042.tar.bz2
Patch by Chris Petrilli to display the origin of a module in its
repr() -- either "(builtin)" or "from '<filename>'".
Diffstat (limited to 'Objects')
-rw-r--r--Objects/moduleobject.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index a7f36d4..7dfca73 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -93,6 +93,24 @@ PyModule_GetName(m)
return PyString_AsString(nameobj);
}
+char *
+PyModule_GetFilename(m)
+ PyObject *m;
+{
+ PyObject *fileobj;
+ if (!PyModule_Check(m)) {
+ PyErr_BadArgument();
+ return NULL;
+ }
+ fileobj = PyDict_GetItemString(((PyModuleObject *)m)->md_dict,
+ "__file__");
+ if (fileobj == NULL || !PyString_Check(fileobj)) {
+ PyErr_SetString(PyExc_SystemError, "module filename missing");
+ return NULL;
+ }
+ return PyString_AsString(fileobj);
+}
+
void
_PyModule_Clear(m)
PyObject *m;
@@ -159,13 +177,22 @@ static PyObject *
module_repr(m)
PyModuleObject *m;
{
- char buf[100];
- char *name = PyModule_GetName((PyObject *)m);
+ char buf[400];
+ char *name;
+ char *filename;
+ name = PyModule_GetName((PyObject *)m);
if (name == NULL) {
PyErr_Clear();
name = "?";
}
- sprintf(buf, "<module '%.80s'>", name);
+ filename = PyModule_GetFilename((PyObject *)m);
+ if (filename == NULL) {
+ PyErr_Clear();
+ sprintf(buf, "<module '%.80s' (built-in)>", name);
+ } else {
+ sprintf(buf, "<module '%.80s' from '%.255s'>", name, filename);
+ }
+
return PyString_FromString(buf);
}