Commit Graph

596 Commits

Author SHA1 Message Date
Brett Cannon ecfefb7956 Fix a spelling mistake in a comment. 2012-08-05 19:24:57 -04:00
Antoine Pitrou c4d974d3fa Remove unused variable `trim_get_code`. 2012-08-04 23:26:25 +02:00
Nick Coghlan 42c0766a53 Close #15486: Simplify the mechanism used to remove importlib frames from tracebacks when they just introduce irrelevant noise 2012-07-31 21:14:18 +10:00
Nick Coghlan 5ee9892406 Close #15425: Eliminate more importlib related traceback noise 2012-07-29 20:30:36 +10:00
Brett Cannon a6473f9cfd Issues #15169, #14599: Make PyImport_ExecCodeModuleWithPathnames() use
Lib/imp.py for imp.source_from_cache() instead of its own C version.

Also change PyImport_ExecCodeModuleObject() to not infer the source
path from the bytecode path like
PyImport_ExecCodeModuleWithPathnames() does. This makes the function
less magical.

This also has the side-effect of removing all uses of MAXPATHLEN in
Python/import.c which can cause failures on really long filenames.
2012-07-13 13:57:03 -04:00
Antoine Pitrou 44b4b6a9a5 Fix compilation under Windows 2012-07-10 18:27:54 +02:00
Benjamin Peterson 66f3659c9e fix refleak 2012-07-09 22:21:55 -07:00
Benjamin Peterson fa873704a4 initialize variable for compiler happiness 2012-07-09 13:43:53 -07:00
Brett Cannon 77b2abd094 Issue #15167 (as part of #13959): imp.get_magic() is no implemented in
Lib/imp.py.
2012-07-09 16:09:00 -04:00
Brett Cannon 3adc7b75a5 Issue #15242: Have PyImport_GetMagicTag() return a const char *
defined in sysmodule.c instead of straight out of a Unicode object.

Thanks to Amaury Forgeot d'Arc for noticing the bug and Eric Snow for
writing the patch.
2012-07-09 14:22:12 -04:00
Antoine Pitrou bc07a5c913 Issue #15110: Fix the tracebacks generated by "import xxx" to not show the importlib stack frames. 2012-07-08 12:01:27 +02:00
Brett Cannon 98979b85e7 Issue #15166: Re-implement imp.get_tag() using sys.implementation.
Also eliminates some C code in Python/import.c as well.

Patch by Eric Snow with verification by comparing against another
patch from Jeff Knupp.
2012-07-02 15:13:11 -04:00
Victor Stinner 81c39a88a4 get_sourcefile(): use PyUnicode_READ() to avoid the creation of a temporary
Py_UCS4 buffer
2012-06-16 03:22:05 +02:00
Nick Coghlan 0b43bcf528 Close #14857: fix regression in references to PEP 3135 implicit __class__ closure variable. Reopens issue #12370, but also updates unittest.mock to workaround that issue 2012-05-27 18:17:07 +10:00
Antoine Pitrou ea3eb88bca Issue #9260: A finer-grained import lock.
Most of the import sequence now uses per-module locks rather than the
global import lock, eliminating well-known issues with threads and imports.
2012-05-17 18:55:59 +02:00
Antoine Pitrou 6efa50a384 Issue #14583: Fix importlib bug when a package's __init__.py would first import one of its modules then raise an error. 2012-05-07 21:41:59 +02:00
Antoine Pitrou b78174c010 Fix too early decrefs. 2012-05-06 17:15:23 +02:00
Nadeem Vawda 8f46d655b9 Fix typo in changeset eb5c5c23ca9b. 2012-05-05 12:27:30 +02:00
Antoine Pitrou f3a42dee9a Simplify code for load_dynamic() 2012-05-04 22:40:25 +02:00
Brett Cannon 0429e1a57d Issue #13959: Move module type constants to Lib/imp.py. 2012-05-04 16:13:30 -04:00
Brett Cannon 6b9b727695 Remove dead Windows code which no longer will compile. 2012-05-04 16:04:14 -04:00
Brett Cannon 2657df4744 Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
This introduces a new function, imp.extension_suffixes(), which is
currently undocumented. That is forthcoming once issue #14657 is
resolved and how to expose file suffixes is decided.
2012-05-04 15:20:40 -04:00
Brett Cannon 62228dbd6c Issues #13959, 14647: Re-implement imp.reload() in Lib/imp.py.
Thanks to Eric Snow for the patch.
2012-04-29 14:38:11 -04:00
Brett Cannon acf85cd131 Issue #13959: Re-implement imp.NullImporter in Lib/imp.py. 2012-04-29 12:50:03 -04:00
Brett Cannon aa93642a35 Issue #14605: Use None in sys.path_importer_cache to represent no
finder instead of using some (now non-existent) implicit finder.
2012-04-27 15:30:58 -04:00
Victor Stinner 8f825060f1 Check newly created consistency using _PyUnicode_CheckConsistency(str, 1)
* In debug mode, fill the string data with invalid characters
 * Simplify also reference counting in PyCodec_BackslashReplaceErrors()
   and PyCodec_XMLCharRefReplaceError()
