(original) (raw)
changeset: 83607:e39a8f8ceb9f user: Brett Cannon brett@python.org date: Sat May 04 13:56:58 2013 -0400 files: Doc/c-api/module.rst Doc/library/importlib.rst Doc/reference/import.rst Doc/whatsnew/3.4.rst Lib/ctypes/test/__init__.py Lib/doctest.py Lib/importlib/_bootstrap.py Lib/inspect.py Lib/test/test_descr.py Lib/test/test_importlib/test_api.py Lib/test/test_module.py Misc/NEWS Objects/moduleobject.c Python/importlib.h Python/pythonrun.c description: #17115,17116: Have modules initialize the __package__ and __loader__ attributes to None. The long-term goal is for people to be able to rely on these attributes existing and checking for None to see if they have been set. Since import itself sets these attributes when a loader does not the only instances when the attributes are None are from someone overloading __import__() and not using a loader or someone creating a module from scratch. This patch also unifies module initialization. Before you could have different attributes with default values depending on how the module object was created. Now the only way to not get the same default set of attributes is to circumvent initialization by calling ModuleType.__new__() directly. diff -r d4912244cce6 -r e39a8f8ceb9f Doc/c-api/module.rst --- a/Doc/c-api/module.rst Sat May 04 18:07:12 2013 +0300 +++ b/Doc/c-api/module.rst Sat May 04 13:56:58 2013 -0400 @@ -35,13 +35,20 @@ single: __name__ (module attribute) single: __doc__ (module attribute) single: __file__ (module attribute) + single: __package__ (module attribute) + single: __loader__ (module attribute) Return a new module object with the :attr:`__name__` attribute set to *name*. - Only the module's :attr:`__doc__` and :attr:`__name__` attributes are filled in; - the caller is responsible for providing a :attr:`__file__` attribute. + The module's :attr:`__name__`, :attr:`__doc__`, :attr:`__package__`, and + :attr:`__loader__` attributes are filled in (all but :attr:`__name__` are set + to ``None``); the caller is responsible for providing a :attr:`__file__` + attribute. .. versionadded:: 3.3 + .. versionchanged:: 3.4 + :attr:`__package__` and :attr:`__loader__` are set to ``None``. + .. c:function:: PyObject* PyModule_New(const char *name) diff -r d4912244cce6 -r e39a8f8ceb9f Doc/library/importlib.rst --- a/Doc/library/importlib.rst Sat May 04 18:07:12 2013 +0300 +++ b/Doc/library/importlib.rst Sat May 04 13:56:58 2013 -0400 @@ -827,7 +827,7 @@ decorator as it subsumes this functionality. .. versionchanged:: 3.4 - Set ``__loader__`` if set to ``None`` as well if the attribute does not + Set ``__loader__`` if set to ``None``, as if the attribute does not exist. diff -r d4912244cce6 -r e39a8f8ceb9f Doc/reference/import.rst --- a/Doc/reference/import.rst Sat May 04 18:07:12 2013 +0300 +++ b/Doc/reference/import.rst Sat May 04 13:56:58 2013 -0400 @@ -423,8 +423,8 @@ * If the module has a ``__file__`` attribute, this is used as part of the module's repr. - * If the module has no ``__file__`` but does have a ``__loader__``, then the - loader's repr is used as part of the module's repr. + * If the module has no ``__file__`` but does have a ``__loader__`` that is not + ``None``, then the loader's repr is used as part of the module's repr. * Otherwise, just use the module's ``__name__`` in the repr. diff -r d4912244cce6 -r e39a8f8ceb9f Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst Sat May 04 18:07:12 2013 +0300 +++ b/Doc/whatsnew/3.4.rst Sat May 04 13:56:58 2013 -0400 @@ -231,3 +231,8 @@ :exc:`NotImplementedError` blindly. This will only affect code calling :func:`super` and falling through all the way to the ABCs. For compatibility, catch both :exc:`NotImplementedError` or the appropriate exception as needed. + +* The module type now initializes the :attr:`__package__` and :attr:`__loader__` + attributes to ``None`` by default. To determine if these attributes were set + in a backwards-compatible fashion, use e.g. + ``getattr(module, '__loader__', None) is not None``. \ No newline at end of file diff -r d4912244cce6 -r e39a8f8ceb9f Lib/ctypes/test/__init__.py --- a/Lib/ctypes/test/__init__.py Sat May 04 18:07:12 2013 +0300 +++ b/Lib/ctypes/test/__init__.py Sat May 04 13:56:58 2013 -0400 @@ -37,7 +37,7 @@ def find_package_modules(package, mask): import fnmatch - if (hasattr(package, "__loader__") and + if (package.__loader__ is not None and hasattr(package.__loader__, '_files')): path = package.__name__.replace(".", os.path.sep) mask = os.path.join(path, mask) diff -r d4912244cce6 -r e39a8f8ceb9f Lib/doctest.py --- a/Lib/doctest.py Sat May 04 18:07:12 2013 +0300 +++ b/Lib/doctest.py Sat May 04 13:56:58 2013 -0400 @@ -215,7 +215,7 @@ if module_relative: package = _normalize_module(package, 3) filename = _module_relative_path(package, filename) - if hasattr(package, '__loader__'): + if getattr(package, '__loader__', None) is not None: if hasattr(package.__loader__, 'get_data'): file_contents = package.__loader__.get_data(filename) file_contents = file_contents.decode(encoding) diff -r d4912244cce6 -r e39a8f8ceb9f Lib/importlib/_bootstrap.py --- a/Lib/importlib/_bootstrap.py Sat May 04 18:07:12 2013 +0300 +++ b/Lib/importlib/_bootstrap.py Sat May 04 13:56:58 2013 -0400 @@ -1726,7 +1726,7 @@ module_type = type(sys) for name, module in sys.modules.items(): if isinstance(module, module_type): - if not hasattr(module, '__loader__'): + if getattr(module, '__loader__', None) is None: if name in sys.builtin_module_names: module.__loader__ = BuiltinImporter elif _imp.is_frozen(name): diff -r d4912244cce6 -r e39a8f8ceb9f Lib/inspect.py --- a/Lib/inspect.py Sat May 04 18:07:12 2013 +0300 +++ b/Lib/inspect.py Sat May 04 13:56:58 2013 -0400 @@ -476,7 +476,7 @@ if os.path.exists(filename): return filename # only return a non-existent filename if the module has a PEP 302 loader - if hasattr(getmodule(object, filename), '__loader__'): + if getattr(getmodule(object, filename), '__loader__', None) is not None: return filename # or it is in the linecache if filename in linecache.cache: diff -r d4912244cce6 -r e39a8f8ceb9f Lib/test/test_descr.py --- a/Lib/test/test_descr.py Sat May 04 18:07:12 2013 +0300 +++ b/Lib/test/test_descr.py Sat May 04 13:56:58 2013 -0400 @@ -2250,7 +2250,9 @@ minstance = M("m") minstance.b = 2 minstance.a = 1 - names = [x for x in dir(minstance) if x not in ["__name__", "__doc__"]] + default_attributes = ['__name__', '__doc__', '__package__', + '__loader__'] + names = [x for x in dir(minstance) if x not in default_attributes] self.assertEqual(names, ['a', 'b']) class M2(M): diff -r d4912244cce6 -r e39a8f8ceb9f Lib/test/test_importlib/test_api.py --- a/Lib/test/test_importlib/test_api.py Sat May 04 18:07:12 2013 +0300 +++ b/Lib/test/test_importlib/test_api.py Sat May 04 13:56:58 2013 -0400 @@ -197,14 +197,12 @@ # Issue #17098: all modules should have __loader__ defined. for name, module in sys.modules.items(): if isinstance(module, types.ModuleType): - if name in sys.builtin_module_names: - self.assertIn(module.__loader__, - (importlib.machinery.BuiltinImporter, - importlib._bootstrap.BuiltinImporter)) - elif imp.is_frozen(name): - self.assertIn(module.__loader__, - (importlib.machinery.FrozenImporter, - importlib._bootstrap.FrozenImporter)) + self.assertTrue(hasattr(module, '__loader__'), + '{!r} lacks a __loader__ attribute'.format(name)) + if importlib.machinery.BuiltinImporter.find_module(name): + self.assertIsNot(module.__loader__, None) + elif importlib.machinery.FrozenImporter.find_module(name): + self.assertIsNot(module.__loader__, None) if __name__ == '__main__': diff -r d4912244cce6 -r e39a8f8ceb9f Lib/test/test_module.py --- a/Lib/test/test_module.py Sat May 04 18:07:12 2013 +0300 +++ b/Lib/test/test_module.py Sat May 04 13:56:58 2013 -0400 @@ -33,7 +33,10 @@ foo = ModuleType("foo") self.assertEqual(foo.__name__, "foo") self.assertEqual(foo.__doc__, None) - self.assertEqual(foo.__dict__, {"__name__": "foo", "__doc__": None}) + self.assertIs(foo.__loader__, None) + self.assertIs(foo.__package__, None) + self.assertEqual(foo.__dict__, {"__name__": "foo", "__doc__": None, + "__loader__": None, "__package__": None}) def test_ascii_docstring(self): # ASCII docstring @@ -41,7 +44,8 @@ self.assertEqual(foo.__name__, "foo") self.assertEqual(foo.__doc__, "foodoc") self.assertEqual(foo.__dict__, - {"__name__": "foo", "__doc__": "foodoc"}) + {"__name__": "foo", "__doc__": "foodoc", + "__loader__": None, "__package__": None}) def test_unicode_docstring(self): # Unicode docstring @@ -49,7 +53,8 @@ self.assertEqual(foo.__name__, "foo") self.assertEqual(foo.__doc__, "foodoc\u1234") self.assertEqual(foo.__dict__, - {"__name__": "foo", "__doc__": "foodoc\u1234"}) + {"__name__": "foo", "__doc__": "foodoc\u1234", + "__loader__": None, "__package__": None}) def test_reinit(self): # Reinitialization should not replace the __dict__ @@ -61,7 +66,8 @@ self.assertEqual(foo.__doc__, "foodoc") self.assertEqual(foo.bar, 42) self.assertEqual(foo.__dict__, - {"__name__": "foo", "__doc__": "foodoc", "bar": 42}) + {"__name__": "foo", "__doc__": "foodoc", "bar": 42, + "__loader__": None, "__package__": None}) self.assertTrue(foo.__dict__ is d) @unittest.expectedFailure @@ -110,13 +116,19 @@ m.__file__ = '/tmp/foo.py' self.assertEqual(repr(m), "") + def test_module_repr_with_loader_as_None(self): + m = ModuleType('foo') + assert m.__loader__ is None + self.assertEqual(repr(m), "") + def test_module_repr_with_bare_loader_but_no_name(self): m = ModuleType('foo') del m.__name__ # Yes, a class not an instance. m.__loader__ = BareLoader + loader_repr = repr(BareLoader) self.assertEqual( - repr(m), ")>") + repr(m), "".format(loader_repr)) def test_module_repr_with_full_loader_but_no_name(self): # m.__loader__.module_repr() will fail because the module has no @@ -126,15 +138,17 @@ del m.__name__ # Yes, a class not an instance. m.__loader__ = FullLoader + loader_repr = repr(FullLoader) self.assertEqual( - repr(m), ")>") + repr(m), "".format(loader_repr)) def test_module_repr_with_bare_loader(self): m = ModuleType('foo') # Yes, a class not an instance. m.__loader__ = BareLoader + module_repr = repr(BareLoader) self.assertEqual( - repr(m), ")>") + repr(m), "".format(module_repr)) def test_module_repr_with_full_loader(self): m = ModuleType('foo') diff -r d4912244cce6 -r e39a8f8ceb9f Misc/NEWS --- a/Misc/NEWS Sat May 04 18:07:12 2013 +0300 +++ b/Misc/NEWS Sat May 04 13:56:58 2013 -0400 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #17115,17116: Module initialization now includes setting __package__ and + __loader__ attributes to None. + - Issue #17853: Ensure locals of a class that shadow free variables always win over the closures. diff -r d4912244cce6 -r e39a8f8ceb9f Objects/moduleobject.c --- a/Objects/moduleobject.c Sat May 04 18:07:12 2013 +0300 +++ b/Objects/moduleobject.c Sat May 04 13:56:58 2013 -0400 @@ -26,6 +26,27 @@ }; +static int +module_init_dict(PyObject *md_dict, PyObject *name, PyObject *doc) +{ + if (md_dict == NULL) + return -1; + if (doc == NULL) + doc = Py_None; + + if (PyDict_SetItemString(md_dict, "__name__", name) != 0) + return -1; + if (PyDict_SetItemString(md_dict, "__doc__", doc) != 0) + return -1; + if (PyDict_SetItemString(md_dict, "__package__", Py_None) != 0) + return -1; + if (PyDict_SetItemString(md_dict, "__loader__", Py_None) != 0) + return -1; + + return 0; +} + + PyObject * PyModule_NewObject(PyObject *name) { @@ -36,13 +57,7 @@ m->md_def = NULL; m->md_state = NULL; m->md_dict = PyDict_New(); - if (m->md_dict == NULL) - goto fail; - if (PyDict_SetItemString(m->md_dict, "__name__", name) != 0) - goto fail; - if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0) - goto fail; - if (PyDict_SetItemString(m->md_dict, "__package__", Py_None) != 0) + if (module_init_dict(m->md_dict, name, NULL) != 0) goto fail; PyObject_GC_Track(m); return (PyObject *)m; @@ -347,9 +362,7 @@ return -1; m->md_dict = dict; } - if (PyDict_SetItemString(dict, "__name__", name) < 0) - return -1; - if (PyDict_SetItemString(dict, "__doc__", doc) < 0) + if (module_init_dict(dict, name, doc) < 0) return -1; return 0; } @@ -380,7 +393,7 @@ if (m->md_dict != NULL) { loader = PyDict_GetItemString(m->md_dict, "__loader__"); } - if (loader != NULL) { + if (loader != NULL && loader != Py_None) { repr = PyObject_CallMethod(loader, "module_repr", "(O)", (PyObject *)m, NULL); if (repr == NULL) { @@ -404,10 +417,10 @@ filename = PyModule_GetFilenameObject((PyObject *)m); if (filename == NULL) { PyErr_Clear(); - /* There's no m.__file__, so if there was an __loader__, use that in + /* 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) { + if (loader == NULL || loader == Py_None) { repr = PyUnicode_FromFormat("", name); } else { diff -r d4912244cce6 -r e39a8f8ceb9f Python/importlib.h --- a/Python/importlib.h Sat May 04 18:07:12 2013 +0300 +++ b/Python/importlib.h Sat May 04 13:56:58 2013 -0400 @@ -3354,189 +3354,190 @@ 115,26,0,0,0,0,11,12,1,15,2,24,1,12,1,18, 1,6,3,12,1,23,1,6,1,4,4,35,3,40,2,114, 77,1,0,0,99,2,0,0,0,0,0,0,0,16,0,0, - 0,13,0,0,0,67,0,0,0,115,228,2,0,0,124,1, + 0,13,0,0,0,67,0,0,0,115,237,2,0,0,124,1, 0,97,0,0,124,0,0,97,1,0,116,1,0,106,2,0, 106,3,0,114,33,0,116,4,0,97,5,0,110,6,0,116, 6,0,97,5,0,116,7,0,116,1,0,131,1,0,125,2, - 0,120,119,0,116,1,0,106,8,0,106,9,0,131,0,0, - 68,93,102,0,92,2,0,125,3,0,125,4,0,116,10,0, + 0,120,128,0,116,1,0,106,8,0,106,9,0,131,0,0, + 68,93,111,0,92,2,0,125,3,0,125,4,0,116,10,0, 124,4,0,124,2,0,131,2,0,114,67,0,116,11,0,124, - 4,0,100,1,0,131,2,0,115,169,0,124,3,0,116,1, - 0,106,12,0,107,6,0,114,136,0,116,13,0,124,4,0, - 95,14,0,113,166,0,116,0,0,106,15,0,124,3,0,131, - 1,0,114,166,0,116,16,0,124,4,0,95,14,0,113,166, - 0,113,169,0,113,67,0,113,67,0,87,116,1,0,106,8, - 0,116,17,0,25,125,5,0,120,76,0,100,27,0,68,93, - 68,0,125,6,0,124,6,0,116,1,0,106,8,0,107,7, - 0,114,232,0,116,13,0,106,18,0,124,6,0,131,1,0, - 125,7,0,110,13,0,116,1,0,106,8,0,124,6,0,25, - 125,7,0,116,19,0,124,5,0,124,6,0,124,7,0,131, - 3,0,1,113,193,0,87,100,6,0,100,7,0,103,1,0, - 102,2,0,100,8,0,100,9,0,100,7,0,103,2,0,102, - 2,0,102,2,0,125,8,0,120,149,0,124,8,0,68,93, - 129,0,92,2,0,125,9,0,125,10,0,116,20,0,100,10, - 0,100,11,0,132,0,0,124,10,0,68,131,1,0,131,1, - 0,115,92,1,116,21,0,130,1,0,124,10,0,100,12,0, - 25,125,11,0,124,9,0,116,1,0,106,8,0,107,6,0, - 114,134,1,116,1,0,106,8,0,124,9,0,25,125,12,0, - 80,113,49,1,121,20,0,116,13,0,106,18,0,124,9,0, - 131,1,0,125,12,0,80,87,113,49,1,4,116,22,0,107, - 10,0,114,177,1,1,1,1,119,49,1,89,113,49,1,88, - 113,49,1,87,116,22,0,100,13,0,131,1,0,130,1,0, - 121,19,0,116,13,0,106,18,0,100,14,0,131,1,0,125, - 13,0,87,110,24,0,4,116,22,0,107,10,0,114,239,1, - 1,1,1,100,15,0,125,13,0,89,110,1,0,88,116,13, - 0,106,18,0,100,16,0,131,1,0,125,14,0,124,9,0, - 100,8,0,107,2,0,114,45,2,116,13,0,106,18,0,100, - 17,0,131,1,0,125,15,0,116,19,0,124,5,0,100,18, - 0,124,15,0,131,3,0,1,110,0,0,116,19,0,124,5, - 0,100,19,0,124,12,0,131,3,0,1,116,19,0,124,5, - 0,100,14,0,124,13,0,131,3,0,1,116,19,0,124,5, - 0,100,16,0,124,14,0,131,3,0,1,116,19,0,124,5, - 0,100,20,0,124,11,0,131,3,0,1,116,19,0,124,5, - 0,100,21,0,100,22,0,106,23,0,124,10,0,131,1,0, - 131,3,0,1,116,19,0,124,5,0,100,23,0,116,24,0, - 131,0,0,131,3,0,1,116,25,0,106,26,0,116,0,0, - 106,27,0,131,0,0,131,1,0,1,124,9,0,100,8,0, - 107,2,0,114,224,2,116,28,0,106,29,0,100,24,0,131, - 1,0,1,100,25,0,116,25,0,107,6,0,114,224,2,100, - 26,0,116,30,0,95,31,0,113,224,2,110,0,0,100,15, - 0,83,40,28,0,0,0,117,250,0,0,0,83,101,116,117, - 112,32,105,109,112,111,114,116,108,105,98,32,98,121,32,105, - 109,112,111,114,116,105,110,103,32,110,101,101,100,101,100,32, - 98,117,105,108,116,45,105,110,32,109,111,100,117,108,101,115, - 32,97,110,100,32,105,110,106,101,99,116,105,110,103,32,116, - 104,101,109,10,32,32,32,32,105,110,116,111,32,116,104,101, - 32,103,108,111,98,97,108,32,110,97,109,101,115,112,97,99, - 101,46,10,10,32,32,32,32,65,115,32,115,121,115,32,105, - 115,32,110,101,101,100,101,100,32,102,111,114,32,115,121,115, - 46,109,111,100,117,108,101,115,32,97,99,99,101,115,115,32, - 97,110,100,32,95,105,109,112,32,105,115,32,110,101,101,100, - 101,100,32,116,111,32,108,111,97,100,32,98,117,105,108,116, - 45,105,110,10,32,32,32,32,109,111,100,117,108,101,115,44, - 32,116,104,111,115,101,32,116,119,111,32,109,111,100,117,108, - 101,115,32,109,117,115,116,32,98,101,32,101,120,112,108,105, - 99,105,116,108,121,32,112,97,115,115,101,100,32,105,110,46, - 10,10,32,32,32,32,114,149,0,0,0,114,48,0,0,0, - 114,170,0,0,0,244,8,0,0,0,98,117,105,108,116,105, - 110,115,114,186,0,0,0,116,5,0,0,0,112,111,115,105, - 120,245,1,0,0,0,47,244,2,0,0,0,110,116,245,1, - 0,0,0,92,99,1,0,0,0,0,0,0,0,2,0,0, - 0,3,0,0,0,115,0,0,0,115,33,0,0,0,124,0, - 0,93,23,0,125,1,0,116,0,0,124,1,0,131,1,0, - 100,0,0,107,2,0,86,1,113,3,0,100,1,0,83,40, - 2,0,0,0,114,29,0,0,0,78,40,1,0,0,0,114, - 31,0,0,0,40,2,0,0,0,114,22,0,0,0,114,118, - 0,0,0,114,4,0,0,0,114,4,0,0,0,114,5,0, - 0,0,114,2,1,0,0,210,6,0,0,115,2,0,0,0, - 6,0,117,25,0,0,0,95,115,101,116,117,112,46,60,108, - 111,99,97,108,115,62,46,60,103,101,110,101,120,112,114,62, - 114,71,0,0,0,117,30,0,0,0,105,109,112,111,114,116, - 108,105,98,32,114,101,113,117,105,114,101,115,32,112,111,115, - 105,120,32,111,114,32,110,116,114,72,0,0,0,78,114,95, - 0,0,0,116,6,0,0,0,119,105,110,114,101,103,114,206, - 0,0,0,114,3,0,0,0,114,25,0,0,0,114,21,0, - 0,0,114,30,0,0,0,114,6,0,0,0,117,4,0,0, - 0,46,112,121,119,117,6,0,0,0,95,100,46,112,121,100, - 84,40,4,0,0,0,117,3,0,0,0,95,105,111,117,9, - 0,0,0,95,119,97,114,110,105,110,103,115,117,8,0,0, - 0,98,117,105,108,116,105,110,115,117,7,0,0,0,109,97, - 114,115,104,97,108,40,32,0,0,0,114,97,0,0,0,114, - 7,0,0,0,114,105,0,0,0,114,106,0,0,0,114,108, - 0,0,0,114,75,1,0,0,114,107,0,0,0,114,65,0, - 0,0,114,152,0,0,0,244,5,0,0,0,105,116,101,109, - 115,114,187,0,0,0,114,59,0,0,0,114,163,0,0,0, - 114,194,0,0,0,114,149,0,0,0,114,166,0,0,0,114, - 202,0,0,0,114,56,0,0,0,114,198,0,0,0,114,60, - 0,0,0,244,3,0,0,0,97,108,108,114,89,0,0,0, - 114,154,0,0,0,114,26,0,0,0,114,11,0,0,0,114, - 4,1,0,0,114,192,0,0,0,114,74,1,0,0,114,122, - 0,0,0,114,251,0,0,0,114,205,0,0,0,114,209,0, - 0,0,40,16,0,0,0,244,10,0,0,0,115,121,115,95, - 109,111,100,117,108,101,244,11,0,0,0,95,105,109,112,95, - 109,111,100,117,108,101,116,11,0,0,0,109,111,100,117,108, - 101,95,116,121,112,101,114,66,0,0,0,114,145,0,0,0, - 116,11,0,0,0,115,101,108,102,95,109,111,100,117,108,101, - 116,12,0,0,0,98,117,105,108,116,105,110,95,110,97,109, - 101,116,14,0,0,0,98,117,105,108,116,105,110,95,109,111, - 100,117,108,101,116,10,0,0,0,111,115,95,100,101,116,97, - 105,108,115,116,10,0,0,0,98,117,105,108,116,105,110,95, - 111,115,114,21,0,0,0,114,25,0,0,0,116,9,0,0, - 0,111,115,95,109,111,100,117,108,101,116,13,0,0,0,116, - 104,114,101,97,100,95,109,111,100,117,108,101,116,14,0,0, - 0,119,101,97,107,114,101,102,95,109,111,100,117,108,101,116, - 13,0,0,0,119,105,110,114,101,103,95,109,111,100,117,108, - 101,114,4,0,0,0,114,4,0,0,0,114,5,0,0,0, - 244,6,0,0,0,95,115,101,116,117,112,173,6,0,0,115, - 102,0,0,0,0,9,6,1,6,2,12,1,9,2,6,2, - 12,1,28,1,15,1,15,1,15,1,12,1,15,1,22,2, - 13,1,13,1,15,1,18,2,13,1,20,2,33,1,19,2, - 31,1,10,1,15,1,13,1,4,2,3,1,15,1,5,1, - 13,1,12,2,12,2,3,1,19,1,13,2,11,1,15,2, - 12,1,15,1,19,2,16,1,16,1,16,1,16,1,25,2, - 19,1,19,1,12,1,13,1,12,1,114,86,1,0,0,99, - 2,0,0,0,0,0,0,0,3,0,0,0,3,0,0,0, - 67,0,0,0,115,136,0,0,0,116,0,0,124,0,0,124, - 1,0,131,2,0,1,116,1,0,131,0,0,125,2,0,116, - 2,0,106,3,0,106,4,0,116,5,0,106,6,0,124,2, - 0,140,0,0,103,1,0,131,1,0,1,116,2,0,106,7, - 0,106,8,0,116,9,0,131,1,0,1,116,2,0,106,7, - 0,106,8,0,116,10,0,131,1,0,1,116,11,0,106,12, - 0,100,1,0,107,2,0,114,116,0,116,2,0,106,7,0, - 106,8,0,116,13,0,131,1,0,1,110,0,0,116,2,0, - 106,7,0,106,8,0,116,14,0,131,1,0,1,100,2,0, - 83,40,3,0,0,0,117,50,0,0,0,73,110,115,116,97, - 108,108,32,105,109,112,111,114,116,108,105,98,32,97,115,32, - 116,104,101,32,105,109,112,108,101,109,101,110,116,97,116,105, - 111,110,32,111,102,32,105,109,112,111,114,116,46,114,80,1, - 0,0,78,40,15,0,0,0,114,86,1,0,0,114,215,0, - 0,0,114,7,0,0,0,114,26,1,0,0,114,192,0,0, - 0,114,33,1,0,0,114,47,1,0,0,114,55,1,0,0, - 114,251,0,0,0,114,194,0,0,0,114,202,0,0,0,114, - 3,0,0,0,114,56,0,0,0,114,205,0,0,0,114,21, - 1,0,0,40,3,0,0,0,114,84,1,0,0,114,85,1, - 0,0,116,17,0,0,0,115,117,112,112,111,114,116,101,100, - 95,108,111,97,100,101,114,115,114,4,0,0,0,114,4,0, - 0,0,114,5,0,0,0,244,8,0,0,0,95,105,110,115, - 116,97,108,108,249,6,0,0,115,16,0,0,0,0,2,13, - 1,9,1,28,1,16,1,16,1,15,1,19,1,114,87,1, - 0,0,40,3,0,0,0,117,3,0,0,0,119,105,110,114, - 1,0,0,0,114,2,0,0,0,40,77,0,0,0,114,58, - 0,0,0,114,10,0,0,0,114,11,0,0,0,114,17,0, - 0,0,114,19,0,0,0,114,28,0,0,0,114,38,0,0, - 0,114,43,0,0,0,114,44,0,0,0,114,45,0,0,0, - 114,54,0,0,0,114,64,0,0,0,114,65,0,0,0,244, - 8,0,0,0,95,95,99,111,100,101,95,95,114,188,0,0, - 0,114,67,0,0,0,114,92,0,0,0,114,81,0,0,0, - 114,88,0,0,0,114,68,0,0,0,114,70,0,0,0,114, - 91,0,0,0,114,96,0,0,0,114,99,0,0,0,114,102, - 0,0,0,114,15,0,0,0,114,181,0,0,0,114,14,0, - 0,0,114,18,0,0,0,116,17,0,0,0,95,82,65,87, - 95,77,65,71,73,67,95,78,85,77,66,69,82,114,113,0, - 0,0,114,122,0,0,0,114,107,0,0,0,114,108,0,0, - 0,114,120,0,0,0,114,123,0,0,0,114,131,0,0,0, - 114,133,0,0,0,114,141,0,0,0,114,148,0,0,0,114, - 151,0,0,0,114,159,0,0,0,114,162,0,0,0,114,165, - 0,0,0,114,168,0,0,0,114,176,0,0,0,114,185,0, - 0,0,114,190,0,0,0,114,193,0,0,0,114,194,0,0, - 0,114,202,0,0,0,114,205,0,0,0,114,218,0,0,0, - 114,224,0,0,0,114,244,0,0,0,114,248,0,0,0,114, - 254,0,0,0,114,4,1,0,0,114,255,0,0,0,114,5, - 1,0,0,114,20,1,0,0,114,21,1,0,0,114,33,1, - 0,0,114,48,1,0,0,114,54,1,0,0,114,56,1,0, - 0,114,59,1,0,0,114,60,1,0,0,114,63,1,0,0, - 114,64,1,0,0,114,65,1,0,0,114,71,1,0,0,114, - 73,1,0,0,114,215,0,0,0,114,77,1,0,0,114,86, - 1,0,0,114,87,1,0,0,114,4,0,0,0,114,4,0, - 0,0,114,4,0,0,0,114,5,0,0,0,244,8,0,0, - 0,60,109,111,100,117,108,101,62,8,0,0,0,115,140,0, - 0,0,6,21,6,3,12,13,12,10,12,9,12,6,12,12, - 12,10,12,6,12,7,15,22,12,8,15,3,12,12,6,2, - 6,3,22,4,19,68,19,23,12,19,12,20,12,109,22,1, - 18,2,6,2,9,2,9,1,9,2,15,27,12,23,12,21, - 12,12,18,8,12,13,12,11,12,55,12,18,12,11,12,11, - 12,13,21,55,21,12,18,12,19,57,19,54,19,50,19,34, - 22,132,19,29,25,43,25,19,6,3,19,45,19,55,19,18, - 19,91,19,128,19,13,12,9,12,17,12,17,6,2,12,50, - 12,13,18,24,12,34,12,15,12,11,24,36,12,76, + 4,0,100,1,0,100,2,0,131,3,0,100,2,0,107,8, + 0,114,178,0,124,3,0,116,1,0,106,12,0,107,6,0, + 114,145,0,116,13,0,124,4,0,95,14,0,113,175,0,116, + 0,0,106,15,0,124,3,0,131,1,0,114,175,0,116,16, + 0,124,4,0,95,14,0,113,175,0,113,178,0,113,67,0, + 113,67,0,87,116,1,0,106,8,0,116,17,0,25,125,5, + 0,120,76,0,100,27,0,68,93,68,0,125,6,0,124,6, + 0,116,1,0,106,8,0,107,7,0,114,241,0,116,13,0, + 106,18,0,124,6,0,131,1,0,125,7,0,110,13,0,116, + 1,0,106,8,0,124,6,0,25,125,7,0,116,19,0,124, + 5,0,124,6,0,124,7,0,131,3,0,1,113,202,0,87, + 100,7,0,100,8,0,103,1,0,102,2,0,100,9,0,100, + 10,0,100,8,0,103,2,0,102,2,0,102,2,0,125,8, + 0,120,149,0,124,8,0,68,93,129,0,92,2,0,125,9, + 0,125,10,0,116,20,0,100,11,0,100,12,0,132,0,0, + 124,10,0,68,131,1,0,131,1,0,115,101,1,116,21,0, + 130,1,0,124,10,0,100,13,0,25,125,11,0,124,9,0, + 116,1,0,106,8,0,107,6,0,114,143,1,116,1,0,106, + 8,0,124,9,0,25,125,12,0,80,113,58,1,121,20,0, + 116,13,0,106,18,0,124,9,0,131,1,0,125,12,0,80, + 87,113,58,1,4,116,22,0,107,10,0,114,186,1,1,1, + 1,119,58,1,89,113,58,1,88,113,58,1,87,116,22,0, + 100,14,0,131,1,0,130,1,0,121,19,0,116,13,0,106, + 18,0,100,15,0,131,1,0,125,13,0,87,110,24,0,4, + 116,22,0,107,10,0,114,248,1,1,1,1,100,2,0,125, + 13,0,89,110,1,0,88,116,13,0,106,18,0,100,16,0, + 131,1,0,125,14,0,124,9,0,100,9,0,107,2,0,114, + 54,2,116,13,0,106,18,0,100,17,0,131,1,0,125,15, + 0,116,19,0,124,5,0,100,18,0,124,15,0,131,3,0, + 1,110,0,0,116,19,0,124,5,0,100,19,0,124,12,0, + 131,3,0,1,116,19,0,124,5,0,100,15,0,124,13,0, + 131,3,0,1,116,19,0,124,5,0,100,16,0,124,14,0, + 131,3,0,1,116,19,0,124,5,0,100,20,0,124,11,0, + 131,3,0,1,116,19,0,124,5,0,100,21,0,100,22,0, + 106,23,0,124,10,0,131,1,0,131,3,0,1,116,19,0, + 124,5,0,100,23,0,116,24,0,131,0,0,131,3,0,1, + 116,25,0,106,26,0,116,0,0,106,27,0,131,0,0,131, + 1,0,1,124,9,0,100,9,0,107,2,0,114,233,2,116, + 28,0,106,29,0,100,24,0,131,1,0,1,100,25,0,116, + 25,0,107,6,0,114,233,2,100,26,0,116,30,0,95,31, + 0,113,233,2,110,0,0,100,2,0,83,40,28,0,0,0, + 117,250,0,0,0,83,101,116,117,112,32,105,109,112,111,114, + 116,108,105,98,32,98,121,32,105,109,112,111,114,116,105,110, + 103,32,110,101,101,100,101,100,32,98,117,105,108,116,45,105, + 110,32,109,111,100,117,108,101,115,32,97,110,100,32,105,110, + 106,101,99,116,105,110,103,32,116,104,101,109,10,32,32,32, + 32,105,110,116,111,32,116,104,101,32,103,108,111,98,97,108, + 32,110,97,109,101,115,112,97,99,101,46,10,10,32,32,32, + 32,65,115,32,115,121,115,32,105,115,32,110,101,101,100,101, + 100,32,102,111,114,32,115,121,115,46,109,111,100,117,108,101, + 115,32,97,99,99,101,115,115,32,97,110,100,32,95,105,109, + 112,32,105,115,32,110,101,101,100,101,100,32,116,111,32,108, + 111,97,100,32,98,117,105,108,116,45,105,110,10,32,32,32, + 32,109,111,100,117,108,101,115,44,32,116,104,111,115,101,32, + 116,119,111,32,109,111,100,117,108,101,115,32,109,117,115,116, + 32,98,101,32,101,120,112,108,105,99,105,116,108,121,32,112, + 97,115,115,101,100,32,105,110,46,10,10,32,32,32,32,114, + 149,0,0,0,78,114,48,0,0,0,114,170,0,0,0,244, + 8,0,0,0,98,117,105,108,116,105,110,115,114,186,0,0, + 0,116,5,0,0,0,112,111,115,105,120,245,1,0,0,0, + 47,244,2,0,0,0,110,116,245,1,0,0,0,92,99,1, + 0,0,0,0,0,0,0,2,0,0,0,3,0,0,0,115, + 0,0,0,115,33,0,0,0,124,0,0,93,23,0,125,1, + 0,116,0,0,124,1,0,131,1,0,100,0,0,107,2,0, + 86,1,113,3,0,100,1,0,83,40,2,0,0,0,114,29, + 0,0,0,78,40,1,0,0,0,114,31,0,0,0,40,2, + 0,0,0,114,22,0,0,0,114,118,0,0,0,114,4,0, + 0,0,114,4,0,0,0,114,5,0,0,0,114,2,1,0, + 0,210,6,0,0,115,2,0,0,0,6,0,117,25,0,0, + 0,95,115,101,116,117,112,46,60,108,111,99,97,108,115,62, + 46,60,103,101,110,101,120,112,114,62,114,71,0,0,0,117, + 30,0,0,0,105,109,112,111,114,116,108,105,98,32,114,101, + 113,117,105,114,101,115,32,112,111,115,105,120,32,111,114,32, + 110,116,114,72,0,0,0,114,95,0,0,0,116,6,0,0, + 0,119,105,110,114,101,103,114,206,0,0,0,114,3,0,0, + 0,114,25,0,0,0,114,21,0,0,0,114,30,0,0,0, + 114,6,0,0,0,117,4,0,0,0,46,112,121,119,117,6, + 0,0,0,95,100,46,112,121,100,84,40,4,0,0,0,117, + 3,0,0,0,95,105,111,117,9,0,0,0,95,119,97,114, + 110,105,110,103,115,117,8,0,0,0,98,117,105,108,116,105, + 110,115,117,7,0,0,0,109,97,114,115,104,97,108,40,32, + 0,0,0,114,97,0,0,0,114,7,0,0,0,114,105,0, + 0,0,114,106,0,0,0,114,108,0,0,0,114,75,1,0, + 0,114,107,0,0,0,114,65,0,0,0,114,152,0,0,0, + 244,5,0,0,0,105,116,101,109,115,114,187,0,0,0,114, + 61,0,0,0,114,163,0,0,0,114,194,0,0,0,114,149, + 0,0,0,114,166,0,0,0,114,202,0,0,0,114,56,0, + 0,0,114,198,0,0,0,114,60,0,0,0,244,3,0,0, + 0,97,108,108,114,89,0,0,0,114,154,0,0,0,114,26, + 0,0,0,114,11,0,0,0,114,4,1,0,0,114,192,0, + 0,0,114,74,1,0,0,114,122,0,0,0,114,251,0,0, + 0,114,205,0,0,0,114,209,0,0,0,40,16,0,0,0, + 244,10,0,0,0,115,121,115,95,109,111,100,117,108,101,244, + 11,0,0,0,95,105,109,112,95,109,111,100,117,108,101,116, + 11,0,0,0,109,111,100,117,108,101,95,116,121,112,101,114, + 66,0,0,0,114,145,0,0,0,116,11,0,0,0,115,101, + 108,102,95,109,111,100,117,108,101,116,12,0,0,0,98,117, + 105,108,116,105,110,95,110,97,109,101,116,14,0,0,0,98, + 117,105,108,116,105,110,95,109,111,100,117,108,101,116,10,0, + 0,0,111,115,95,100,101,116,97,105,108,115,116,10,0,0, + 0,98,117,105,108,116,105,110,95,111,115,114,21,0,0,0, + 114,25,0,0,0,116,9,0,0,0,111,115,95,109,111,100, + 117,108,101,116,13,0,0,0,116,104,114,101,97,100,95,109, + 111,100,117,108,101,116,14,0,0,0,119,101,97,107,114,101, + 102,95,109,111,100,117,108,101,116,13,0,0,0,119,105,110, + 114,101,103,95,109,111,100,117,108,101,114,4,0,0,0,114, + 4,0,0,0,114,5,0,0,0,244,6,0,0,0,95,115, + 101,116,117,112,173,6,0,0,115,102,0,0,0,0,9,6, + 1,6,2,12,1,9,2,6,2,12,1,28,1,15,1,24, + 1,15,1,12,1,15,1,22,2,13,1,13,1,15,1,18, + 2,13,1,20,2,33,1,19,2,31,1,10,1,15,1,13, + 1,4,2,3,1,15,1,5,1,13,1,12,2,12,2,3, + 1,19,1,13,2,11,1,15,2,12,1,15,1,19,2,16, + 1,16,1,16,1,16,1,25,2,19,1,19,1,12,1,13, + 1,12,1,114,86,1,0,0,99,2,0,0,0,0,0,0, + 0,3,0,0,0,3,0,0,0,67,0,0,0,115,136,0, + 0,0,116,0,0,124,0,0,124,1,0,131,2,0,1,116, + 1,0,131,0,0,125,2,0,116,2,0,106,3,0,106,4, + 0,116,5,0,106,6,0,124,2,0,140,0,0,103,1,0, + 131,1,0,1,116,2,0,106,7,0,106,8,0,116,9,0, + 131,1,0,1,116,2,0,106,7,0,106,8,0,116,10,0, + 131,1,0,1,116,11,0,106,12,0,100,1,0,107,2,0, + 114,116,0,116,2,0,106,7,0,106,8,0,116,13,0,131, + 1,0,1,110,0,0,116,2,0,106,7,0,106,8,0,116, + 14,0,131,1,0,1,100,2,0,83,40,3,0,0,0,117, + 50,0,0,0,73,110,115,116,97,108,108,32,105,109,112,111, + 114,116,108,105,98,32,97,115,32,116,104,101,32,105,109,112, + 108,101,109,101,110,116,97,116,105,111,110,32,111,102,32,105, + 109,112,111,114,116,46,114,80,1,0,0,78,40,15,0,0, + 0,114,86,1,0,0,114,215,0,0,0,114,7,0,0,0, + 114,26,1,0,0,114,192,0,0,0,114,33,1,0,0,114, + 47,1,0,0,114,55,1,0,0,114,251,0,0,0,114,194, + 0,0,0,114,202,0,0,0,114,3,0,0,0,114,56,0, + 0,0,114,205,0,0,0,114,21,1,0,0,40,3,0,0, + 0,114,84,1,0,0,114,85,1,0,0,116,17,0,0,0, + 115,117,112,112,111,114,116,101,100,95,108,111,97,100,101,114, + 115,114,4,0,0,0,114,4,0,0,0,114,5,0,0,0, + 244,8,0,0,0,95,105,110,115,116,97,108,108,249,6,0, + 0,115,16,0,0,0,0,2,13,1,9,1,28,1,16,1, + 16,1,15,1,19,1,114,87,1,0,0,40,3,0,0,0, + 117,3,0,0,0,119,105,110,114,1,0,0,0,114,2,0, + 0,0,40,77,0,0,0,114,58,0,0,0,114,10,0,0, + 0,114,11,0,0,0,114,17,0,0,0,114,19,0,0,0, + 114,28,0,0,0,114,38,0,0,0,114,43,0,0,0,114, + 44,0,0,0,114,45,0,0,0,114,54,0,0,0,114,64, + 0,0,0,114,65,0,0,0,244,8,0,0,0,95,95,99, + 111,100,101,95,95,114,188,0,0,0,114,67,0,0,0,114, + 92,0,0,0,114,81,0,0,0,114,88,0,0,0,114,68, + 0,0,0,114,70,0,0,0,114,91,0,0,0,114,96,0, + 0,0,114,99,0,0,0,114,102,0,0,0,114,15,0,0, + 0,114,181,0,0,0,114,14,0,0,0,114,18,0,0,0, + 116,17,0,0,0,95,82,65,87,95,77,65,71,73,67,95, + 78,85,77,66,69,82,114,113,0,0,0,114,122,0,0,0, + 114,107,0,0,0,114,108,0,0,0,114,120,0,0,0,114, + 123,0,0,0,114,131,0,0,0,114,133,0,0,0,114,141, + 0,0,0,114,148,0,0,0,114,151,0,0,0,114,159,0, + 0,0,114,162,0,0,0,114,165,0,0,0,114,168,0,0, + 0,114,176,0,0,0,114,185,0,0,0,114,190,0,0,0, + 114,193,0,0,0,114,194,0,0,0,114,202,0,0,0,114, + 205,0,0,0,114,218,0,0,0,114,224,0,0,0,114,244, + 0,0,0,114,248,0,0,0,114,254,0,0,0,114,4,1, + 0,0,114,255,0,0,0,114,5,1,0,0,114,20,1,0, + 0,114,21,1,0,0,114,33,1,0,0,114,48,1,0,0, + 114,54,1,0,0,114,56,1,0,0,114,59,1,0,0,114, + 60,1,0,0,114,63,1,0,0,114,64,1,0,0,114,65, + 1,0,0,114,71,1,0,0,114,73,1,0,0,114,215,0, + 0,0,114,77,1,0,0,114,86,1,0,0,114,87,1,0, + 0,114,4,0,0,0,114,4,0,0,0,114,4,0,0,0, + 114,5,0,0,0,244,8,0,0,0,60,109,111,100,117,108, + 101,62,8,0,0,0,115,140,0,0,0,6,21,6,3,12, + 13,12,10,12,9,12,6,12,12,12,10,12,6,12,7,15, + 22,12,8,15,3,12,12,6,2,6,3,22,4,19,68,19, + 23,12,19,12,20,12,109,22,1,18,2,6,2,9,2,9, + 1,9,2,15,27,12,23,12,21,12,12,18,8,12,13,12, + 11,12,55,12,18,12,11,12,11,12,13,21,55,21,12,18, + 12,19,57,19,54,19,50,19,34,22,132,19,29,25,43,25, + 19,6,3,19,45,19,55,19,18,19,91,19,128,19,13,12, + 9,12,17,12,17,6,2,12,50,12,13,18,24,12,34,12, + 15,12,11,24,36,12,76, }; diff -r d4912244cce6 -r e39a8f8ceb9f Python/pythonrun.c --- a/Python/pythonrun.c Sat May 04 18:07:12 2013 +0300 +++ b/Python/pythonrun.c Sat May 04 13:56:58 2013 -0400 @@ -866,7 +866,8 @@ * be set if __main__ gets further initialized later in the startup * process. */ - if (PyDict_GetItemString(d, "__loader__") == NULL) { + PyObject *loader = PyDict_GetItemString(d, "__loader__"); + if (loader == NULL || loader == Py_None) { PyObject *loader = PyObject_GetAttrString(interp->importlib, "BuiltinImporter"); if (loader == NULL) {/brett@python.org