summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2013-11-22 16:05:39 (GMT)
committerEric Snow <ericsnowcurrently@gmail.com>2013-11-22 16:05:39 (GMT)
commitb523f8433a8982e10eb41a3e2b37ee0e6d6a6e00 (patch)
treeb38661db4903b7edc4042e7562b32720dd3687bf /Objects
parent9e6097ebe7bb99a4a22b949ef4b1563b21ad7166 (diff)
downloadcpython-b523f8433a8982e10eb41a3e2b37ee0e6d6a6e00.zip
cpython-b523f8433a8982e10eb41a3e2b37ee0e6d6a6e00.tar.gz
cpython-b523f8433a8982e10eb41a3e2b37ee0e6d6a6e00.tar.bz2
Implement PEP 451 (ModuleSpec).
Diffstat (limited to 'Objects')
-rw-r--r--Objects/moduleobject.c53
1 files changed, 5 insertions, 48 deletions
diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c
index 3ea3be8..d59475e 100644
--- a/Objects/moduleobject.c
+++ b/Objects/moduleobject.c
@@ -45,6 +45,8 @@ module_init_dict(PyModuleObject *mod, PyObject *md_dict,
return -1;
if (PyDict_SetItemString(md_dict, "__loader__", Py_None) != 0)
return -1;
+ if (PyDict_SetItemString(md_dict, "__spec__", Py_None) != 0)
+ return -1;
if (PyUnicode_CheckExact(name)) {
Py_INCREF(name);
Py_XDECREF(mod->md_name);
@@ -398,55 +400,10 @@ module_dealloc(PyModuleObject *m)
static PyObject *
module_repr(PyModuleObject *m)
{
- PyObject *name, *filename, *repr, *loader = NULL;
+ PyThreadState *tstate = PyThreadState_GET();
+ PyInterpreterState *interp = tstate->interp;
- /* See if the module has an __loader__. If it does, give the loader the
- * first shot at producing a repr for the module.
- */
- if (m->md_dict != NULL) {
- loader = PyDict_GetItemString(m->md_dict, "__loader__");
- }
- if (loader != NULL && loader != Py_None) {
- repr = PyObject_CallMethod(loader, "module_repr", "(O)",
- (PyObject *)m, NULL);
- if (repr == NULL) {
- PyErr_Clear();
- }
- else {
- return repr;
- }
- }
- /* __loader__.module_repr(m) did not provide us with a repr. Next, see if
- * the module has an __file__. If it doesn't then use repr(__loader__) if
- * it exists, otherwise, just use module.__name__.
- */
- name = PyModule_GetNameObject((PyObject *)m);
- if (name == NULL) {
- PyErr_Clear();
- name = PyUnicode_FromStringAndSize("?", 1);
- if (name == NULL)
- return NULL;
- }
- filename = PyModule_GetFilenameObject((PyObject *)m);
- if (filename == NULL) {
- PyErr_Clear();
- /* There's no m.__file__, so if there was a __loader__, use that in
- * the repr, otherwise, the only thing you can use is m.__name__
- */
- if (loader == NULL || loader == Py_None) {
- repr = PyUnicode_FromFormat("<module %R>", name);
- }
- else {
- repr = PyUnicode_FromFormat("<module %R (%R)>", name, loader);
- }
- }
- /* Finally, use m.__file__ */
- else {
- repr = PyUnicode_FromFormat("<module %R from %R>", name, filename);
- Py_DECREF(filename);
- }
- Py_DECREF(name);
- return repr;
+ return PyObject_CallMethod(interp->importlib, "_module_repr", "O", m);
}
static int