2012-04-27 13:55:39 +02:00
Brett Cannon 8923a4d4c5 Issue #14605: Insert to the front of sys.path_hooks instead of appending. 2012-04-24 22:03:46 -04:00
Brett Cannon e69f0df45b Issue #13959: Re-implement imp.find_module() in Lib/imp.py.
Thanks to Eric Snow for taking an initial stab at the implementation.
2012-04-21 21:09:46 -04:00
Brett Cannon a64faf0771 Issue #13959: Re-implement imp.source_from_cache() in Lib/imp.py. 2012-04-21 18:52:52 -04:00
Brett Cannon ea59dbff16 Issue #13959: Re-implement imp.cache_from_source() in Lib/imp.py. 2012-04-20 21:44:46 -04:00
Benjamin Peterson d76bc7abac rollback 005fd1fe31ab (see #14609 and #14582)
Being able to overload a sys.module entry during import of a module was broken
by this changeset.
2012-04-18 10:55:43 -04:00
Brett Cannon 64befe939c Issue #13959: Re-implement imp.load_compiled() in imp.py. 2012-04-17 19:14:26 -04:00
Brett Cannon 273323cf68 Issue #14592: A relative import will raise a KeyError if __package__
or __name__ are not set in globals.

Thanks to Stefan Behnel for the bug report.
2012-04-17 19:05:11 -04:00
Brian Curtin 09b86d1196 Fix #14600. Correct reference handling and naming of ImportError convenience function 2012-04-17 16:57:09 -05:00
Brett Cannon 16475adcbb Issue #13959: Re-implement imp.load_source() in imp.py. 2012-04-16 22:11:25 -04:00
Antoine Pitrou 22a1d17bb5 Fix another refleak 2012-04-16 22:06:21 +02:00
Antoine Pitrou 538ba2afb5 Fix a refleak 2012-04-16 21:52:45 +02:00
Antoine Pitrou 71382cb64b Fix reference loss on Py_None when None is encountered in sys.modules. 2012-04-16 18:48:49 +02:00
Brett Cannon 2ee61422ed Issue #13959: Re-implement imp.load_package() in imp.py.
Thanks to Eric Snow for helping with imp.load_module() (previous
commit) which led to the removal of a bunch of C code.
2012-04-15 22:28:28 -04:00
Brett Cannon 01a76171a0 Issue #13959: Re-implement imp.load_module() in imp.py. 2012-04-15 20:25:23 -04:00
Brett Cannon 8a1d04c643 Issue #13959: Simplify imp.reload() by relying on a module's
__loader__.

Since import now sets __loader__ on all modules it creates and
imp.reload() already relied on the attribute for modules that import
didn't create, the only potential compatibility issue is if people
were deleting the attribute on modules and expecting imp.reload() to
continue to work.
2012-04-15 17:56:09 -04:00
Brett Cannon 6f44d66bc4 Issue #13959: Rename imp to _imp and add Lib/imp.py and begin
rewriting functionality in pure Python.

To start, imp.new_module() has been rewritten in pure Python, put into
importlib (privately) and then publicly exposed in imp.
2012-04-15 16:08:47 -04:00
Brett Cannon 881535b726 Issue #14582: Import returns the module returned by a loader instead
of sys.modules when possible.

This is being done for two reasons. One is to gain a little bit of
performance by skipping an unnecessary dict lookup in sys.modules. But
the other (and main) reason is to be a little bit more clear in how
things should work from the perspective of import's interactions with
loaders. Otherwise loaders can easily forget to return the module even
though PEP 302 explicitly states they are expected to return the module
they loaded.
2012-04-15 15:24:04 -04:00
Brett Cannon 27fc52877c Set ImportError.name when raising the exception in the case of None
found in sys.modules.
2012-04-15 14:15:31 -04:00
Brett Cannon 49f8d8b016 Handle importing pkg.mod by executing
__import__('mod', {'__packaging__': 'pkg', level=1) w/o properly (and
thus not segfaulting).
2012-04-14 21:50:00 -04:00
Brian Curtin e6b299faf5 Fix Windows build 2012-04-14 14:19:33 -05:00
Brett Cannon 740fce0e38 Undo a C99 idiom. 2012-04-14 14:23:49 -04:00
Brett Cannon fd0741555b Issue #2377: Make importlib the implementation of __import__().
importlib._bootstrap is now frozen into Python/importlib.h and stored
as _frozen_importlib in sys.modules. Py_Initialize() loads the frozen
code along with sys and imp and then uses _frozen_importlib._install()
to set builtins.__import__() w/ _frozen_importlib.__import__().
2012-04-14 14:10:13 -04:00
Benjamin Peterson f53d20f2cd in 72556ff86828, I should have updated the magic as well as the comment (#14230) 2012-03-16 09:39:12 -05:00
Benjamin Peterson abdb5528c0 fix comment 2012-03-15 15:40:37 -05:00
Benjamin Peterson 2afe6aeae8 perform yield from delegation by repeating YIELD_FROM opcode (closes #14230)
This allows generators that are using yield from to be seen by debuggers. It
also kills the f_yieldfrom field on frame objects.

Patch mostly from Mark Shannon with a few tweaks by me.
2012-03-15 15:37:39 -05:00
Antoine Pitrou cf1c8339f9 Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding. 2012-02-22 18:08:30 +01:00
Antoine Pitrou 4f22a8d739 Issue #14084: Fix a file descriptor leak when importing a module with a bad encoding. 2012-02-22 18:05:43 +01:00
Antoine Pitrou 7214612443 In find_module(), do not silence fileno() and dup() errors. 2012-02-22 18:03:04 +01:00
Victor Stinner a3dd409b52 Remove now useless arbitrary limit of module name length 2012-01-26 00:31:49 +01:00
Antoine Pitrou 581616624d Port import fixes from 2.7. 2012-01-25 18:06:07 +01:00
Antoine Pitrou 33d15f7c85 Port import fixes from 2.7. 2012-01-25 18:01:45 +01:00
Antoine Pitrou abaf89b2be Issue #11235: Fix OverflowError when trying to import a source file whose modification time doesn't fit in a 32-bit timestamp. 2012-01-24 17:45:50 +01:00
Antoine Pitrou 2be60afb7e Issue #11235: Fix OverflowError when trying to import a source file whose modification time doesn't fit in a 32-bit timestamp. 2012-01-24 17:44:06 +01:00
Antoine Pitrou 165e01f83f Fix the builtin module initialization code to store the init function for future reinitialization. 2012-01-18 20:17:58 +01:00
Antoine Pitrou 6c40eb7f42 Fix the builtin module initialization code to store the init function for future reinitialization. 2012-01-18 20:16:09 +01:00
Antoine Pitrou 5136ac0ca2 Issue #13645: pyc files now contain the size of the corresponding source
code, to avoid timestamp collisions (especially on filesystems with a low
timestamp resolution) when checking for freshness of the bytecode.
2012-01-13 18:52:16 +01:00
Victor Stinner 3573476271 (Merge 3.2) Handle correctly _Py_fopen() error: don't replace the exception 2011-12-18 21:05:22 +01:00
Victor Stinner bd0850b857 import.c now catchs _Py_stat() exceptions
_Py_stat() now returns -2 if an exception was raised.
2011-12-18 20:47:30 +01:00
Charles-François Natali 1659b83b1d Followup to a541bda2f5e2: Add a short comment. 2011-12-07 23:17:58 +01:00
Charles-François Natali 7c0b0cc9f9 Issue #11051: Reduce the number of syscalls per import. 2011-12-07 19:16:01 +01:00
Antoine Pitrou 86a36b500a PEP 3155 / issue #13448: Qualified name for classes and functions. 2011-11-25 18:56:07 +01:00
Victor Stinner 1f7951711c Catch PyUnicode_AS_UNICODE() errors 2011-11-17 00:45:54 +01:00
Antoine Pitrou 8ad982cccf Use PyUnicode_FromFormat() to create the temporary file name.
Also, as in importlib, append the id of an object to make the file name
pseudo-random.
2011-11-15 22:27:32 +01:00
Antoine Pitrou 1d8f3f451c Fix regression under Windows following b75b41237380 (from issue #13392) 2011-11-15 20:40:55 +01:00
Antoine Pitrou 28e401e717 Issue #13392: Writing a pyc file should now be atomic under Windows as well. 2011-11-15 19:15:19 +01:00
Charles-François Natali 0c929d9d39 Issue #13303: Fix bytecode file default permission. 2011-11-10 19:12:29 +01:00
Éric Araujo e64052176d Merge follow-up for #11254 and other changes from 3.2 2011-11-03 05:17:11 +01:00
Éric Araujo 5df1108de2 Add signatures to the docstring of functions added to imp by PEP 3147 2011-11-03 03:38:44 +01:00
Antoine Pitrou 8db076cf8a Issue #10363: Deallocate global locks in Py_Finalize(). 2011-10-30 19:13:55 +01:00
Charles-François Natali e695eec24a Issue #13303: Fix a race condition in the bytecode file creation. 2011-10-31 20:47:31 +01:00
Martin v. Löwis f45dee998f Port import_module_level to Unicode API. 2011-10-30 23:50:02 +01:00
Antoine Pitrou 6fbbc33440 Issue #10363: Deallocate global locks in Py_Finalize(). 2011-10-30 19:14:46 +01:00
Martin v. Löwis 796ea53937 Port PyImport_ReloadModule to Unicode API. 2011-10-30 09:07:07 +01:00
Antoine Pitrou b528fcf954 Fix test_imp failure under Windows 2011-10-25 00:21:02 +02:00
Martin v. Löwis 9af29d39af Rewrite find_module_path using unicode API. 2011-10-23 18:45:16 +02:00
Martin v. Löwis 2cc0cc54a2 Fix off-by-one error. 2011-10-23 18:41:56 +02:00
Martin v. Löwis fadcd317fa Drop unused macros. Use CACHEDIR consistently. 2011-10-23 18:08:20 +02:00
Martin v. Löwis 8a0ef78e8c Rewrite make_source_pathname using Unicode API. 2011-10-23 18:05:06 +02:00
Martin v. Löwis 30260a7fe3 Add ready checks for make_compiled_pathname. 2011-10-23 17:35:46 +02:00
Martin v. Löwis 2db72863fb Reformulate make_compiled_pathname in terms of unicode objects. 2011-10-23 17:29:08 +02:00
Antoine Pitrou 707033a694 Issue #13146: Writing a pyc file is now atomic under POSIX. 2011-10-17 19:28:44 +02:00
Martin v. Löwis bd928fef42 Rename _Py_identifier to _Py_IDENTIFIER. 2011-10-14 10:20:37 +02:00
Victor Stinner 8c9818980b Fix typo in import.c 2011-10-11 22:27:13 +02:00
Victor Stinner beac78bb24 Use PyUnicode_AsUnicodeAndSize() instead of PyUnicode_GET_SIZE() 2011-10-11 21:55:01 +02:00
Martin v. Löwis 1ee1b6fe0d Use identifier API for PyObject_GetAttrString. 2011-10-10 18:11:30 +02:00
Martin v. Löwis afe55bba33 Add API for static strings, primarily good for identifiers.
Thanks to Konrad Schöbel and Jasper Schulz for helping with the mass-editing.
2011-10-09 10:38:36 +02:00
Victor Stinner 46084bad88 Fix find_module_path(): make the string ready 2011-10-06 02:39:42 +02:00
Benjamin Peterson 014cc42db8 remove unused label 2011-10-02 13:19:16 -04:00
Martin v. Löwis 0b1d348990 Issue 13085: Fix some memory leaks. Patch by Stefan Krah. 2011-10-01 16:35:40 +02:00
Georg Brandl 4cb0de246c Rename new macros to conform to naming rules (function macros have "Py" prefix, not "PY"). 2011-09-28 21:49:49 +02:00
Martin v. Löwis d63a3b8beb Implement PEP 393. 2011-09-28 07:41:54 +02:00
Victor Stinner a1fe1f8dcf Merge 3.2: Issue #7732: Don't open a directory as a file anymore while
importing a module. Ignore the direcotry if its name matchs the module name
(e.g.  "__init__.py") and raise a ImportError instead.
2011-09-23 18:59:08 +02:00
Victor Stinner 53ffdc53bf Issue #7732: Don't open a directory as a file anymore while importing a
module. Ignore the direcotry if its name matchs the module name (e.g.
"__init__.py") and raise a ImportError instead.
2011-09-23 18:54:40 +02:00
Victor Stinner 9561d7c526 import.c: remove now useless arbitrary limit 2011-09-15 19:50:01 +02:00