Status: | Merged |
---|---|
Merge reported by: | Barry Warsaw |
Merged at revision: | not available |
Proposed branch: | lp:~barry/python/pep3147 |
Merge into: | lp:python/py3k |
Diff against target: |
2808 lines (+1209/-293) 39 files modified
.bzrignore (+1/-0) .hgignore (+1/-0) Doc/c-api/import.rst (+17/-0) Doc/library/compileall.rst (+12/-6) Doc/library/imp.rst (+35/-2) Doc/library/py_compile.rst (+7/-3) Doc/library/runpy.rst (+4/-1) Include/import.h (+3/-0) Lib/compileall.py (+48/-26) Lib/importlib/_bootstrap.py (+20/-1) Lib/importlib/test/__main__.py (+6/-1) Lib/importlib/test/source/test_file_loader.py (+5/-4) Lib/importlib/test/source/test_finder.py (+12/-1) Lib/importlib/test/source/test_source_encoding.py (+1/-1) Lib/importlib/test/source/util.py (+11/-8) Lib/importlib/util.py (+1/-0) Lib/inspect.py (+1/-0) Lib/py_compile.py (+27/-21) Lib/pydoc.py (+2/-1) Lib/runpy.py (+2/-0) Lib/site.py (+8/-4) Lib/test/script_helper.py (+12/-11) Lib/test/support.py (+64/-26) Lib/test/test_cmd_line_script.py (+18/-12) Lib/test/test_compileall.py (+69/-10) Lib/test/test_frozen.py (+5/-5) Lib/test/test_imp.py (+125/-2) Lib/test/test_import.py (+176/-30) Lib/test/test_pkg.py (+10/-10) Lib/test/test_pkgimport.py (+14/-12) Lib/test/test_pydoc.py (+7/-9) Lib/test/test_runpy.py (+17/-8) Lib/test/test_site.py (+32/-13) Lib/test/test_zipfile.py (+8/-1) Lib/test/test_zipimport.py (+19/-20) Lib/zipfile.py (+40/-13) Makefile.pre.in (+1/-0) Python/import.c (+366/-31) Python/pythonrun.c (+2/-0) |
To merge this branch: | bzr merge lp:~barry/python/pep3147 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Python Development | Pending | ||
Review via email: mp+22648@code.launchpad.net |
Commit message
Description of the change
Work-in-progress implementation of PEP 3147
- 41150. By raymond.hettinger
-
Document sorting HowTo
- 41151. By raymond.hettinger
-
Add and update itertools recipes.
- 41152. By raymond.hettinger
-
Fix nits in itertools recipes.
- 41153. By georg.brandl
-
#8213: document behavior of -u on py3k better.
- 41154. By larry.hastings
-
Blocked revisions 79590 via svnmerge
........
r79590 | larry.hastings | 2010-04-02 04:01:35 -0700 (Fri, 02 Apr 2010) | 10 linesCapsule-related changes:
* PyCObject_AsVoidPtr( ) can now open capsules. This addresses
most of the remaining backwards-compatibility concerns about
the conversion of Python 2.7 from CObjects to capsules.
* CObjects were marked Pending Deprecation.
* Documentation about this pending deprecation was added to
cobject.h.
* The capsule source files were added to the legacy PC build
processes.
........ - 41155. By larry.hastings
-
Blocked revisions 79592 via svnmerge
........
r79592 | larry.hastings | 2010-04-02 04:18:17 -0700 (Fri, 02 Apr 2010) | 3 linesIssue #8235: _socket: Add the constant ``SO_SETFIB``. SO_SETFIB is
a socket option available on FreeBSD 7.1 and newer.
........ - 41156. By larry.hastings
-
- Issue #8235: _socket: Add the constant ``SO_SETFIB``. SO_SETFIB is
a socket option available on FreeBSD 7.1 and newer. - 41157. By ezio.melotti
-
Merged revisions 79540-79541 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk Add -Wd to the flags used to run the tests (-3 is not necessary here).
........
r79540 | ezio.melotti | 2010-04-01 01:18:09 +0300 (Thu, 01 Apr 2010) | 1 lineAdd -Wd and -3 to the flags used to run the tests.
........
r79541 | ezio.melotti | 2010-04-01 01:43:31 +0300 (Thu, 01 Apr 2010) | 1 lineAdd -Wd and -3 to the flags used to run the tests on Windows.
........ - 41158. By raymond.hettinger
-
Issue 8257: Decimal constructor to accept float argument.
- 41159. By andrew.kuchling
-
Merged revisions 79603 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79603 | andrew.kuchling | 2010-04-02 12:59:16 -0400 (Fri, 02 Apr 2010) | 1 line#4440: modernize a use of filter(), making it compatible with 3.x
........ - 41160. By antoine.pitrou
-
Furniture is not very reliable these days (buildbot failures).
- 41161. By florent.xicluna
-
(partially)
Merged revisions 79534,79537,
79539,79558, 79606 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79534 | florent.xicluna | 2010-03-31 23:21:54 +0200 (mer, 31 mar 2010) | 2 linesFix test for xml.etree when using a non-ascii path. And use check_warnings instead of catch_warnings.
........
r79537 | florent.xicluna | 2010-03-31 23:40:32 +0200 (mer, 31 mar 2010) | 2 linesFix typo
........
r79539 | florent.xicluna | 2010-04-01 00:01:03 +0200 (jeu, 01 avr 2010) | 2 linesReplace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
........
r79558 | florent.xicluna | 2010-04-01 20:17:09 +0200 (jeu, 01 avr 2010) | 2 lines#7092: Fix some -3 warnings, and fix Lib/platform.py when the path contains a double-quote.
........
r79606 | florent.xicluna | 2010-04-02 19:26:42 +0200 (ven, 02 avr 2010) | 2 linesBackport some robotparser test and skip the test if the external resource is not available.
........ - 41162. By raymond.hettinger
-
Add nice docstrings to namedtuples.
- 41163. By florent.xicluna
-
An oversight in previous merge, r79610: test_doctest is sensible to the line numbering.
- 41164. By georg.brandl
-
#8288: fix next -> __next__.
- 41165. By tarek.ziade
-
Merged revisions 79618 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79618 | tarek.ziade | 2010-04-02 23:14:04 +0200 (Fri, 02 Apr 2010) | 1 lineremoved the local copy of xxmodule, and skip only test_build_ext when xxmodule is not found, not the whole unittest
........ - 41166. By ezio.melotti
-
Blocked revisions 79582 via svnmerge
........
r79582 | georg.brandl | 2010-04-02 11:51:31 +0300 (Fri, 02 Apr 2010) | 1 lineFix typo in unicode character name.
........ - 41167. By brian.curtin
-
Change test_support to support. Fixes a failing test on Windows.
- 41168. By benjamin.peterson
-
Blocked revisions 79636,79639 via svnmerge
........
r79636 | benjamin.peterson | 2010-04-02 18:59:41 -0500 (Fri, 02 Apr 2010) | 4 linesalways check _PyString_Resize for error
also normalize how this error is checked
........
r79639 | benjamin.peterson | 2010-04-02 19:57:33 -0500 (Fri, 02 Apr 2010) | 1 linemore _PyString_Resize error checking
........ - 41169. By benjamin.peterson
-
Merged revisions 79642,79644 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79642 | benjamin.peterson | 2010-04-02 20:08:34 -0500 (Fri, 02 Apr 2010) | 1 linesplit out large test function
........
r79644 | benjamin.peterson | 2010-04-02 20:28:57 -0500 (Fri, 02 Apr 2010) | 1 linegive TypeError when trying to set T_STRING_INPLACE
........ - 41170. By victor.stinner
-
Blocked revisions 79654 via svnmerge
........
r79654 | victor.stinner | 2010-04-03 10:40:16 +0200 (sam., 03 avril 2010) | 5 linesIssue #8227: Fix C API documentation, argument parsing
* 'z', 'z#', 'z*' does also accept Unicode
* unify types name: replace "string or Unicode objet" by "string or Unicode"
........ - 41171. By tarek.ziade
-
Merged revisions 79652 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79652 | tarek.ziade | 2010-04-03 10:37:59 +0200 (Sat, 03 Apr 2010) | 1 lineIssue #1222585: Added LDCXXSHARED for C++ support
........ - 41172. By raymond.hettinger
-
Add a subtract() method to collections.
Counter( ) - 41173. By mark.dickinson
-
Merged revisions 79661 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79661 | mark.dickinson | 2010-04-03 11:27:05 +0100 (Sat, 03 Apr 2010) | 14 linesFix a couple of issues with the test_structmemb
ersType class in _testcapimodule - rename to _test_structmem
bersType to avoid the class being automatically
called by test_capi- allow space for trailing NUL in inplace_member field of all_structmembers
- use T_STRING_INPLACE instead of T_INPLACE_STRING as keyword argument
to _test_structmembersType initializer - don't attempt to initialize inplace_member field if T_STRING_INPLACE
argument wasn't supplied.
........ - 41174. By mark.dickinson
-
Merged revisions 79583,79588-79589 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79583 | mark.dickinson | 2010-04-02 09:53:22 +0100 (Fri, 02 Apr 2010) | 7 linesIssue #2531: Make float-to-decimal comparisons return correct results.
Float to decimal comparison operations now return a result based on
the numeric values of the operands. Decimal.__hash__ has also been
fixed so that Decimal and float values that compare equal have equal
hash value.
........
r79588 | mark.dickinson | 2010-04-02 11:17:07 +0100 (Fri, 02 Apr 2010) | 2 linesIssue #7279: Make comparisons involving a Decimal sNaN signal InvalidOperation.
........
r79589 | mark.dickinson | 2010-04-02 11:35:12 +0100 (Fri, 02 Apr 2010) | 6 linesIssue #7279: Make Decimal('nan') hashable. Decimal('snan') remains unhashable.
Also rewrite the Decimal __hash__ method so that it doesn't rely on
float('inf') being valid: float('inf') could raise an exception on
platforms not using IEEE 754 arithmetic.
........ - 41175. By mark.dickinson
-
Merged revisions 79629 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79629 | mark.dickinson | 2010-04-02 23:27:36 +0100 (Fri, 02 Apr 2010) | 2 linesIssue #8294: Allow float and Decimal arguments in Fraction constructor.
........ - 41176. By mark.dickinson
-
Remove unused define.
- 41177. By ezio.melotti
-
Merged revisions 79678 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79678 | ezio.melotti | 2010-04-03 17:51:00 +0300 (Sat, 03 Apr 2010) | 1 lineUse more specific assert* methods in test_decimal.
........ - 41178. By mark.dickinson
-
Clean up integer tests in test_struct, and bring them more in line with the trunk tests.
- 41179. By mark.dickinson
-
Internal refactoring in struct.pack: make all integer conversions go through get_pylong.
- 41180. By ezio.melotti
-
Add -bb to rt.bat to do some extra checks during the tests (it is already used by the non-Windows buildbots).
- 41181. By ezio.melotti
-
Blocked revisions 79624 via svnmerge
........
r79624 | ezio.melotti | 2010-04-03 00:43:10 +0300 (Sat, 03 Apr 2010) | 1 lineFix test_compiler.py that was using unittest.__file__ to find Lib/ (unittest is now a package).
........ - 41182. By benjamin.peterson
-
Blocked revisions 79693,79695 via svnmerge
........
r79693 | benjamin.peterson | 2010-04-03 10:38:38 -0500 (Sat, 03 Apr 2010) | 1 linewrap
........
r79695 | benjamin.peterson | 2010-04-03 10:40:29 -0500 (Sat, 03 Apr 2010) | 1 lineremove unneeded argument
........ - 41183. By mark.dickinson
-
Merged revisions 79699 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79699 | mark.dickinson | 2010-04-03 16:47:46 +0100 (Sat, 03 Apr 2010) | 1 lineAdd Misc/NEWS entry for r79609.
........ - 41184. By mark.dickinson
-
Merged revisions 79674 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79674 | mark.dickinson | 2010-04-03 15:05:10 +0100 (Sat, 03 Apr 2010) | 3 linesIssue #8300: Let struct.pack use __index__ to convert and pack non-integers.
Based on a patch by Meador Inge.
........ - 41185. By benjamin.peterson
-
Blocked revisions 79697-79698,79704 via svnmerge
........
r79697 | benjamin.peterson | 2010-04-03 10:44:56 -0500 (Sat, 03 Apr 2010) | 1 linesilence PyCObject warnings in bsddb
........
r79698 | benjamin.peterson | 2010-04-03 10:45:59 -0500 (Sat, 03 Apr 2010) | 1 linespelling
........
r79704 | benjamin.peterson | 2010-04-03 10:58:15 -0500 (Sat, 03 Apr 2010) | 1 lineremove deprecation warnings silence attempting
........ - 41186. By mark.dickinson
-
Blocked revisions 79707 via svnmerge
........
r79707 | mark.dickinson | 2010-04-03 17:41:20 +0100 (Sat, 03 Apr 2010) | 5 linesEnsure 'module removed' warning messages contain the word 'module' or 'package'.
This should fix the test_py3kwarn failure on OS X. test_support.
import_ module
also requires this.
........ - 41187. By mark.dickinson
-
Blocked revisions 79714 via svnmerge
........
r79714 | mark.dickinson | 2010-04-03 19:17:54 +0100 (Sat, 03 Apr 2010) | 1 lineSilence DeprecationWarnings from uses of has_key and <> in plat-mac.
........ - 41188. By benjamin.peterson
-
Blocked revisions 79712 via svnmerge
........
r79712 | raymond.hettinger | 2010-04-03 12:10:05 -0500 (Sat, 03 Apr 2010) | 1 lineSilence a compiler warning.
........ - 41189. By benjamin.peterson
-
Blocked revisions 79718-79719 via svnmerge
........
r79718 | antoine.pitrou | 2010-04-03 16:42:18 -0500 (Sat, 03 Apr 2010) | 3 linesRemove useless (?) import from r79706
........
r79719 | benjamin.peterson | 2010-04-03 16:50:40 -0500 (Sat, 03 Apr 2010) | 1 lineimport bsddb more robustly
........ - 41190. By benjamin.peterson
-
Merged revisions 79723 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79723 | benjamin.peterson | 2010-04-03 17:48:51 -0500 (Sat, 03 Apr 2010) | 1 lineensure that the locale does not affect the tokenization of identifiers
........ - 41191. By benjamin.peterson
-
Merged revisions 79725 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79725 | benjamin.peterson | 2010-04-03 18:03:35 -0500 (Sat, 03 Apr 2010) | 4 linesuse our own locale independent ctype macros
requires building pyctype.o into pgen
........ - 41192. By raymond.hettinger
-
Add count() method to collections.
deque() . - 41193. By benjamin.peterson
-
add missing decrefs
- 41194. By ezio.melotti
-
Fix versionchanged from 2.7 to 3.2 in decimal.rst.
- 41195. By ezio.melotti
-
Merged revisions 79733,79735 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79733 | ezio.melotti | 2010-04-04 09:41:27 +0300 (Sun, 04 Apr 2010) | 1 lineAdd a versionadded to Counter.subtract() doc.
........
r79735 | ezio.melotti | 2010-04-04 09:50:58 +0300 (Sun, 04 Apr 2010) | 1 lineRevert 79733 - Counter is new in 2.7, the versionadded is not necessary - and fix a typo.
........ - 41196. By ezio.melotti
-
Recorded merge of revisions 79660 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79660 | raymond.hettinger | 2010-04-03 13:22:00 +0300 (Sat, 03 Apr 2010) | 1 lineAdd subtract() method to collections.
Counter( ) objects.
........ - 41197. By ezio.melotti
-
Merged revisions 79740 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79740 | ezio.melotti | 2010-04-04 10:00:02 +0300 (Sun, 04 Apr 2010) | 1 lineUse more specific assert* methods in test_struct.
........ - 41198. By mark.dickinson
-
Merged revisions 79745 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79745 | mark.dickinson | 2010-04-04 09:43:04 +0100 (Sun, 04 Apr 2010) | 3 linesIssue #8300 (__index__ handling in struct.pack): Remove redundant check
and improve test coverage. Thanks Meador Inge for the patch.
........ - 41199. By mark.dickinson
-
Merged revisions 79751 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79751 | mark.dickinson | 2010-04-04 22:19:35 +0100 (Sun, 04 Apr 2010) | 1 lineA handful of whitespace fixes in Modules/_struct.c.
........ - 41200. By mark.dickinson
-
Merged revisions 79756 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79756 | mark.dickinson | 2010-04-04 23:09:21 +0100 (Sun, 04 Apr 2010) | 6 linesAdd versionchanged entry for Decimal(float) construction.
Also add an example of constructing a Decimal directly from a float,
update the quickstart tutorial, and tweak another couple of
sentences.
........ - 41201. By benjamin.peterson
-
Merged revisions 79762 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79762 | benjamin.peterson | 2010-04-04 18:01:03 -0500 (Sun, 04 Apr 2010) | 1 linetabify
........ - 41202. By benjamin.peterson
-
Merged revisions 79763 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79763 | benjamin.peterson | 2010-04-04 18:03:22 -0500 (Sun, 04 Apr 2010) | 1 linefix tabs
........ - 41203. By benjamin.peterson
-
Blocked revisions 79769 via svnmerge
........
r79769 | benjamin.peterson | 2010-04-04 18:23:22 -0500 (Sun, 04 Apr 2010) | 1 linefix dis on new style classes #8310
........ - 41204. By benjamin.peterson
-
factor out constant
- 41205. By ezio.melotti
-
Merged revisions 79768 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79768 | ezio.melotti | 2010-04-05 02:21:53 +0300 (Mon, 05 Apr 2010) | 1 lineFix markup in decimal.rst.
........ - 41206. By philip.jenvey
-
Merged revisions 79779 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79779 | philip.jenvey | 2010-04-04 19:51:51 -0700 (Sun, 04 Apr 2010) | 2 linesfix escape_encode to return the correct consumed size
........ - 41207. By ezio.melotti
-
Merged revisions 79781 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79781 | ezio.melotti | 2010-04-05 06:51:38 +0300 (Mon, 05 Apr 2010) | 1 line#8212: rephrase the webservers howto and fix some mistakes.
........ - 41208. By ezio.melotti
-
Merged revisions 79788 via svnmerge from
svn+ssh://<email address hidden>/python/ trunk ........
r79788 | ezio.melotti | 2010-04-05 11:16:41 +0300 (Mon, 05 Apr 2010) | 1 lineFix markup errors.
........ - 41209. By Barry Warsaw
-
branch merge
- 41210. By Barry Warsaw
-
Ensure that no .pyc file outside of __pycache__ is written by the test suite.
- 41211. By Barry Warsaw
-
merge trunk
- 41212. By Barry Warsaw
-
Many updates based on Rietveld review by Antoine Pitrou.
- 41213. By Barry Warsaw
-
trunk merge
- 41214. By Barry Warsaw
-
trunk merge
- 41215. By Barry Warsaw
-
trunk merge
- 41216. By Barry Warsaw
-
Second round of Rietveld comments.
* Added documentation for cache_from_
source( ), source_ from_cache( ), and
magic_tags.
* Use addCleanup() where appropriate.
* Other style cleanup. - 41217. By Barry Warsaw
-
Test repairs.
- 41218. By Barry Warsaw
-
trunk merge
- 41219. By Barry Warsaw
-
Fixes for Windows compatibility.
- 41220. By Barry Warsaw
-
Be more aggressive for Windows.
- 41221. By Barry Warsaw
-
trunk merge
- 41222. By Barry Warsaw
-
Benjamin makes a good point that debug_override should accept true-ish and
false-ish values (when not None) to more closely mirror a pure-Python
implementation. - 41223. By Barry Warsaw
-
* Add __cached__ attribute to modules.
* PyImport_ExecCodeModuleE x() gets a new parameter. - 41224. By Barry Warsaw
-
Remove some unnecessary code.
- 41225. By Barry Warsaw
-
Based on Guido's recommendation, add PyImport_
ExecCodeModuleE xEx() - 41226. By Barry Warsaw
-
trunk merge
- 41227. By Barry Warsaw
-
* PyImport_
ExecCodeModuleE xEx() -> PyImport_ ExecCodeModuleW ithPathnames( )
* Document the above.
* Added PyImport_GetMagicTag( ) and document.
* Removed imp.magic_tags and replaced with imp.get_tag(). - 41228. By Barry Warsaw
-
More responses to Rietveld and mailing list comments. The most important
change here is an additional guard against buffer overflows in
make_compiled_pathname( ). - 41229. By Barry Warsaw
-
trunk merge
- 41230. By Barry Warsaw
-
Patches from Brian Curtin for Windows.
- 41231. By Barry Warsaw
-
Support -b flag for compile to create legacy .pyc files. This does not delete
the source files. - 41232. By Barry Warsaw
-
Document extended compileall options.
- 41233. By Barry Warsaw
-
trunk merge
- 41234. By Barry Warsaw
-
Make sure __cache__ shows up in modules executed via command line and -m
(runpy). Update runpy documentation. - 41235. By Barry Warsaw
-
Typo.
- 41236. By Barry Warsaw
-
trunk merge
- 41237. By Barry Warsaw
-
* abs__file__() -> abs_paths() since this now also modifies m.__cached__
* actually make test_abs_path() not suck. - 41238. By Barry Warsaw
-
trunk merge
- 41239. By Barry Warsaw
-
trunk merge
Preview Diff
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2010-04-11 20:49:28 +0000 | |||
3 | +++ .bzrignore 2010-04-16 18:55:41 +0000 | |||
4 | @@ -33,3 +33,4 @@ | |||
5 | 33 | Lib/test/data/* | 33 | Lib/test/data/* |
6 | 34 | Lib/lib2to3/Grammar*.pickle | 34 | Lib/lib2to3/Grammar*.pickle |
7 | 35 | Lib/lib2to3/PatternGrammar*.pickle | 35 | Lib/lib2to3/PatternGrammar*.pickle |
8 | 36 | __pycache__ | ||
9 | 36 | 37 | ||
10 | === modified file '.hgignore' | |||
11 | --- .hgignore 2010-04-13 16:37:01 +0000 | |||
12 | +++ .hgignore 2010-04-16 18:55:41 +0000 | |||
13 | @@ -54,3 +54,4 @@ | |||
14 | 54 | PCbuild/*.ncb | 54 | PCbuild/*.ncb |
15 | 55 | PCbuild/*.bsc | 55 | PCbuild/*.bsc |
16 | 56 | PCbuild/Win32-temp-* | 56 | PCbuild/Win32-temp-* |
17 | 57 | __pycache__ | ||
18 | 57 | 58 | ||
19 | === modified file 'Doc/c-api/import.rst' | |||
20 | --- Doc/c-api/import.rst 2010-04-11 15:12:57 +0000 | |||
21 | +++ Doc/c-api/import.rst 2010-04-16 18:55:41 +0000 | |||
22 | @@ -124,12 +124,24 @@ | |||
23 | 124 | If *name* points to a dotted name of the form ``package.module``, any package | 124 | If *name* points to a dotted name of the form ``package.module``, any package |
24 | 125 | structures not already created will still not be created. | 125 | structures not already created will still not be created. |
25 | 126 | 126 | ||
26 | 127 | See also :func:`PyImport_ExecCodeModuleEx` and | ||
27 | 128 | :func:`PyImport_ExecCodeModuleWithPathnames`. | ||
28 | 129 | |||
29 | 127 | 130 | ||
30 | 128 | .. cfunction:: PyObject* PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname) | 131 | .. cfunction:: PyObject* PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname) |
31 | 129 | 132 | ||
32 | 130 | Like :cfunc:`PyImport_ExecCodeModule`, but the :attr:`__file__` attribute of | 133 | Like :cfunc:`PyImport_ExecCodeModule`, but the :attr:`__file__` attribute of |
33 | 131 | the module object is set to *pathname* if it is non-``NULL``. | 134 | the module object is set to *pathname* if it is non-``NULL``. |
34 | 132 | 135 | ||
35 | 136 | See also :func:`PyImport_ExecCodeModuleWithPathnames`. | ||
36 | 137 | |||
37 | 138 | |||
38 | 139 | .. cfunction:: PyObject* PyImport_ExecCodeModuleWithPathnames(char *name, PyObject *co, char *pathname, char *cpathname) | ||
39 | 140 | |||
40 | 141 | Like :cfunc:`PyImport_ExecCodeModuleEx`, but the :attr:`__cached__` | ||
41 | 142 | attribute of the module object is set to *cpathname* if it is | ||
42 | 143 | non-``NULL``. Of the three functions, this is the preferred one to use. | ||
43 | 144 | |||
44 | 133 | 145 | ||
45 | 134 | .. cfunction:: long PyImport_GetMagicNumber() | 146 | .. cfunction:: long PyImport_GetMagicNumber() |
46 | 135 | 147 | ||
47 | @@ -138,6 +150,11 @@ | |||
48 | 138 | of the bytecode file, in little-endian byte order. | 150 | of the bytecode file, in little-endian byte order. |
49 | 139 | 151 | ||
50 | 140 | 152 | ||
51 | 153 | .. cfunction:: const char * PyImport_GetMagicTag() | ||
52 | 154 | |||
53 | 155 | Return the magic tag string for :pep:`3147` format Python bytecode file | ||
54 | 156 | names. | ||
55 | 157 | |||
56 | 141 | .. cfunction:: PyObject* PyImport_GetModuleDict() | 158 | .. cfunction:: PyObject* PyImport_GetModuleDict() |
57 | 142 | 159 | ||
58 | 143 | Return the dictionary used for the module administration (a.k.a. | 160 | Return the dictionary used for the module administration (a.k.a. |
59 | 144 | 161 | ||
60 | === modified file 'Doc/library/compileall.rst' | |||
61 | --- Doc/library/compileall.rst 2009-05-17 11:29:12 +0000 | |||
62 | +++ Doc/library/compileall.rst 2010-04-16 18:55:41 +0000 | |||
63 | @@ -17,9 +17,11 @@ | |||
64 | 17 | sys.path``. Printing lists of the files compiled can be disabled with the | 17 | sys.path``. Printing lists of the files compiled can be disabled with the |
65 | 18 | :option:`-q` flag. In addition, the :option:`-x` option takes a regular | 18 | :option:`-q` flag. In addition, the :option:`-x` option takes a regular |
66 | 19 | expression argument. All files that match the expression will be skipped. | 19 | expression argument. All files that match the expression will be skipped. |
70 | 20 | 20 | The :option:`-b` flag may be given to write legacy ``.pyc`` file path names, | |
71 | 21 | 21 | otherwise :pep:`3147` style byte-compiled path names are written. | |
72 | 22 | .. function:: compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None, quiet=False) | 22 | |
73 | 23 | |||
74 | 24 | .. function:: compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None, quiet=False, legacy=False) | ||
75 | 23 | 25 | ||
76 | 24 | Recursively descend the directory tree named by *dir*, compiling all :file:`.py` | 26 | Recursively descend the directory tree named by *dir*, compiling all :file:`.py` |
77 | 25 | files along the way. The *maxlevels* parameter is used to limit the depth of | 27 | files along the way. The *maxlevels* parameter is used to limit the depth of |
78 | @@ -34,12 +36,16 @@ | |||
79 | 34 | If *quiet* is true, nothing is printed to the standard output in normal | 36 | If *quiet* is true, nothing is printed to the standard output in normal |
80 | 35 | operation. | 37 | operation. |
81 | 36 | 38 | ||
84 | 37 | 39 | If *legacy* is true, old-style ``.pyc`` file path names are written, | |
85 | 38 | .. function:: compile_path(skip_curdir=True, maxlevels=0, force=False) | 40 | otherwise (the default), :pep:`3147` style path names are written. |
86 | 41 | |||
87 | 42 | |||
88 | 43 | .. function:: compile_path(skip_curdir=True, maxlevels=0, force=False, legacy=False) | ||
89 | 39 | 44 | ||
90 | 40 | Byte-compile all the :file:`.py` files found along ``sys.path``. If | 45 | Byte-compile all the :file:`.py` files found along ``sys.path``. If |
91 | 41 | *skip_curdir* is true (the default), the current directory is not included in | 46 | *skip_curdir* is true (the default), the current directory is not included in |
93 | 42 | the search. The *maxlevels* and *force* parameters default to ``0`` and are | 47 | the search. The *maxlevels* parameter defaults to ``0``, and the *force* |
94 | 48 | and *legacy* parameters default to ``False``. All are | ||
95 | 43 | passed to the :func:`compile_dir` function. | 49 | passed to the :func:`compile_dir` function. |
96 | 44 | 50 | ||
97 | 45 | To force a recompile of all the :file:`.py` files in the :file:`Lib/` | 51 | To force a recompile of all the :file:`.py` files in the :file:`Lib/` |
98 | 46 | 52 | ||
99 | === modified file 'Doc/library/imp.rst' | |||
100 | --- Doc/library/imp.rst 2009-07-17 09:42:05 +0000 | |||
101 | +++ Doc/library/imp.rst 2010-04-16 18:55:41 +0000 | |||
102 | @@ -204,8 +204,41 @@ | |||
103 | 204 | function does nothing. | 204 | function does nothing. |
104 | 205 | 205 | ||
105 | 206 | 206 | ||
108 | 207 | The following constants with integer values, defined in this module, are used to | 207 | The following functions and data provide conveniences for handling :pep:`3147` |
109 | 208 | indicate the search result of :func:`find_module`. | 208 | byte-compiled file paths. |
110 | 209 | |||
111 | 210 | .. versionadded:: 3.2 | ||
112 | 211 | |||
113 | 212 | .. function:: cache_from_source(path, debug_override=None) | ||
114 | 213 | |||
115 | 214 | Return the PEP 3147 path to the byte-compiled file associated with the | ||
116 | 215 | source *path*. For example, if *path* is ``/foo/bar/baz.py`` the return | ||
117 | 216 | value would be ``/foo/bar/__pycache__/baz.cpython-32.pyc`` for Python 3.2. | ||
118 | 217 | The ``cpython-32`` string comes from the current magic tag (see | ||
119 | 218 | :func:`get_tag`). The returned path will end in ``.pyc`` when | ||
120 | 219 | ``__debug__`` is True or ``.pyo`` for an optimized Python | ||
121 | 220 | (i.e. ``__debug__`` is False). By passing in True or False for | ||
122 | 221 | *debug_override* you can override the system's value for ``__debug__`` for | ||
123 | 222 | extension selection. | ||
124 | 223 | |||
125 | 224 | *path* need not exist. | ||
126 | 225 | |||
127 | 226 | .. function:: source_from_cache(path) | ||
128 | 227 | |||
129 | 228 | Given the *path* to a PEP 3147 file name, return the associated source code | ||
130 | 229 | file path. For example, if *path* is | ||
131 | 230 | ``/foo/bar/__pycache__/baz.cpython-32.pyc`` the returned path would be | ||
132 | 231 | ``/foo/bar/baz.py``. *path* need not exist, however if it does not conform | ||
133 | 232 | to PEP 3147 format, a ``ValueError`` is raised. | ||
134 | 233 | |||
135 | 234 | .. function:: get_tag() | ||
136 | 235 | |||
137 | 236 | Return the PEP 3147 magic tag string matching this version of Python's | ||
138 | 237 | magic number, as returned by :func:`get_magic`. | ||
139 | 238 | |||
140 | 239 | |||
141 | 240 | The following constants with integer values, defined in this module, are used | ||
142 | 241 | to indicate the search result of :func:`find_module`. | ||
143 | 209 | 242 | ||
144 | 210 | 243 | ||
145 | 211 | .. data:: PY_SOURCE | 244 | .. data:: PY_SOURCE |
146 | 212 | 245 | ||
147 | === modified file 'Doc/library/py_compile.rst' | |||
148 | --- Doc/library/py_compile.rst 2009-09-02 19:34:52 +0000 | |||
149 | +++ Doc/library/py_compile.rst 2010-04-16 18:55:41 +0000 | |||
150 | @@ -26,12 +26,16 @@ | |||
151 | 26 | 26 | ||
152 | 27 | Compile a source file to byte-code and write out the byte-code cache file. The | 27 | Compile a source file to byte-code and write out the byte-code cache file. The |
153 | 28 | source code is loaded from the file name *file*. The byte-code is written to | 28 | source code is loaded from the file name *file*. The byte-code is written to |
156 | 29 | *cfile*, which defaults to *file* ``+`` ``'c'`` (``'o'`` if optimization is | 29 | *cfile*, which defaults to the :PEP:`3147` path, ending in ``.pyc`` |
157 | 30 | enabled in the current interpreter). If *dfile* is specified, it is used as the | 30 | (``'.pyo`` if optimization is enabled in the current interpreter). For |
158 | 31 | example, if *file* is ``/foo/bar/baz.py`` *cfile* will default to | ||
159 | 32 | ``/foo/bar/__pycache__/baz.cpython-32.pyc`` for Python 3.2. If *dfile* is specified, it is used as the | ||
160 | 31 | name of the source file in error messages instead of *file*. If *doraise* is | 33 | name of the source file in error messages instead of *file*. If *doraise* is |
161 | 32 | true, a :exc:`PyCompileError` is raised when an error is encountered while | 34 | true, a :exc:`PyCompileError` is raised when an error is encountered while |
162 | 33 | compiling *file*. If *doraise* is false (the default), an error string is | 35 | compiling *file*. If *doraise* is false (the default), an error string is |
164 | 34 | written to ``sys.stderr``, but no exception is raised. | 36 | written to ``sys.stderr``, but no exception is raised. This function |
165 | 37 | returns the path to byte-compiled file, i.e. whatever *cfile* value was | ||
166 | 38 | used. | ||
167 | 35 | 39 | ||
168 | 36 | 40 | ||
169 | 37 | .. function:: main(args=None) | 41 | .. function:: main(args=None) |
170 | 38 | 42 | ||
171 | === modified file 'Doc/library/runpy.rst' | |||
172 | --- Doc/library/runpy.rst 2010-01-04 09:29:10 +0000 | |||
173 | +++ Doc/library/runpy.rst 2010-04-16 18:55:41 +0000 | |||
174 | @@ -32,7 +32,8 @@ | |||
175 | 32 | below are defined in the supplied dictionary, those definitions are | 32 | below are defined in the supplied dictionary, those definitions are |
176 | 33 | overridden by :func:`run_module`. | 33 | overridden by :func:`run_module`. |
177 | 34 | 34 | ||
179 | 35 | The special global variables ``__name__``, ``__file__``, ``__loader__`` | 35 | The special global variables ``__name__``, ``__file__``, ``__cached__``, |
180 | 36 | ``__loader__`` | ||
181 | 36 | and ``__package__`` are set in the globals dictionary before the module | 37 | and ``__package__`` are set in the globals dictionary before the module |
182 | 37 | code is executed (Note that this is a minimal set of variables - other | 38 | code is executed (Note that this is a minimal set of variables - other |
183 | 38 | variables may be set implicitly as an interpreter implementation detail). | 39 | variables may be set implicitly as an interpreter implementation detail). |
184 | @@ -45,6 +46,8 @@ | |||
185 | 45 | loader does not make filename information available, this variable is set | 46 | loader does not make filename information available, this variable is set |
186 | 46 | to :const:`None`. | 47 | to :const:`None`. |
187 | 47 | 48 | ||
188 | 49 | ``__cached__`` will be set to ``None``. | ||
189 | 50 | |||
190 | 48 | ``__loader__`` is set to the PEP 302 module loader used to retrieve the | 51 | ``__loader__`` is set to the PEP 302 module loader used to retrieve the |
191 | 49 | code for the module (This loader may be a wrapper around the standard | 52 | code for the module (This loader may be a wrapper around the standard |
192 | 50 | import mechanism). | 53 | import mechanism). |
193 | 51 | 54 | ||
194 | === modified file 'Include/import.h' | |||
195 | --- Include/import.h 2009-10-04 19:32:25 +0000 | |||
196 | +++ Include/import.h 2010-04-16 18:55:41 +0000 | |||
197 | @@ -8,9 +8,12 @@ | |||
198 | 8 | #endif | 8 | #endif |
199 | 9 | 9 | ||
200 | 10 | PyAPI_FUNC(long) PyImport_GetMagicNumber(void); | 10 | PyAPI_FUNC(long) PyImport_GetMagicNumber(void); |
201 | 11 | PyAPI_FUNC(const char *) PyImport_GetMagicTag(void); | ||
202 | 11 | PyAPI_FUNC(PyObject *) PyImport_ExecCodeModule(char *name, PyObject *co); | 12 | PyAPI_FUNC(PyObject *) PyImport_ExecCodeModule(char *name, PyObject *co); |
203 | 12 | PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleEx( | 13 | PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleEx( |
204 | 13 | char *name, PyObject *co, char *pathname); | 14 | char *name, PyObject *co, char *pathname); |
205 | 15 | PyAPI_FUNC(PyObject *) PyImport_ExecCodeModuleWithPathnames( | ||
206 | 16 | char *name, PyObject *co, char *pathname, char *cpathname); | ||
207 | 14 | PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void); | 17 | PyAPI_FUNC(PyObject *) PyImport_GetModuleDict(void); |
208 | 15 | PyAPI_FUNC(PyObject *) PyImport_AddModule(const char *name); | 18 | PyAPI_FUNC(PyObject *) PyImport_AddModule(const char *name); |
209 | 16 | PyAPI_FUNC(PyObject *) PyImport_ImportModule(const char *name); | 19 | PyAPI_FUNC(PyObject *) PyImport_ImportModule(const char *name); |
210 | 17 | 20 | ||
211 | === modified file 'Lib/compileall.py' | |||
212 | --- Lib/compileall.py 2010-03-21 23:13:07 +0000 | |||
213 | +++ Lib/compileall.py 2010-04-16 18:55:41 +0000 | |||
214 | @@ -12,6 +12,7 @@ | |||
215 | 12 | 12 | ||
216 | 13 | """ | 13 | """ |
217 | 14 | import os | 14 | import os |
218 | 15 | import errno | ||
219 | 15 | import sys | 16 | import sys |
220 | 16 | import py_compile | 17 | import py_compile |
221 | 17 | import struct | 18 | import struct |
222 | @@ -20,7 +21,7 @@ | |||
223 | 20 | __all__ = ["compile_dir","compile_file","compile_path"] | 21 | __all__ = ["compile_dir","compile_file","compile_path"] |
224 | 21 | 22 | ||
225 | 22 | def compile_dir(dir, maxlevels=10, ddir=None, | 23 | def compile_dir(dir, maxlevels=10, ddir=None, |
227 | 23 | force=0, rx=None, quiet=0): | 24 | force=False, rx=None, quiet=False, legacy=False): |
228 | 24 | """Byte-compile all modules in the given directory tree. | 25 | """Byte-compile all modules in the given directory tree. |
229 | 25 | 26 | ||
230 | 26 | Arguments (only dir is required): | 27 | Arguments (only dir is required): |
231 | @@ -29,8 +30,9 @@ | |||
232 | 29 | maxlevels: maximum recursion level (default 10) | 30 | maxlevels: maximum recursion level (default 10) |
233 | 30 | ddir: if given, purported directory name (this is the | 31 | ddir: if given, purported directory name (this is the |
234 | 31 | directory name that will show up in error messages) | 32 | directory name that will show up in error messages) |
237 | 32 | force: if 1, force compilation, even if timestamps are up-to-date | 33 | force: if True, force compilation, even if timestamps are up-to-date |
238 | 33 | quiet: if 1, be quiet during compilation | 34 | quiet: if True, be quiet during compilation |
239 | 35 | legacy: if True, produce legacy pyc paths instead of PEP 3147 paths | ||
240 | 34 | 36 | ||
241 | 35 | """ | 37 | """ |
242 | 36 | if not quiet: | 38 | if not quiet: |
243 | @@ -49,24 +51,26 @@ | |||
244 | 49 | else: | 51 | else: |
245 | 50 | dfile = None | 52 | dfile = None |
246 | 51 | if not os.path.isdir(fullname): | 53 | if not os.path.isdir(fullname): |
248 | 52 | if not compile_file(fullname, ddir, force, rx, quiet): | 54 | if not compile_file(fullname, ddir, force, rx, quiet, legacy): |
249 | 53 | success = 0 | 55 | success = 0 |
250 | 54 | elif maxlevels > 0 and \ | 56 | elif maxlevels > 0 and \ |
251 | 55 | name != os.curdir and name != os.pardir and \ | 57 | name != os.curdir and name != os.pardir and \ |
252 | 56 | os.path.isdir(fullname) and \ | 58 | os.path.isdir(fullname) and \ |
253 | 57 | not os.path.islink(fullname): | 59 | not os.path.islink(fullname): |
254 | 58 | if not compile_dir(fullname, maxlevels - 1, dfile, force, rx, | 60 | if not compile_dir(fullname, maxlevels - 1, dfile, force, rx, |
256 | 59 | quiet): | 61 | quiet, legacy): |
257 | 60 | success = 0 | 62 | success = 0 |
258 | 61 | return success | 63 | return success |
259 | 62 | 64 | ||
261 | 63 | def compile_file(fullname, ddir=None, force=0, rx=None, quiet=0): | 65 | def compile_file(fullname, ddir=None, force=0, rx=None, quiet=False, |
262 | 66 | legacy=False): | ||
263 | 64 | """Byte-compile file. | 67 | """Byte-compile file. |
265 | 65 | file: the file to byte-compile | 68 | fullname: the file to byte-compile |
266 | 66 | ddir: if given, purported directory name (this is the | 69 | ddir: if given, purported directory name (this is the |
267 | 67 | directory name that will show up in error messages) | 70 | directory name that will show up in error messages) |
270 | 68 | force: if 1, force compilation, even if timestamps are up-to-date | 71 | force: if True, force compilation, even if timestamps are up-to-date |
271 | 69 | quiet: if 1, be quiet during compilation | 72 | quiet: if True, be quiet during compilation |
272 | 73 | legacy: if True, produce legacy pyc paths instead of PEP 3147 paths | ||
273 | 70 | 74 | ||
274 | 71 | """ | 75 | """ |
275 | 72 | success = 1 | 76 | success = 1 |
276 | @@ -80,13 +84,22 @@ | |||
277 | 80 | if mo: | 84 | if mo: |
278 | 81 | return success | 85 | return success |
279 | 82 | if os.path.isfile(fullname): | 86 | if os.path.isfile(fullname): |
280 | 87 | if legacy: | ||
281 | 88 | cfile = fullname + ('c' if __debug__ else 'o') | ||
282 | 89 | else: | ||
283 | 90 | cfile = imp.cache_from_source(fullname) | ||
284 | 91 | cache_dir = os.path.dirname(cfile) | ||
285 | 92 | try: | ||
286 | 93 | os.mkdir(cache_dir) | ||
287 | 94 | except OSError as error: | ||
288 | 95 | if error.errno != errno.EEXIST: | ||
289 | 96 | raise | ||
290 | 83 | head, tail = name[:-3], name[-3:] | 97 | head, tail = name[:-3], name[-3:] |
291 | 84 | if tail == '.py': | 98 | if tail == '.py': |
292 | 85 | if not force: | 99 | if not force: |
293 | 86 | try: | 100 | try: |
294 | 87 | mtime = int(os.stat(fullname).st_mtime) | 101 | mtime = int(os.stat(fullname).st_mtime) |
295 | 88 | expect = struct.pack('<4sl', imp.get_magic(), mtime) | 102 | expect = struct.pack('<4sl', imp.get_magic(), mtime) |
296 | 89 | cfile = fullname + (__debug__ and 'c' or 'o') | ||
297 | 90 | with open(cfile, 'rb') as chandle: | 103 | with open(cfile, 'rb') as chandle: |
298 | 91 | actual = chandle.read(8) | 104 | actual = chandle.read(8) |
299 | 92 | if expect == actual: | 105 | if expect == actual: |
300 | @@ -96,14 +109,15 @@ | |||
301 | 96 | if not quiet: | 109 | if not quiet: |
302 | 97 | print('Compiling', fullname, '...') | 110 | print('Compiling', fullname, '...') |
303 | 98 | try: | 111 | try: |
305 | 99 | ok = py_compile.compile(fullname, None, dfile, True) | 112 | ok = py_compile.compile(fullname, cfile, dfile, True) |
306 | 100 | except py_compile.PyCompileError as err: | 113 | except py_compile.PyCompileError as err: |
307 | 101 | if quiet: | 114 | if quiet: |
308 | 102 | print('*** Error compiling', fullname, '...') | 115 | print('*** Error compiling', fullname, '...') |
309 | 103 | else: | 116 | else: |
310 | 104 | print('*** ', end='') | 117 | print('*** ', end='') |
311 | 105 | # escape non-printable characters in msg | 118 | # escape non-printable characters in msg |
313 | 106 | msg = err.msg.encode(sys.stdout.encoding, errors='backslashreplace') | 119 | msg = err.msg.encode(sys.stdout.encoding, |
314 | 120 | errors='backslashreplace') | ||
315 | 107 | msg = msg.decode(sys.stdout.encoding) | 121 | msg = msg.decode(sys.stdout.encoding) |
316 | 108 | print(msg) | 122 | print(msg) |
317 | 109 | success = 0 | 123 | success = 0 |
318 | @@ -119,15 +133,17 @@ | |||
319 | 119 | success = 0 | 133 | success = 0 |
320 | 120 | return success | 134 | return success |
321 | 121 | 135 | ||
323 | 122 | def compile_path(skip_curdir=1, maxlevels=0, force=0, quiet=0): | 136 | def compile_path(skip_curdir=1, maxlevels=0, force=False, quiet=False, |
324 | 137 | legacy=False): | ||
325 | 123 | """Byte-compile all module on sys.path. | 138 | """Byte-compile all module on sys.path. |
326 | 124 | 139 | ||
327 | 125 | Arguments (all optional): | 140 | Arguments (all optional): |
328 | 126 | 141 | ||
329 | 127 | skip_curdir: if true, skip current directory (default true) | 142 | skip_curdir: if true, skip current directory (default true) |
330 | 128 | maxlevels: max recursion level (default 0) | 143 | maxlevels: max recursion level (default 0) |
333 | 129 | force: as for compile_dir() (default 0) | 144 | force: as for compile_dir() (default False) |
334 | 130 | quiet: as for compile_dir() (default 0) | 145 | quiet: as for compile_dir() (default False) |
335 | 146 | legacy: as for compile_dir() (default False) | ||
336 | 131 | 147 | ||
337 | 132 | """ | 148 | """ |
338 | 133 | success = 1 | 149 | success = 1 |
339 | @@ -136,7 +152,8 @@ | |||
340 | 136 | print('Skipping current directory') | 152 | print('Skipping current directory') |
341 | 137 | else: | 153 | else: |
342 | 138 | success = success and compile_dir(dir, maxlevels, None, | 154 | success = success and compile_dir(dir, maxlevels, None, |
344 | 139 | force, quiet=quiet) | 155 | force, quiet=quiet, |
345 | 156 | legacy=legacy) | ||
346 | 140 | return success | 157 | return success |
347 | 141 | 158 | ||
348 | 142 | def expand_args(args, flist): | 159 | def expand_args(args, flist): |
349 | @@ -162,10 +179,10 @@ | |||
350 | 162 | """Script main program.""" | 179 | """Script main program.""" |
351 | 163 | import getopt | 180 | import getopt |
352 | 164 | try: | 181 | try: |
354 | 165 | opts, args = getopt.getopt(sys.argv[1:], 'lfqd:x:i:') | 182 | opts, args = getopt.getopt(sys.argv[1:], 'lfqd:x:i:b') |
355 | 166 | except getopt.error as msg: | 183 | except getopt.error as msg: |
356 | 167 | print(msg) | 184 | print(msg) |
358 | 168 | print("usage: python compileall.py [-l] [-f] [-q] [-d destdir] " \ | 185 | print("usage: python compileall.py [-l] [-f] [-q] [-d destdir] " |
359 | 169 | "[-x regexp] [-i list] [directory|file ...]") | 186 | "[-x regexp] [-i list] [directory|file ...]") |
360 | 170 | print("-l: don't recurse down") | 187 | print("-l: don't recurse down") |
361 | 171 | print("-f: force rebuild even if timestamps are up-to-date") | 188 | print("-f: force rebuild even if timestamps are up-to-date") |
362 | @@ -174,23 +191,27 @@ | |||
363 | 174 | print(" if no directory arguments, -l sys.path is assumed") | 191 | print(" if no directory arguments, -l sys.path is assumed") |
364 | 175 | print("-x regexp: skip files matching the regular expression regexp") | 192 | print("-x regexp: skip files matching the regular expression regexp") |
365 | 176 | print(" the regexp is searched for in the full path of the file") | 193 | print(" the regexp is searched for in the full path of the file") |
367 | 177 | print("-i list: expand list with its content (file and directory names)") | 194 | print("-i list: expand list with its content " |
368 | 195 | "(file and directory names)") | ||
369 | 196 | print("-b: Produce legacy byte-compile file paths") | ||
370 | 178 | sys.exit(2) | 197 | sys.exit(2) |
371 | 179 | maxlevels = 10 | 198 | maxlevels = 10 |
372 | 180 | ddir = None | 199 | ddir = None |
375 | 181 | force = 0 | 200 | force = False |
376 | 182 | quiet = 0 | 201 | quiet = False |
377 | 183 | rx = None | 202 | rx = None |
378 | 184 | flist = None | 203 | flist = None |
379 | 204 | legacy = False | ||
380 | 185 | for o, a in opts: | 205 | for o, a in opts: |
381 | 186 | if o == '-l': maxlevels = 0 | 206 | if o == '-l': maxlevels = 0 |
382 | 187 | if o == '-d': ddir = a | 207 | if o == '-d': ddir = a |
385 | 188 | if o == '-f': force = 1 | 208 | if o == '-f': force = True |
386 | 189 | if o == '-q': quiet = 1 | 209 | if o == '-q': quiet = True |
387 | 190 | if o == '-x': | 210 | if o == '-x': |
388 | 191 | import re | 211 | import re |
389 | 192 | rx = re.compile(a) | 212 | rx = re.compile(a) |
390 | 193 | if o == '-i': flist = a | 213 | if o == '-i': flist = a |
391 | 214 | if o == '-b': legacy = True | ||
392 | 194 | if ddir: | 215 | if ddir: |
393 | 195 | if len(args) != 1 and not os.path.isdir(args[0]): | 216 | if len(args) != 1 and not os.path.isdir(args[0]): |
394 | 196 | print("-d destdir require exactly one directory argument") | 217 | print("-d destdir require exactly one directory argument") |
395 | @@ -207,13 +228,14 @@ | |||
396 | 207 | for arg in args: | 228 | for arg in args: |
397 | 208 | if os.path.isdir(arg): | 229 | if os.path.isdir(arg): |
398 | 209 | if not compile_dir(arg, maxlevels, ddir, | 230 | if not compile_dir(arg, maxlevels, ddir, |
400 | 210 | force, rx, quiet): | 231 | force, rx, quiet, legacy): |
401 | 211 | success = 0 | 232 | success = 0 |
402 | 212 | else: | 233 | else: |
404 | 213 | if not compile_file(arg, ddir, force, rx, quiet): | 234 | if not compile_file(arg, ddir, force, rx, |
405 | 235 | quiet, legacy): | ||
406 | 214 | success = 0 | 236 | success = 0 |
407 | 215 | else: | 237 | else: |
409 | 216 | success = compile_path() | 238 | success = compile_path(legacy=legacy) |
410 | 217 | except KeyboardInterrupt: | 239 | except KeyboardInterrupt: |
411 | 218 | print("\n[interrupt]") | 240 | print("\n[interrupt]") |
412 | 219 | success = 0 | 241 | success = 0 |
413 | 220 | 242 | ||
414 | === modified file 'Lib/importlib/_bootstrap.py' | |||
415 | --- Lib/importlib/_bootstrap.py 2010-03-19 20:44:28 +0000 | |||
416 | +++ Lib/importlib/_bootstrap.py 2010-04-16 18:55:41 +0000 | |||
417 | @@ -488,6 +488,16 @@ | |||
418 | 488 | 488 | ||
419 | 489 | """Load a module from a source or bytecode file.""" | 489 | """Load a module from a source or bytecode file.""" |
420 | 490 | 490 | ||
421 | 491 | def _find_path(self, ext_type): | ||
422 | 492 | """Return PEP 3147 path if ext_type is PY_COMPILED, otherwise | ||
423 | 493 | super()._find_path() is called.""" | ||
424 | 494 | if ext_type == imp.PY_COMPILED: | ||
425 | 495 | # We don't really care what the extension on self._base_path is, | ||
426 | 496 | # as long as it has exactly one dot. | ||
427 | 497 | bytecode_path = imp.cache_from_source(self._base_path + '.py') | ||
428 | 498 | return (bytecode_path if _path_exists(bytecode_path) else None) | ||
429 | 499 | return super()._find_path(ext_type) | ||
430 | 500 | |||
431 | 491 | @_check_name | 501 | @_check_name |
432 | 492 | def source_mtime(self, name): | 502 | def source_mtime(self, name): |
433 | 493 | """Return the modification time of the source for the specified | 503 | """Return the modification time of the source for the specified |
434 | @@ -515,7 +525,16 @@ | |||
435 | 515 | """ | 525 | """ |
436 | 516 | bytecode_path = self.bytecode_path(name) | 526 | bytecode_path = self.bytecode_path(name) |
437 | 517 | if not bytecode_path: | 527 | if not bytecode_path: |
439 | 518 | bytecode_path = self._base_path + _suffix_list(imp.PY_COMPILED)[0] | 528 | source_path = self.source_path(name) |
440 | 529 | bytecode_path = imp.cache_from_source(source_path) | ||
441 | 530 | # Ensure that the __pycache__ directory exists. We can't use | ||
442 | 531 | # os.path.dirname() here. | ||
443 | 532 | dirname, sep, basename = bytecode_path.rpartition(path_sep) | ||
444 | 533 | try: | ||
445 | 534 | _os.mkdir(dirname) | ||
446 | 535 | except OSError as error: | ||
447 | 536 | if error.errno != errno.EEXIST: | ||
448 | 537 | raise | ||
449 | 519 | try: | 538 | try: |
450 | 520 | # Assuming bytes. | 539 | # Assuming bytes. |
451 | 521 | with _closing(_io.FileIO(bytecode_path, 'w')) as bytecode_file: | 540 | with _closing(_io.FileIO(bytecode_path, 'w')) as bytecode_file: |
452 | 522 | 541 | ||
453 | === modified file 'Lib/importlib/test/__main__.py' | |||
454 | --- Lib/importlib/test/__main__.py 2010-03-19 20:44:28 +0000 | |||
455 | +++ Lib/importlib/test/__main__.py 2010-04-16 18:55:41 +0000 | |||
456 | @@ -13,7 +13,12 @@ | |||
457 | 13 | 13 | ||
458 | 14 | 14 | ||
459 | 15 | def test_main(): | 15 | def test_main(): |
461 | 16 | start_dir = os.path.dirname(__file__) | 16 | if '__pycache__' in __file__: |
462 | 17 | parts = __file__.split(os.path.sep) | ||
463 | 18 | start_dir = sep.join(parts[:-2]) | ||
464 | 19 | else: | ||
465 | 20 | start_dir = os.path.dirname(__file__) | ||
466 | 21 | # XXX 2010-03-18 barry: Fix __file__ | ||
467 | 17 | top_dir = os.path.dirname(os.path.dirname(start_dir)) | 22 | top_dir = os.path.dirname(os.path.dirname(start_dir)) |
468 | 18 | test_loader = unittest.TestLoader() | 23 | test_loader = unittest.TestLoader() |
469 | 19 | if '--builtin' in sys.argv: | 24 | if '--builtin' in sys.argv: |
470 | 20 | 25 | ||
471 | === modified file 'Lib/importlib/test/source/test_file_loader.py' | |||
472 | --- Lib/importlib/test/source/test_file_loader.py 2010-03-19 20:44:28 +0000 | |||
473 | +++ Lib/importlib/test/source/test_file_loader.py 2010-04-16 18:55:41 +0000 | |||
474 | @@ -127,7 +127,7 @@ | |||
475 | 127 | except KeyError: | 127 | except KeyError: |
476 | 128 | pass | 128 | pass |
477 | 129 | py_compile.compile(mapping[name]) | 129 | py_compile.compile(mapping[name]) |
479 | 130 | bytecode_path = source_util.bytecode_path(mapping[name]) | 130 | bytecode_path = imp.cache_from_source(mapping[name]) |
480 | 131 | with open(bytecode_path, 'rb') as file: | 131 | with open(bytecode_path, 'rb') as file: |
481 | 132 | bc = file.read() | 132 | bc = file.read() |
482 | 133 | new_bc = manipulator(bc) | 133 | new_bc = manipulator(bc) |
483 | @@ -226,7 +226,7 @@ | |||
484 | 226 | zeros = b'\x00\x00\x00\x00' | 226 | zeros = b'\x00\x00\x00\x00' |
485 | 227 | with source_util.create_modules('_temp') as mapping: | 227 | with source_util.create_modules('_temp') as mapping: |
486 | 228 | py_compile.compile(mapping['_temp']) | 228 | py_compile.compile(mapping['_temp']) |
488 | 229 | bytecode_path = source_util.bytecode_path(mapping['_temp']) | 229 | bytecode_path = imp.cache_from_source(mapping['_temp']) |
489 | 230 | with open(bytecode_path, 'r+b') as bytecode_file: | 230 | with open(bytecode_path, 'r+b') as bytecode_file: |
490 | 231 | bytecode_file.seek(4) | 231 | bytecode_file.seek(4) |
491 | 232 | bytecode_file.write(zeros) | 232 | bytecode_file.write(zeros) |
492 | @@ -242,9 +242,10 @@ | |||
493 | 242 | def test_bad_marshal(self): | 242 | def test_bad_marshal(self): |
494 | 243 | # Bad marshal data should raise a ValueError. | 243 | # Bad marshal data should raise a ValueError. |
495 | 244 | with source_util.create_modules('_temp') as mapping: | 244 | with source_util.create_modules('_temp') as mapping: |
497 | 245 | bytecode_path = source_util.bytecode_path(mapping['_temp']) | 245 | bytecode_path = imp.cache_from_source(mapping['_temp']) |
498 | 246 | source_mtime = os.path.getmtime(mapping['_temp']) | 246 | source_mtime = os.path.getmtime(mapping['_temp']) |
499 | 247 | source_timestamp = importlib._w_long(source_mtime) | 247 | source_timestamp = importlib._w_long(source_mtime) |
500 | 248 | source_util.ensure_bytecode_path(bytecode_path) | ||
501 | 248 | with open(bytecode_path, 'wb') as bytecode_file: | 249 | with open(bytecode_path, 'wb') as bytecode_file: |
502 | 249 | bytecode_file.write(imp.get_magic()) | 250 | bytecode_file.write(imp.get_magic()) |
503 | 250 | bytecode_file.write(source_timestamp) | 251 | bytecode_file.write(source_timestamp) |
504 | @@ -260,7 +261,7 @@ | |||
505 | 260 | with source_util.create_modules('_temp') as mapping: | 261 | with source_util.create_modules('_temp') as mapping: |
506 | 261 | # Create bytecode that will need to be re-created. | 262 | # Create bytecode that will need to be re-created. |
507 | 262 | py_compile.compile(mapping['_temp']) | 263 | py_compile.compile(mapping['_temp']) |
509 | 263 | bytecode_path = source_util.bytecode_path(mapping['_temp']) | 264 | bytecode_path = imp.cache_from_source(mapping['_temp']) |
510 | 264 | with open(bytecode_path, 'r+b') as bytecode_file: | 265 | with open(bytecode_path, 'r+b') as bytecode_file: |
511 | 265 | bytecode_file.seek(0) | 266 | bytecode_file.seek(0) |
512 | 266 | bytecode_file.write(b'\x00\x00\x00\x00') | 267 | bytecode_file.write(b'\x00\x00\x00\x00') |
513 | 267 | 268 | ||
514 | === modified file 'Lib/importlib/test/source/test_finder.py' | |||
515 | --- Lib/importlib/test/source/test_finder.py 2010-03-19 20:44:28 +0000 | |||
516 | +++ Lib/importlib/test/source/test_finder.py 2010-04-16 18:55:41 +0000 | |||
517 | @@ -1,7 +1,9 @@ | |||
518 | 1 | from importlib import _bootstrap | 1 | from importlib import _bootstrap |
519 | 2 | from .. import abc | 2 | from .. import abc |
520 | 3 | from . import util as source_util | 3 | from . import util as source_util |
521 | 4 | from test.support import make_legacy_pyc | ||
522 | 4 | import os | 5 | import os |
523 | 6 | import errno | ||
524 | 5 | import py_compile | 7 | import py_compile |
525 | 6 | import unittest | 8 | import unittest |
526 | 7 | import warnings | 9 | import warnings |
527 | @@ -52,6 +54,14 @@ | |||
528 | 52 | if unlink: | 54 | if unlink: |
529 | 53 | for name in unlink: | 55 | for name in unlink: |
530 | 54 | os.unlink(mapping[name]) | 56 | os.unlink(mapping[name]) |
531 | 57 | try: | ||
532 | 58 | make_legacy_pyc(mapping[name]) | ||
533 | 59 | except OSError as error: | ||
534 | 60 | # Some tests do not set compile_=True so the source | ||
535 | 61 | # module will not get compiled and there will be no | ||
536 | 62 | # PEP 3147 pyc file to rename. | ||
537 | 63 | if error.errno != errno.ENOENT: | ||
538 | 64 | raise | ||
539 | 55 | loader = self.import_(mapping['.root'], test) | 65 | loader = self.import_(mapping['.root'], test) |
540 | 56 | self.assertTrue(hasattr(loader, 'load_module')) | 66 | self.assertTrue(hasattr(loader, 'load_module')) |
541 | 57 | return loader | 67 | return loader |
542 | @@ -60,7 +70,8 @@ | |||
543 | 60 | # [top-level source] | 70 | # [top-level source] |
544 | 61 | self.run_test('top_level') | 71 | self.run_test('top_level') |
545 | 62 | # [top-level bc] | 72 | # [top-level bc] |
547 | 63 | self.run_test('top_level', compile_={'top_level'}, unlink={'top_level'}) | 73 | self.run_test('top_level', compile_={'top_level'}, |
548 | 74 | unlink={'top_level'}) | ||
549 | 64 | # [top-level both] | 75 | # [top-level both] |
550 | 65 | self.run_test('top_level', compile_={'top_level'}) | 76 | self.run_test('top_level', compile_={'top_level'}) |
551 | 66 | 77 | ||
552 | 67 | 78 | ||
553 | === modified file 'Lib/importlib/test/source/test_source_encoding.py' | |||
554 | --- Lib/importlib/test/source/test_source_encoding.py 2010-03-19 20:44:28 +0000 | |||
555 | +++ Lib/importlib/test/source/test_source_encoding.py 2010-04-16 18:55:41 +0000 | |||
556 | @@ -33,7 +33,7 @@ | |||
557 | 33 | 33 | ||
558 | 34 | def run_test(self, source): | 34 | def run_test(self, source): |
559 | 35 | with source_util.create_modules(self.module_name) as mapping: | 35 | with source_util.create_modules(self.module_name) as mapping: |
561 | 36 | with open(mapping[self.module_name], 'wb')as file: | 36 | with open(mapping[self.module_name], 'wb') as file: |
562 | 37 | file.write(source) | 37 | file.write(source) |
563 | 38 | loader = _bootstrap._PyPycFileLoader(self.module_name, | 38 | loader = _bootstrap._PyPycFileLoader(self.module_name, |
564 | 39 | mapping[self.module_name], False) | 39 | mapping[self.module_name], False) |
565 | 40 | 40 | ||
566 | === modified file 'Lib/importlib/test/source/util.py' | |||
567 | --- Lib/importlib/test/source/util.py 2010-03-19 20:44:28 +0000 | |||
568 | +++ Lib/importlib/test/source/util.py 2010-04-16 18:55:41 +0000 | |||
569 | @@ -1,5 +1,6 @@ | |||
570 | 1 | from .. import util | 1 | from .. import util |
571 | 2 | import contextlib | 2 | import contextlib |
572 | 3 | import errno | ||
573 | 3 | import functools | 4 | import functools |
574 | 4 | import imp | 5 | import imp |
575 | 5 | import os | 6 | import os |
576 | @@ -26,14 +27,16 @@ | |||
577 | 26 | return wrapper | 27 | return wrapper |
578 | 27 | 28 | ||
579 | 28 | 29 | ||
588 | 29 | def bytecode_path(source_path): | 30 | def ensure_bytecode_path(bytecode_path): |
589 | 30 | for suffix, _, type_ in imp.get_suffixes(): | 31 | """Ensure that the __pycache__ directory for PEP 3147 pyc file exists. |
590 | 31 | if type_ == imp.PY_COMPILED: | 32 | |
591 | 32 | bc_suffix = suffix | 33 | :param bytecode_path: File system path to PEP 3147 pyc file. |
592 | 33 | break | 34 | """ |
593 | 34 | else: | 35 | try: |
594 | 35 | raise ValueError("no bytecode suffix is defined") | 36 | os.mkdir(os.path.dirname(bytecode_path)) |
595 | 36 | return os.path.splitext(source_path)[0] + bc_suffix | 37 | except OSError as error: |
596 | 38 | if error.errno != errno.EEXIST: | ||
597 | 39 | raise | ||
598 | 37 | 40 | ||
599 | 38 | 41 | ||
600 | 39 | @contextlib.contextmanager | 42 | @contextlib.contextmanager |
601 | 40 | 43 | ||
602 | === modified file 'Lib/importlib/util.py' | |||
603 | --- Lib/importlib/util.py 2010-03-19 20:44:28 +0000 | |||
604 | +++ Lib/importlib/util.py 2010-04-16 18:55:41 +0000 | |||
605 | @@ -1,4 +1,5 @@ | |||
606 | 1 | """Utility code for constructing importers, etc.""" | 1 | """Utility code for constructing importers, etc.""" |
607 | 2 | |||
608 | 2 | from ._bootstrap import module_for_loader | 3 | from ._bootstrap import module_for_loader |
609 | 3 | from ._bootstrap import set_loader | 4 | from ._bootstrap import set_loader |
610 | 4 | from ._bootstrap import set_package | 5 | from ._bootstrap import set_package |
611 | 5 | 6 | ||
612 | === modified file 'Lib/inspect.py' | |||
613 | --- Lib/inspect.py 2010-03-30 17:42:32 +0000 | |||
614 | +++ Lib/inspect.py 2010-04-16 18:55:41 +0000 | |||
615 | @@ -54,6 +54,7 @@ | |||
616 | 54 | """Return true if the object is a module. | 54 | """Return true if the object is a module. |
617 | 55 | 55 | ||
618 | 56 | Module objects provide these attributes: | 56 | Module objects provide these attributes: |
619 | 57 | __cached__ pathname to byte compiled file | ||
620 | 57 | __doc__ documentation string | 58 | __doc__ documentation string |
621 | 58 | __file__ filename (missing for built-in modules)""" | 59 | __file__ filename (missing for built-in modules)""" |
622 | 59 | return isinstance(object, types.ModuleType) | 60 | return isinstance(object, types.ModuleType) |
623 | 60 | 61 | ||
624 | === modified file 'Lib/py_compile.py' | |||
625 | --- Lib/py_compile.py 2010-03-31 20:36:22 +0000 | |||
626 | +++ Lib/py_compile.py 2010-04-16 18:55:41 +0000 | |||
627 | @@ -4,6 +4,7 @@ | |||
628 | 4 | """ | 4 | """ |
629 | 5 | 5 | ||
630 | 6 | import builtins | 6 | import builtins |
631 | 7 | import errno | ||
632 | 7 | import imp | 8 | import imp |
633 | 8 | import marshal | 9 | import marshal |
634 | 9 | import os | 10 | import os |
635 | @@ -37,16 +38,18 @@ | |||
636 | 37 | can be accesses as class variable 'file' | 38 | can be accesses as class variable 'file' |
637 | 38 | 39 | ||
638 | 39 | msg: string message to be written as error message | 40 | msg: string message to be written as error message |
642 | 40 | If no value is given, a default exception message will be given, | 41 | If no value is given, a default exception message will be |
643 | 41 | consistent with 'standard' py_compile output. | 42 | given, consistent with 'standard' py_compile output. |
644 | 42 | message (or default) can be accesses as class variable 'msg' | 43 | message (or default) can be accesses as class variable |
645 | 44 | 'msg' | ||
646 | 43 | 45 | ||
647 | 44 | """ | 46 | """ |
648 | 45 | 47 | ||
649 | 46 | def __init__(self, exc_type, exc_value, file, msg=''): | 48 | def __init__(self, exc_type, exc_value, file, msg=''): |
650 | 47 | exc_type_name = exc_type.__name__ | 49 | exc_type_name = exc_type.__name__ |
651 | 48 | if exc_type is SyntaxError: | 50 | if exc_type is SyntaxError: |
653 | 49 | tbtext = ''.join(traceback.format_exception_only(exc_type, exc_value)) | 51 | tbtext = ''.join(traceback.format_exception_only( |
654 | 52 | exc_type, exc_value)) | ||
655 | 50 | errmsg = tbtext.replace('File "<string>"', 'File "%s"' % file) | 53 | errmsg = tbtext.replace('File "<string>"', 'File "%s"' % file) |
656 | 51 | else: | 54 | else: |
657 | 52 | errmsg = "Sorry: %s: %s" % (exc_type_name,exc_value) | 55 | errmsg = "Sorry: %s: %s" % (exc_type_name,exc_value) |
658 | @@ -64,7 +67,7 @@ | |||
659 | 64 | 67 | ||
660 | 65 | def wr_long(f, x): | 68 | def wr_long(f, x): |
661 | 66 | """Internal; write a 32-bit int to a file in little-endian order.""" | 69 | """Internal; write a 32-bit int to a file in little-endian order.""" |
663 | 67 | f.write(bytes([x & 0xff, | 70 | f.write(bytes([x & 0xff, |
664 | 68 | (x >> 8) & 0xff, | 71 | (x >> 8) & 0xff, |
665 | 69 | (x >> 16) & 0xff, | 72 | (x >> 16) & 0xff, |
666 | 70 | (x >> 24) & 0xff])) | 73 | (x >> 24) & 0xff])) |
667 | @@ -72,20 +75,18 @@ | |||
668 | 72 | def compile(file, cfile=None, dfile=None, doraise=False): | 75 | def compile(file, cfile=None, dfile=None, doraise=False): |
669 | 73 | """Byte-compile one Python source file to Python bytecode. | 76 | """Byte-compile one Python source file to Python bytecode. |
670 | 74 | 77 | ||
685 | 75 | Arguments: | 78 | :param file: The source file name. |
686 | 76 | 79 | :param cfile: The target byte compiled file name. When not given, this | |
687 | 77 | file: source filename | 80 | defaults to the PEP 3147 location. |
688 | 78 | cfile: target filename; defaults to source with 'c' or 'o' appended | 81 | :param dfile: Purported file name, i.e. the file name that shows up in |
689 | 79 | ('c' normally, 'o' in optimizing mode, giving .pyc or .pyo) | 82 | error messages. Defaults to the source file name. |
690 | 80 | dfile: purported filename; defaults to source (this is the filename | 83 | :param doraise: Flag indicating whether or not an exception should be |
691 | 81 | that will show up in error messages) | 84 | raised when a compile error is found. If an exception occurs and this |
692 | 82 | doraise: flag indicating whether or not an exception should be | 85 | flag is set to False, a string indicating the nature of the exception |
693 | 83 | raised when a compile error is found. If an exception | 86 | will be printed, and the function will return to the caller. If an |
694 | 84 | occurs and this flag is set to False, a string | 87 | exception occurs and this flag is set to True, a PyCompileError |
695 | 85 | indicating the nature of the exception will be printed, | 88 | exception will be raised. |
696 | 86 | and the function will return to the caller. If an | 89 | :return: Path to the resulting byte compiled file. |
683 | 87 | exception occurs and this flag is set to True, a | ||
684 | 88 | PyCompileError exception will be raised. | ||
697 | 89 | 90 | ||
698 | 90 | Note that it isn't necessary to byte-compile Python modules for | 91 | Note that it isn't necessary to byte-compile Python modules for |
699 | 91 | execution efficiency -- Python itself byte-compiles a module when | 92 | execution efficiency -- Python itself byte-compiles a module when |
700 | @@ -102,7 +103,6 @@ | |||
701 | 102 | See compileall.py for a script/module that uses this module to | 103 | See compileall.py for a script/module that uses this module to |
702 | 103 | byte-compile all installed files (or all files in selected | 104 | byte-compile all installed files (or all files in selected |
703 | 104 | directories). | 105 | directories). |
704 | 105 | |||
705 | 106 | """ | 106 | """ |
706 | 107 | with open(file, "rb") as f: | 107 | with open(file, "rb") as f: |
707 | 108 | encoding = tokenize.detect_encoding(f.readline)[0] | 108 | encoding = tokenize.detect_encoding(f.readline)[0] |
708 | @@ -122,7 +122,12 @@ | |||
709 | 122 | sys.stderr.write(py_exc.msg + '\n') | 122 | sys.stderr.write(py_exc.msg + '\n') |
710 | 123 | return | 123 | return |
711 | 124 | if cfile is None: | 124 | if cfile is None: |
713 | 125 | cfile = file + (__debug__ and 'c' or 'o') | 125 | cfile = imp.cache_from_source(file) |
714 | 126 | try: | ||
715 | 127 | os.mkdir(os.path.dirname(cfile)) | ||
716 | 128 | except OSError as error: | ||
717 | 129 | if error.errno != errno.EEXIST: | ||
718 | 130 | raise | ||
719 | 126 | with open(cfile, 'wb') as fc: | 131 | with open(cfile, 'wb') as fc: |
720 | 127 | fc.write(b'\0\0\0\0') | 132 | fc.write(b'\0\0\0\0') |
721 | 128 | wr_long(fc, timestamp) | 133 | wr_long(fc, timestamp) |
722 | @@ -130,6 +135,7 @@ | |||
723 | 130 | fc.flush() | 135 | fc.flush() |
724 | 131 | fc.seek(0, 0) | 136 | fc.seek(0, 0) |
725 | 132 | fc.write(MAGIC) | 137 | fc.write(MAGIC) |
726 | 138 | return cfile | ||
727 | 133 | 139 | ||
728 | 134 | def main(args=None): | 140 | def main(args=None): |
729 | 135 | """Compile several source files. | 141 | """Compile several source files. |
730 | 136 | 142 | ||
731 | === modified file 'Lib/pydoc.py' | |||
732 | --- Lib/pydoc.py 2010-04-01 03:05:25 +0000 | |||
733 | +++ Lib/pydoc.py 2010-04-16 18:55:41 +0000 | |||
734 | @@ -159,7 +159,8 @@ | |||
735 | 159 | """Decide whether to show documentation on a variable.""" | 159 | """Decide whether to show documentation on a variable.""" |
736 | 160 | # Certain special names are redundant. | 160 | # Certain special names are redundant. |
737 | 161 | _hidden_names = ('__builtins__', '__doc__', '__file__', '__path__', | 161 | _hidden_names = ('__builtins__', '__doc__', '__file__', '__path__', |
739 | 162 | '__module__', '__name__', '__slots__', '__package__') | 162 | '__module__', '__name__', '__slots__', '__package__', |
740 | 163 | '__cached__') | ||
741 | 163 | if name in _hidden_names: return 0 | 164 | if name in _hidden_names: return 0 |
742 | 164 | # Private names are hidden, but special names are displayed. | 165 | # Private names are hidden, but special names are displayed. |
743 | 165 | if name.startswith('__') and name.endswith('__'): return 1 | 166 | if name.startswith('__') and name.endswith('__'): return 1 |
744 | 166 | 167 | ||
745 | === modified file 'Lib/runpy.py' | |||
746 | --- Lib/runpy.py 2009-12-20 17:28:31 +0000 | |||
747 | +++ Lib/runpy.py 2010-04-16 18:55:41 +0000 | |||
748 | @@ -67,6 +67,7 @@ | |||
749 | 67 | run_globals.update(init_globals) | 67 | run_globals.update(init_globals) |
750 | 68 | run_globals.update(__name__ = mod_name, | 68 | run_globals.update(__name__ = mod_name, |
751 | 69 | __file__ = mod_fname, | 69 | __file__ = mod_fname, |
752 | 70 | __cached__ = None, | ||
753 | 70 | __loader__ = mod_loader, | 71 | __loader__ = mod_loader, |
754 | 71 | __package__ = pkg_name) | 72 | __package__ = pkg_name) |
755 | 72 | exec(code, run_globals) | 73 | exec(code, run_globals) |
756 | @@ -130,6 +131,7 @@ | |||
757 | 130 | At the very least, these variables in __main__ will be overwritten: | 131 | At the very least, these variables in __main__ will be overwritten: |
758 | 131 | __name__ | 132 | __name__ |
759 | 132 | __file__ | 133 | __file__ |
760 | 134 | __cached__ | ||
761 | 133 | __loader__ | 135 | __loader__ |
762 | 134 | __package__ | 136 | __package__ |
763 | 135 | """ | 137 | """ |
764 | 136 | 138 | ||
765 | === modified file 'Lib/site.py' | |||
766 | --- Lib/site.py 2010-04-12 22:33:42 +0000 | |||
767 | +++ Lib/site.py 2010-04-16 18:55:41 +0000 | |||
768 | @@ -74,15 +74,19 @@ | |||
769 | 74 | return dir, os.path.normcase(dir) | 74 | return dir, os.path.normcase(dir) |
770 | 75 | 75 | ||
771 | 76 | 76 | ||
774 | 77 | def abs__file__(): | 77 | def abs_paths(): |
775 | 78 | """Set all module' __file__ attribute to an absolute path""" | 78 | """Set all module __file__ and __cached__ attributes to an absolute path""" |
776 | 79 | for m in set(sys.modules.values()): | 79 | for m in set(sys.modules.values()): |
777 | 80 | if hasattr(m, '__loader__'): | 80 | if hasattr(m, '__loader__'): |
778 | 81 | continue # don't mess with a PEP 302-supplied __file__ | 81 | continue # don't mess with a PEP 302-supplied __file__ |
779 | 82 | try: | 82 | try: |
780 | 83 | m.__file__ = os.path.abspath(m.__file__) | 83 | m.__file__ = os.path.abspath(m.__file__) |
781 | 84 | except AttributeError: | 84 | except AttributeError: |
783 | 85 | continue | 85 | pass |
784 | 86 | try: | ||
785 | 87 | m.__cached__ = os.path.abspath(m.__cached__) | ||
786 | 88 | except AttributeError: | ||
787 | 89 | pass | ||
788 | 86 | 90 | ||
789 | 87 | 91 | ||
790 | 88 | def removeduppaths(): | 92 | def removeduppaths(): |
791 | @@ -518,7 +522,7 @@ | |||
792 | 518 | def main(): | 522 | def main(): |
793 | 519 | global ENABLE_USER_SITE | 523 | global ENABLE_USER_SITE |
794 | 520 | 524 | ||
796 | 521 | abs__file__() | 525 | abs_paths() |
797 | 522 | known_paths = removeduppaths() | 526 | known_paths = removeduppaths() |
798 | 523 | if (os.name == "posix" and sys.path and | 527 | if (os.name == "posix" and sys.path and |
799 | 524 | os.path.basename(sys.path[-1]) == "Modules"): | 528 | os.path.basename(sys.path[-1]) == "Modules"): |
800 | 525 | 529 | ||
801 | === modified file 'Lib/test/script_helper.py' | |||
802 | --- Lib/test/script_helper.py 2010-02-27 16:12:22 +0000 | |||
803 | +++ Lib/test/script_helper.py 2010-04-16 18:55:41 +0000 | |||
804 | @@ -11,6 +11,9 @@ | |||
805 | 11 | import shutil | 11 | import shutil |
806 | 12 | import zipfile | 12 | import zipfile |
807 | 13 | 13 | ||
808 | 14 | from imp import source_from_cache | ||
809 | 15 | from test.support import make_legacy_pyc | ||
810 | 16 | |||
811 | 14 | # Executing the interpreter in a subprocess | 17 | # Executing the interpreter in a subprocess |
812 | 15 | def python_exit_code(*args): | 18 | def python_exit_code(*args): |
813 | 16 | cmd_line = [sys.executable, '-E'] | 19 | cmd_line = [sys.executable, '-E'] |
814 | @@ -62,20 +65,18 @@ | |||
815 | 62 | script_file.close() | 65 | script_file.close() |
816 | 63 | return script_name | 66 | return script_name |
817 | 64 | 67 | ||
818 | 65 | def compile_script(script_name): | ||
819 | 66 | py_compile.compile(script_name, doraise=True) | ||
820 | 67 | if __debug__: | ||
821 | 68 | compiled_name = script_name + 'c' | ||
822 | 69 | else: | ||
823 | 70 | compiled_name = script_name + 'o' | ||
824 | 71 | return compiled_name | ||
825 | 72 | |||
826 | 73 | def make_zip_script(zip_dir, zip_basename, script_name, name_in_zip=None): | 68 | def make_zip_script(zip_dir, zip_basename, script_name, name_in_zip=None): |
827 | 74 | zip_filename = zip_basename+os.extsep+'zip' | 69 | zip_filename = zip_basename+os.extsep+'zip' |
828 | 75 | zip_name = os.path.join(zip_dir, zip_filename) | 70 | zip_name = os.path.join(zip_dir, zip_filename) |
829 | 76 | zip_file = zipfile.ZipFile(zip_name, 'w') | 71 | zip_file = zipfile.ZipFile(zip_name, 'w') |
830 | 77 | if name_in_zip is None: | 72 | if name_in_zip is None: |
832 | 78 | name_in_zip = os.path.basename(script_name) | 73 | parts = script_name.split(os.sep) |
833 | 74 | if len(parts) >= 2 and parts[-2] == '__pycache__': | ||
834 | 75 | legacy_pyc = make_legacy_pyc(source_from_cache(script_name)) | ||
835 | 76 | name_in_zip = os.path.basename(legacy_pyc) | ||
836 | 77 | script_name = legacy_pyc | ||
837 | 78 | else: | ||
838 | 79 | name_in_zip = os.path.basename(script_name) | ||
839 | 79 | zip_file.write(script_name, name_in_zip) | 80 | zip_file.write(script_name, name_in_zip) |
840 | 80 | zip_file.close() | 81 | zip_file.close() |
841 | 81 | #if test.test_support.verbose: | 82 | #if test.test_support.verbose: |
842 | @@ -98,8 +99,8 @@ | |||
843 | 98 | script_name = make_script(zip_dir, script_basename, source) | 99 | script_name = make_script(zip_dir, script_basename, source) |
844 | 99 | unlink.append(script_name) | 100 | unlink.append(script_name) |
845 | 100 | if compiled: | 101 | if compiled: |
848 | 101 | init_name = compile_script(init_name) | 102 | init_name = py_compile(init_name, doraise=True) |
849 | 102 | script_name = compile_script(script_name) | 103 | script_name = py_compile(script_name, doraise=True) |
850 | 103 | unlink.extend((init_name, script_name)) | 104 | unlink.extend((init_name, script_name)) |
851 | 104 | pkg_names = [os.sep.join([pkg_name]*i) for i in range(1, depth+1)] | 105 | pkg_names = [os.sep.join([pkg_name]*i) for i in range(1, depth+1)] |
852 | 105 | script_name_in_zip = os.path.join(pkg_names[-1], os.path.basename(script_name)) | 106 | script_name_in_zip = os.path.join(pkg_names[-1], os.path.basename(script_name)) |
853 | 106 | 107 | ||
854 | === modified file 'Lib/test/support.py' | |||
855 | --- Lib/test/support.py 2010-04-11 20:22:10 +0000 | |||
856 | +++ Lib/test/support.py 2010-04-16 18:55:41 +0000 | |||
857 | @@ -17,22 +17,25 @@ | |||
858 | 17 | import importlib | 17 | import importlib |
859 | 18 | import collections | 18 | import collections |
860 | 19 | import re | 19 | import re |
861 | 20 | import imp | ||
862 | 20 | import time | 21 | import time |
863 | 21 | 22 | ||
878 | 22 | __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module", | 23 | __all__ = [ |
879 | 23 | "verbose", "use_resources", "max_memuse", "record_original_stdout", | 24 | "Error", "TestFailed", "ResourceDenied", "import_module", |
880 | 24 | "get_original_stdout", "unload", "unlink", "rmtree", "forget", | 25 | "verbose", "use_resources", "max_memuse", "record_original_stdout", |
881 | 25 | "is_resource_enabled", "requires", "find_unused_port", "bind_port", | 26 | "get_original_stdout", "unload", "unlink", "rmtree", "forget", |
882 | 26 | "fcmp", "is_jython", "TESTFN", "HOST", "FUZZ", "SAVEDCWD", "temp_cwd", | 27 | "is_resource_enabled", "requires", "find_unused_port", "bind_port", |
883 | 27 | "findfile", "sortdict", "check_syntax_error", "open_urlresource", | 28 | "fcmp", "is_jython", "TESTFN", "HOST", "FUZZ", "SAVEDCWD", "temp_cwd", |
884 | 28 | "check_warnings", "CleanImport", "EnvironmentVarGuard", | 29 | "findfile", "sortdict", "check_syntax_error", "open_urlresource", |
885 | 29 | "TransientResource", "captured_output", "captured_stdout", | 30 | "check_warnings", "CleanImport", "EnvironmentVarGuard", |
886 | 30 | "time_out", "socket_peer_reset", "ioerror_peer_reset", | 31 | "TransientResource", "captured_output", "captured_stdout", |
887 | 31 | "run_with_locale", | 32 | "time_out", "socket_peer_reset", "ioerror_peer_reset", |
888 | 32 | "set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner", | 33 | "run_with_locale", 'temp_umask', |
889 | 33 | "run_unittest", "run_doctest", "threading_setup", "threading_cleanup", | 34 | "set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner", |
890 | 34 | "reap_children", "cpython_only", "check_impl_detail", "get_attribute", | 35 | "run_unittest", "run_doctest", "threading_setup", "threading_cleanup", |
891 | 35 | "swap_item", "swap_attr"] | 36 | "reap_children", "cpython_only", "check_impl_detail", "get_attribute", |
892 | 37 | "swap_item", "swap_attr", | ||
893 | 38 | ] | ||
894 | 36 | 39 | ||
895 | 37 | 40 | ||
896 | 38 | class Error(Exception): | 41 | class Error(Exception): |
897 | @@ -177,27 +180,50 @@ | |||
898 | 177 | def unlink(filename): | 180 | def unlink(filename): |
899 | 178 | try: | 181 | try: |
900 | 179 | os.unlink(filename) | 182 | os.unlink(filename) |
903 | 180 | except OSError: | 183 | except OSError as error: |
904 | 181 | pass | 184 | # The filename need not exist. |
905 | 185 | if error.errno != errno.ENOENT: | ||
906 | 186 | raise | ||
907 | 182 | 187 | ||
908 | 183 | def rmtree(path): | 188 | def rmtree(path): |
909 | 184 | try: | 189 | try: |
910 | 185 | shutil.rmtree(path) | 190 | shutil.rmtree(path) |
912 | 186 | except OSError as e: | 191 | except OSError as error: |
913 | 187 | # Unix returns ENOENT, Windows returns ESRCH. | 192 | # Unix returns ENOENT, Windows returns ESRCH. |
915 | 188 | if e.errno not in (errno.ENOENT, errno.ESRCH): | 193 | if error.errno not in (errno.ENOENT, errno.ESRCH): |
916 | 189 | raise | 194 | raise |
917 | 190 | 195 | ||
918 | 196 | def make_legacy_pyc(source): | ||
919 | 197 | """Move a PEP 3147 pyc/pyo file to its legacy pyc/pyo location. | ||
920 | 198 | |||
921 | 199 | The choice of .pyc or .pyo extension is done based on the __debug__ flag | ||
922 | 200 | value. | ||
923 | 201 | |||
924 | 202 | :param source: The file system path to the source file. The source file | ||
925 | 203 | does not need to exist, however the PEP 3147 pyc file must exist. | ||
926 | 204 | :return: The file system path to the legacy pyc file. | ||
927 | 205 | """ | ||
928 | 206 | pyc_file = imp.cache_from_source(source) | ||
929 | 207 | up_one = os.path.dirname(os.path.abspath(source)) | ||
930 | 208 | legacy_pyc = os.path.join(up_one, source + ('c' if __debug__ else 'o')) | ||
931 | 209 | os.rename(pyc_file, legacy_pyc) | ||
932 | 210 | return legacy_pyc | ||
933 | 211 | |||
934 | 191 | def forget(modname): | 212 | def forget(modname): |
937 | 192 | '''"Forget" a module was ever imported by removing it from sys.modules and | 213 | """'Forget' a module was ever imported. |
938 | 193 | deleting any .pyc and .pyo files.''' | 214 | |
939 | 215 | This removes the module from sys.modules and deletes any PEP 3147 or | ||
940 | 216 | legacy .pyc and .pyo files. | ||
941 | 217 | """ | ||
942 | 194 | unload(modname) | 218 | unload(modname) |
943 | 195 | for dirname in sys.path: | 219 | for dirname in sys.path: |
949 | 196 | unlink(os.path.join(dirname, modname + '.pyc')) | 220 | source = os.path.join(dirname, modname + '.py') |
950 | 197 | # Deleting the .pyo file cannot be within the 'try' for the .pyc since | 221 | # It doesn't matter if they exist or not, unlink all possible |
951 | 198 | # the chance exists that there is no .pyc (and thus the 'try' statement | 222 | # combinations of PEP 3147 and legacy pyc and pyo files. |
952 | 199 | # is exited) but there is a .pyo file. | 223 | unlink(source + 'c') |
953 | 200 | unlink(os.path.join(dirname, modname + '.pyo')) | 224 | unlink(source + 'o') |
954 | 225 | unlink(imp.cache_from_source(source, debug_override=True)) | ||
955 | 226 | unlink(imp.cache_from_source(source, debug_override=False)) | ||
956 | 201 | 227 | ||
957 | 202 | def is_resource_enabled(resource): | 228 | def is_resource_enabled(resource): |
958 | 203 | """Test whether a resource is enabled. Known resources are set by | 229 | """Test whether a resource is enabled. Known resources are set by |
959 | @@ -208,7 +234,9 @@ | |||
960 | 208 | """Raise ResourceDenied if the specified resource is not available. | 234 | """Raise ResourceDenied if the specified resource is not available. |
961 | 209 | 235 | ||
962 | 210 | If the caller's module is __main__ then automatically return True. The | 236 | If the caller's module is __main__ then automatically return True. The |
964 | 211 | possibility of False being returned occurs when regrtest.py is executing.""" | 237 | possibility of False being returned occurs when regrtest.py is |
965 | 238 | executing. | ||
966 | 239 | """ | ||
967 | 212 | # see if the caller's module is __main__ - if so, treat as if | 240 | # see if the caller's module is __main__ - if so, treat as if |
968 | 213 | # the resource was set | 241 | # the resource was set |
969 | 214 | if sys._getframe(1).f_globals.get("__name__") == "__main__": | 242 | if sys._getframe(1).f_globals.get("__name__") == "__main__": |
970 | @@ -405,6 +433,16 @@ | |||
971 | 405 | rmtree(name) | 433 | rmtree(name) |
972 | 406 | 434 | ||
973 | 407 | 435 | ||
974 | 436 | @contextlib.contextmanager | ||
975 | 437 | def temp_umask(umask): | ||
976 | 438 | """Context manager that temporarily sets the process umask.""" | ||
977 | 439 | oldmask = os.umask(umask) | ||
978 | 440 | try: | ||
979 | 441 | yield | ||
980 | 442 | finally: | ||
981 | 443 | os.umask(oldmask) | ||
982 | 444 | |||
983 | 445 | |||
984 | 408 | def findfile(file, here=__file__, subdir=None): | 446 | def findfile(file, here=__file__, subdir=None): |
985 | 409 | """Try to find a file on sys.path and the working directory. If it is not | 447 | """Try to find a file on sys.path and the working directory. If it is not |
986 | 410 | found the argument passed to the function is returned (this does not | 448 | found the argument passed to the function is returned (this does not |
987 | 411 | 449 | ||
988 | === modified file 'Lib/test/test_cmd_line_script.py' | |||
989 | --- Lib/test/test_cmd_line_script.py 2010-03-14 10:45:50 +0000 | |||
990 | +++ Lib/test/test_cmd_line_script.py 2010-04-16 18:55:41 +0000 | |||
991 | @@ -1,12 +1,14 @@ | |||
993 | 1 | # Tests command line execution of scripts | 1 | # tests command line execution of scripts |
994 | 2 | 2 | ||
995 | 3 | import unittest | 3 | import unittest |
996 | 4 | import os | 4 | import os |
997 | 5 | import os.path | 5 | import os.path |
998 | 6 | import py_compile | ||
999 | 7 | |||
1000 | 6 | import test.support | 8 | import test.support |
1004 | 7 | from test.script_helper import (run_python, | 9 | from test.script_helper import ( |
1005 | 8 | temp_dir, make_script, compile_script, | 10 | make_pkg, make_script, make_zip_pkg, make_zip_script, run_python, |
1006 | 9 | make_pkg, make_zip_script, make_zip_pkg) | 11 | temp_dir) |
1007 | 10 | 12 | ||
1008 | 11 | verbose = test.support.verbose | 13 | verbose = test.support.verbose |
1009 | 12 | 14 | ||
1010 | @@ -28,6 +30,7 @@ | |||
1011 | 28 | # Check population of magic variables | 30 | # Check population of magic variables |
1012 | 29 | assertEqual(__name__, '__main__') | 31 | assertEqual(__name__, '__main__') |
1013 | 30 | print('__file__==%r' % __file__) | 32 | print('__file__==%r' % __file__) |
1014 | 33 | assertEqual(__cached__, None) | ||
1015 | 31 | print('__package__==%r' % __package__) | 34 | print('__package__==%r' % __package__) |
1016 | 32 | # Check the sys module | 35 | # Check the sys module |
1017 | 33 | import sys | 36 | import sys |
1018 | @@ -101,9 +104,10 @@ | |||
1019 | 101 | def test_script_compiled(self): | 104 | def test_script_compiled(self): |
1020 | 102 | with temp_dir() as script_dir: | 105 | with temp_dir() as script_dir: |
1021 | 103 | script_name = _make_test_script(script_dir, 'script') | 106 | script_name = _make_test_script(script_dir, 'script') |
1023 | 104 | compiled_name = compile_script(script_name) | 107 | compiled_name = py_compile.compile(script_name, doraise=True) |
1024 | 105 | os.remove(script_name) | 108 | os.remove(script_name) |
1026 | 106 | self._check_script(compiled_name, compiled_name, compiled_name, None) | 109 | self._check_script(compiled_name, compiled_name, |
1027 | 110 | compiled_name, None) | ||
1028 | 107 | 111 | ||
1029 | 108 | def test_directory(self): | 112 | def test_directory(self): |
1030 | 109 | with temp_dir() as script_dir: | 113 | with temp_dir() as script_dir: |
1031 | @@ -113,9 +117,10 @@ | |||
1032 | 113 | def test_directory_compiled(self): | 117 | def test_directory_compiled(self): |
1033 | 114 | with temp_dir() as script_dir: | 118 | with temp_dir() as script_dir: |
1034 | 115 | script_name = _make_test_script(script_dir, '__main__') | 119 | script_name = _make_test_script(script_dir, '__main__') |
1036 | 116 | compiled_name = compile_script(script_name) | 120 | compiled_name = py_compile.compile(script_name, doraise=True) |
1037 | 117 | os.remove(script_name) | 121 | os.remove(script_name) |
1039 | 118 | self._check_script(script_dir, compiled_name, script_dir, '') | 122 | pyc_file = test.support.make_legacy_pyc(script_name) |
1040 | 123 | self._check_script(script_dir, pyc_file, script_dir, '') | ||
1041 | 119 | 124 | ||
1042 | 120 | def test_directory_error(self): | 125 | def test_directory_error(self): |
1043 | 121 | with temp_dir() as script_dir: | 126 | with temp_dir() as script_dir: |
1044 | @@ -131,7 +136,7 @@ | |||
1045 | 131 | def test_zipfile_compiled(self): | 136 | def test_zipfile_compiled(self): |
1046 | 132 | with temp_dir() as script_dir: | 137 | with temp_dir() as script_dir: |
1047 | 133 | script_name = _make_test_script(script_dir, '__main__') | 138 | script_name = _make_test_script(script_dir, '__main__') |
1049 | 134 | compiled_name = compile_script(script_name) | 139 | compiled_name = py_compile.compile(script_name, doraise=True) |
1050 | 135 | zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name) | 140 | zip_name, run_name = make_zip_script(script_dir, 'test_zip', compiled_name) |
1051 | 136 | self._check_script(zip_name, run_name, zip_name, '') | 141 | self._check_script(zip_name, run_name, zip_name, '') |
1052 | 137 | 142 | ||
1053 | @@ -176,11 +181,12 @@ | |||
1054 | 176 | pkg_dir = os.path.join(script_dir, 'test_pkg') | 181 | pkg_dir = os.path.join(script_dir, 'test_pkg') |
1055 | 177 | make_pkg(pkg_dir) | 182 | make_pkg(pkg_dir) |
1056 | 178 | script_name = _make_test_script(pkg_dir, '__main__') | 183 | script_name = _make_test_script(pkg_dir, '__main__') |
1058 | 179 | compiled_name = compile_script(script_name) | 184 | compiled_name = py_compile.compile(script_name, doraise=True) |
1059 | 180 | os.remove(script_name) | 185 | os.remove(script_name) |
1060 | 186 | pyc_file = test.support.make_legacy_pyc(script_name) | ||
1061 | 181 | launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') | 187 | launch_name = _make_launch_script(script_dir, 'launch', 'test_pkg') |
1064 | 182 | self._check_script(launch_name, compiled_name, | 188 | self._check_script(launch_name, pyc_file, |
1065 | 183 | compiled_name, 'test_pkg') | 189 | pyc_file, 'test_pkg') |
1066 | 184 | 190 | ||
1067 | 185 | def test_package_error(self): | 191 | def test_package_error(self): |
1068 | 186 | with temp_dir() as script_dir: | 192 | with temp_dir() as script_dir: |
1069 | 187 | 193 | ||
1070 | === modified file 'Lib/test/test_compileall.py' | |||
1071 | --- Lib/test/test_compileall.py 2010-03-16 13:19:21 +0000 | |||
1072 | +++ Lib/test/test_compileall.py 2010-04-16 18:55:41 +0000 | |||
1073 | @@ -5,22 +5,23 @@ | |||
1074 | 5 | import py_compile | 5 | import py_compile |
1075 | 6 | import shutil | 6 | import shutil |
1076 | 7 | import struct | 7 | import struct |
1077 | 8 | import subprocess | ||
1078 | 8 | import tempfile | 9 | import tempfile |
1079 | 9 | from test import support | ||
1080 | 10 | import unittest | 10 | import unittest |
1081 | 11 | import io | 11 | import io |
1082 | 12 | 12 | ||
1083 | 13 | from test import support | ||
1084 | 13 | 14 | ||
1085 | 14 | class CompileallTests(unittest.TestCase): | 15 | class CompileallTests(unittest.TestCase): |
1086 | 15 | 16 | ||
1087 | 16 | def setUp(self): | 17 | def setUp(self): |
1088 | 17 | self.directory = tempfile.mkdtemp() | 18 | self.directory = tempfile.mkdtemp() |
1089 | 18 | self.source_path = os.path.join(self.directory, '_test.py') | 19 | self.source_path = os.path.join(self.directory, '_test.py') |
1091 | 19 | self.bc_path = self.source_path + ('c' if __debug__ else 'o') | 20 | self.bc_path = imp.cache_from_source(self.source_path) |
1092 | 20 | with open(self.source_path, 'w') as file: | 21 | with open(self.source_path, 'w') as file: |
1093 | 21 | file.write('x = 123\n') | 22 | file.write('x = 123\n') |
1094 | 22 | self.source_path2 = os.path.join(self.directory, '_test2.py') | 23 | self.source_path2 = os.path.join(self.directory, '_test2.py') |
1096 | 23 | self.bc_path2 = self.source_path2 + ('c' if __debug__ else 'o') | 24 | self.bc_path2 = imp.cache_from_source(self.source_path2) |
1097 | 24 | shutil.copyfile(self.source_path, self.source_path2) | 25 | shutil.copyfile(self.source_path, self.source_path2) |
1098 | 25 | 26 | ||
1099 | 26 | def tearDown(self): | 27 | def tearDown(self): |
1100 | @@ -65,17 +66,19 @@ | |||
1101 | 65 | except: | 66 | except: |
1102 | 66 | pass | 67 | pass |
1103 | 67 | compileall.compile_file(self.source_path, force=False, quiet=True) | 68 | compileall.compile_file(self.source_path, force=False, quiet=True) |
1106 | 68 | self.assertTrue(os.path.isfile(self.bc_path) \ | 69 | self.assertTrue(os.path.isfile(self.bc_path) and |
1107 | 69 | and not os.path.isfile(self.bc_path2)) | 70 | not os.path.isfile(self.bc_path2)) |
1108 | 70 | os.unlink(self.bc_path) | 71 | os.unlink(self.bc_path) |
1109 | 71 | compileall.compile_dir(self.directory, force=False, quiet=True) | 72 | compileall.compile_dir(self.directory, force=False, quiet=True) |
1112 | 72 | self.assertTrue(os.path.isfile(self.bc_path) \ | 73 | self.assertTrue(os.path.isfile(self.bc_path) and |
1113 | 73 | and os.path.isfile(self.bc_path2)) | 74 | os.path.isfile(self.bc_path2)) |
1114 | 74 | os.unlink(self.bc_path) | 75 | os.unlink(self.bc_path) |
1115 | 75 | os.unlink(self.bc_path2) | 76 | os.unlink(self.bc_path2) |
1116 | 76 | 77 | ||
1117 | 78 | |||
1118 | 77 | class EncodingTest(unittest.TestCase): | 79 | class EncodingTest(unittest.TestCase): |
1120 | 78 | 'Issue 6716: compileall should escape source code when printing errors to stdout.' | 80 | """Issue 6716: compileall should escape source code when printing errors |
1121 | 81 | to stdout.""" | ||
1122 | 79 | 82 | ||
1123 | 80 | def setUp(self): | 83 | def setUp(self): |
1124 | 81 | self.directory = tempfile.mkdtemp() | 84 | self.directory = tempfile.mkdtemp() |
1125 | @@ -95,9 +98,65 @@ | |||
1126 | 95 | finally: | 98 | finally: |
1127 | 96 | sys.stdout = orig_stdout | 99 | sys.stdout = orig_stdout |
1128 | 97 | 100 | ||
1129 | 101 | class CommandLineTests(unittest.TestCase): | ||
1130 | 102 | """Test some aspects of compileall's CLI.""" | ||
1131 | 103 | |||
1132 | 104 | def setUp(self): | ||
1133 | 105 | self.addCleanup(self._cleanup) | ||
1134 | 106 | self.directory = tempfile.mkdtemp() | ||
1135 | 107 | self.pkgdir = os.path.join(self.directory, 'foo') | ||
1136 | 108 | os.mkdir(self.pkgdir) | ||
1137 | 109 | # Touch the __init__.py and a package module. | ||
1138 | 110 | with open(os.path.join(self.pkgdir, '__init__.py'), 'w'): | ||
1139 | 111 | pass | ||
1140 | 112 | with open(os.path.join(self.pkgdir, 'bar.py'), 'w'): | ||
1141 | 113 | pass | ||
1142 | 114 | sys.path.insert(0, self.directory) | ||
1143 | 115 | |||
1144 | 116 | def _cleanup(self): | ||
1145 | 117 | support.rmtree(self.directory) | ||
1146 | 118 | assert sys.path[0] == self.directory, 'Missing path' | ||
1147 | 119 | del sys.path[0] | ||
1148 | 120 | |||
1149 | 121 | def test_pep3147_paths(self): | ||
1150 | 122 | # Ensure that the default behavior of compileall's CLI is to create | ||
1151 | 123 | # PEP 3147 pyc/pyo files. | ||
1152 | 124 | retcode = subprocess.call( | ||
1153 | 125 | (sys.executable, '-m', 'compileall', '-q', self.pkgdir)) | ||
1154 | 126 | self.assertEqual(retcode, 0) | ||
1155 | 127 | # Verify the __pycache__ directory contents. | ||
1156 | 128 | cachedir = os.path.join(self.pkgdir, '__pycache__') | ||
1157 | 129 | self.assertTrue(os.path.exists(cachedir)) | ||
1158 | 130 | ext = ('pyc' if __debug__ else 'pyo') | ||
1159 | 131 | expected = sorted(base.format(imp.get_tag(), ext) for base in | ||
1160 | 132 | ('__init__.{}.{}', 'bar.{}.{}')) | ||
1161 | 133 | self.assertEqual(sorted(os.listdir(cachedir)), expected) | ||
1162 | 134 | # Make sure there are no .pyc files in the source directory. | ||
1163 | 135 | self.assertFalse([pyc_file for pyc_file in os.listdir(self.pkgdir) | ||
1164 | 136 | if pyc_file.endswith(ext)]) | ||
1165 | 137 | |||
1166 | 138 | def test_legacy_paths(self): | ||
1167 | 139 | # Ensure that with the proper switch, compileall leaves legacy | ||
1168 | 140 | # pyc/pyo files, and no __pycache__ directory. | ||
1169 | 141 | retcode = subprocess.call( | ||
1170 | 142 | (sys.executable, '-m', 'compileall', '-b', '-q', self.pkgdir)) | ||
1171 | 143 | self.assertEqual(retcode, 0) | ||
1172 | 144 | # Verify the __pycache__ directory contents. | ||
1173 | 145 | cachedir = os.path.join(self.pkgdir, '__pycache__') | ||
1174 | 146 | self.assertFalse(os.path.exists(cachedir)) | ||
1175 | 147 | ext = ('pyc' if __debug__ else 'pyo') | ||
1176 | 148 | expected = [base.format(ext) for base in ('__init__.{}', 'bar.{}')] | ||
1177 | 149 | expected.extend(['__init__.py', 'bar.py']) | ||
1178 | 150 | expected.sort() | ||
1179 | 151 | self.assertEqual(sorted(os.listdir(self.pkgdir)), expected) | ||
1180 | 152 | |||
1181 | 153 | |||
1182 | 98 | def test_main(): | 154 | def test_main(): |
1185 | 99 | support.run_unittest(CompileallTests, | 155 | support.run_unittest( |
1186 | 100 | EncodingTest) | 156 | CommandLineTests, |
1187 | 157 | CompileallTests, | ||
1188 | 158 | EncodingTest, | ||
1189 | 159 | ) | ||
1190 | 101 | 160 | ||
1191 | 102 | 161 | ||
1192 | 103 | if __name__ == "__main__": | 162 | if __name__ == "__main__": |
1193 | 104 | 163 | ||
1194 | === modified file 'Lib/test/test_frozen.py' | |||
1195 | --- Lib/test/test_frozen.py 2010-03-14 10:45:50 +0000 | |||
1196 | +++ Lib/test/test_frozen.py 2010-04-16 18:55:41 +0000 | |||
1197 | @@ -11,7 +11,7 @@ | |||
1198 | 11 | except ImportError as x: | 11 | except ImportError as x: |
1199 | 12 | self.fail("import __hello__ failed:" + str(x)) | 12 | self.fail("import __hello__ failed:" + str(x)) |
1200 | 13 | self.assertEqual(__hello__.initialized, True) | 13 | self.assertEqual(__hello__.initialized, True) |
1202 | 14 | self.assertEqual(len(dir(__hello__)), 6, dir(__hello__)) | 14 | self.assertEqual(len(dir(__hello__)), 7, dir(__hello__)) |
1203 | 15 | 15 | ||
1204 | 16 | try: | 16 | try: |
1205 | 17 | import __phello__ | 17 | import __phello__ |
1206 | @@ -19,9 +19,9 @@ | |||
1207 | 19 | self.fail("import __phello__ failed:" + str(x)) | 19 | self.fail("import __phello__ failed:" + str(x)) |
1208 | 20 | self.assertEqual(__phello__.initialized, True) | 20 | self.assertEqual(__phello__.initialized, True) |
1209 | 21 | if not "__phello__.spam" in sys.modules: | 21 | if not "__phello__.spam" in sys.modules: |
1210 | 22 | self.assertEqual(len(dir(__phello__)), 7, dir(__phello__)) | ||
1211 | 23 | else: | ||
1212 | 24 | self.assertEqual(len(dir(__phello__)), 8, dir(__phello__)) | 22 | self.assertEqual(len(dir(__phello__)), 8, dir(__phello__)) |
1213 | 23 | else: | ||
1214 | 24 | self.assertEqual(len(dir(__phello__)), 9, dir(__phello__)) | ||
1215 | 25 | self.assertEquals(__phello__.__path__, [__phello__.__name__]) | 25 | self.assertEquals(__phello__.__path__, [__phello__.__name__]) |
1216 | 26 | 26 | ||
1217 | 27 | try: | 27 | try: |
1218 | @@ -29,8 +29,8 @@ | |||
1219 | 29 | except ImportError as x: | 29 | except ImportError as x: |
1220 | 30 | self.fail("import __phello__.spam failed:" + str(x)) | 30 | self.fail("import __phello__.spam failed:" + str(x)) |
1221 | 31 | self.assertEqual(__phello__.spam.initialized, True) | 31 | self.assertEqual(__phello__.spam.initialized, True) |
1224 | 32 | self.assertEqual(len(dir(__phello__.spam)), 6) | 32 | self.assertEqual(len(dir(__phello__.spam)), 7) |
1225 | 33 | self.assertEqual(len(dir(__phello__)), 8) | 33 | self.assertEqual(len(dir(__phello__)), 9) |
1226 | 34 | 34 | ||
1227 | 35 | try: | 35 | try: |
1228 | 36 | import __phello__.foo | 36 | import __phello__.foo |
1229 | 37 | 37 | ||
1230 | === modified file 'Lib/test/test_imp.py' | |||
1231 | --- Lib/test/test_imp.py 2010-03-20 20:31:34 +0000 | |||
1232 | +++ Lib/test/test_imp.py 2010-04-16 18:55:41 +0000 | |||
1233 | @@ -1,6 +1,7 @@ | |||
1234 | 1 | import imp | 1 | import imp |
1235 | 2 | import os | 2 | import os |
1236 | 3 | import os.path | 3 | import os.path |
1237 | 4 | import shutil | ||
1238 | 4 | import sys | 5 | import sys |
1239 | 5 | import unittest | 6 | import unittest |
1240 | 6 | from test import support | 7 | from test import support |
1241 | @@ -139,7 +140,8 @@ | |||
1242 | 139 | mod = imp.load_source(temp_mod_name, temp_mod_name + '.py') | 140 | mod = imp.load_source(temp_mod_name, temp_mod_name + '.py') |
1243 | 140 | self.assertEqual(mod.a, 1) | 141 | self.assertEqual(mod.a, 1) |
1244 | 141 | 142 | ||
1246 | 142 | mod = imp.load_compiled(temp_mod_name, temp_mod_name + '.pyc') | 143 | mod = imp.load_compiled( |
1247 | 144 | temp_mod_name, imp.cache_from_source(temp_mod_name + '.py')) | ||
1248 | 143 | self.assertEqual(mod.a, 1) | 145 | self.assertEqual(mod.a, 1) |
1249 | 144 | 146 | ||
1250 | 145 | if not os.path.exists(test_package_name): | 147 | if not os.path.exists(test_package_name): |
1251 | @@ -184,11 +186,132 @@ | |||
1252 | 184 | imp.reload(marshal) | 186 | imp.reload(marshal) |
1253 | 185 | 187 | ||
1254 | 186 | 188 | ||
1255 | 189 | class PEP3147Tests(unittest.TestCase): | ||
1256 | 190 | """Tests of PEP 3147.""" | ||
1257 | 191 | |||
1258 | 192 | tag = imp.get_tag() | ||
1259 | 193 | |||
1260 | 194 | def test_cache_from_source(self): | ||
1261 | 195 | # Given the path to a .py file, return the path to its PEP 3147 | ||
1262 | 196 | # defined .pyc file (i.e. under __pycache__). | ||
1263 | 197 | self.assertEqual( | ||
1264 | 198 | imp.cache_from_source('/foo/bar/baz/qux.py', True), | ||
1265 | 199 | '/foo/bar/baz/__pycache__/qux.{}.pyc'.format(self.tag)) | ||
1266 | 200 | |||
1267 | 201 | def test_cache_from_source_optimized(self): | ||
1268 | 202 | # Given the path to a .py file, return the path to its PEP 3147 | ||
1269 | 203 | # defined .pyo file (i.e. under __pycache__). | ||
1270 | 204 | self.assertEqual( | ||
1271 | 205 | imp.cache_from_source('/foo/bar/baz/qux.py', False), | ||
1272 | 206 | '/foo/bar/baz/__pycache__/qux.{}.pyo'.format(self.tag)) | ||
1273 | 207 | |||
1274 | 208 | def test_cache_from_source_cwd(self): | ||
1275 | 209 | self.assertEqual(imp.cache_from_source('foo.py', True), | ||
1276 | 210 | os.sep.join(('__pycache__', | ||
1277 | 211 | 'foo.{}.pyc'.format(self.tag)))) | ||
1278 | 212 | |||
1279 | 213 | def test_cache_from_source_override(self): | ||
1280 | 214 | # When debug_override is not None, it can be any true-ish or false-ish | ||
1281 | 215 | # value. | ||
1282 | 216 | self.assertEqual( | ||
1283 | 217 | imp.cache_from_source('/foo/bar/baz.py', []), | ||
1284 | 218 | '/foo/bar/__pycache__/baz.{}.pyo'.format(self.tag)) | ||
1285 | 219 | self.assertEqual( | ||
1286 | 220 | imp.cache_from_source('/foo/bar/baz.py', [17]), | ||
1287 | 221 | '/foo/bar/__pycache__/baz.{}.pyc'.format(self.tag)) | ||
1288 | 222 | # However if the bool-ishness can't be determined, the exception | ||
1289 | 223 | # propagates. | ||
1290 | 224 | class Bearish: | ||
1291 | 225 | def __bool__(self): raise RuntimeError | ||
1292 | 226 | self.assertRaises( | ||
1293 | 227 | RuntimeError, | ||
1294 | 228 | imp.cache_from_source, '/foo/bar/baz.py', Bearish()) | ||
1295 | 229 | |||
1296 | 230 | @unittest.skipIf(os.altsep is None, | ||
1297 | 231 | 'test meaningful only where os.altsep is defined') | ||
1298 | 232 | def test_altsep_cache_from_source(self): | ||
1299 | 233 | # Windows path and PEP 3147. | ||
1300 | 234 | self.assertEqual( | ||
1301 | 235 | imp.cache_from_source('\\foo\\bar\\baz\\qux.py', True), | ||
1302 | 236 | '\\foo\\bar\\baz\\__pycache__\\qux.{}.pyc'.format(self.tag)) | ||
1303 | 237 | |||
1304 | 238 | @unittest.skipIf(os.altsep is None, | ||
1305 | 239 | 'test meaningful only where os.altsep is defined') | ||
1306 | 240 | def test_altsep_and_sep_cache_from_source(self): | ||
1307 | 241 | # Windows path and PEP 3147 where altsep is right of sep. | ||
1308 | 242 | self.assertEqual( | ||
1309 | 243 | imp.cache_from_source('\\foo\\bar/baz\\qux.py', True), | ||
1310 | 244 | '\\foo\\bar/baz\\__pycache__\\qux.{}.pyc'.format(self.tag)) | ||
1311 | 245 | |||
1312 | 246 | @unittest.skipIf(os.altsep is None, | ||
1313 | 247 | 'test meaningful only where os.altsep is defined') | ||
1314 | 248 | def test_sep_altsep_and_sep_cache_from_source(self): | ||
1315 | 249 | # Windows path and PEP 3147 where sep is right of altsep. | ||
1316 | 250 | self.assertEqual( | ||
1317 | 251 | imp.cache_from_source('\\foo\\bar\\baz/qux.py', True), | ||
1318 | 252 | '\\foo\\bar\\baz/__pycache__/qux.{}.pyc'.format(self.tag)) | ||
1319 | 253 | |||
1320 | 254 | def test_source_from_cache(self): | ||
1321 | 255 | # Given the path to a PEP 3147 defined .pyc file, return the path to | ||
1322 | 256 | # its source. This tests the good path. | ||
1323 | 257 | self.assertEqual(imp.source_from_cache( | ||
1324 | 258 | '/foo/bar/baz/__pycache__/qux.{}.pyc'.format(self.tag)), | ||
1325 | 259 | '/foo/bar/baz/qux.py') | ||
1326 | 260 | |||
1327 | 261 | def test_source_from_cache_bad_path(self): | ||
1328 | 262 | # When the path to a pyc file is not in PEP 3147 format, a ValueError | ||
1329 | 263 | # is raised. | ||
1330 | 264 | self.assertRaises( | ||
1331 | 265 | ValueError, imp.source_from_cache, '/foo/bar/bazqux.pyc') | ||
1332 | 266 | |||
1333 | 267 | def test_source_from_cache_no_slash(self): | ||
1334 | 268 | # No slashes at all in path -> ValueError | ||
1335 | 269 | self.assertRaises( | ||
1336 | 270 | ValueError, imp.source_from_cache, 'foo.cpython-32.pyc') | ||
1337 | 271 | |||
1338 | 272 | def test_source_from_cache_too_few_dots(self): | ||
1339 | 273 | # Too few dots in final path component -> ValueError | ||
1340 | 274 | self.assertRaises( | ||
1341 | 275 | ValueError, imp.source_from_cache, '__pycache__/foo.pyc') | ||
1342 | 276 | |||
1343 | 277 | def test_source_from_cache_too_many_dots(self): | ||
1344 | 278 | # Too many dots in final path component -> ValueError | ||
1345 | 279 | self.assertRaises( | ||
1346 | 280 | ValueError, imp.source_from_cache, | ||
1347 | 281 | '__pycache__/foo.cpython-32.foo.pyc') | ||
1348 | 282 | |||
1349 | 283 | def test_source_from_cache_no__pycache__(self): | ||
1350 | 284 | # Another problem with the path -> ValueError | ||
1351 | 285 | self.assertRaises( | ||
1352 | 286 | ValueError, imp.source_from_cache, | ||
1353 | 287 | '/foo/bar/foo.cpython-32.foo.pyc') | ||
1354 | 288 | |||
1355 | 289 | def test_package___file__(self): | ||
1356 | 290 | # Test that a package's __file__ points to the right source directory. | ||
1357 | 291 | os.mkdir('pep3147') | ||
1358 | 292 | sys.path.insert(0, os.curdir) | ||
1359 | 293 | def cleanup(): | ||
1360 | 294 | if sys.path[0] == os.curdir: | ||
1361 | 295 | del sys.path[0] | ||
1362 | 296 | shutil.rmtree('pep3147') | ||
1363 | 297 | self.addCleanup(cleanup) | ||
1364 | 298 | # Touch the __init__.py file. | ||
1365 | 299 | with open('pep3147/__init__.py', 'w'): | ||
1366 | 300 | pass | ||
1367 | 301 | m = __import__('pep3147') | ||
1368 | 302 | # Ensure we load the pyc file. | ||
1369 | 303 | support.forget('pep3147') | ||
1370 | 304 | m = __import__('pep3147') | ||
1371 | 305 | self.assertEqual(m.__file__, | ||
1372 | 306 | os.sep.join(('.', 'pep3147', '__init__.py'))) | ||
1373 | 307 | |||
1374 | 308 | |||
1375 | 187 | def test_main(): | 309 | def test_main(): |
1376 | 188 | tests = [ | 310 | tests = [ |
1377 | 189 | ImportTests, | 311 | ImportTests, |
1378 | 312 | PEP3147Tests, | ||
1379 | 190 | ReloadTests, | 313 | ReloadTests, |
1381 | 191 | ] | 314 | ] |
1382 | 192 | try: | 315 | try: |
1383 | 193 | import _thread | 316 | import _thread |
1384 | 194 | except ImportError: | 317 | except ImportError: |
1385 | 195 | 318 | ||
1386 | === modified file 'Lib/test/test_import.py' | |||
1387 | --- Lib/test/test_import.py 2010-03-17 20:29:51 +0000 | |||
1388 | +++ Lib/test/test_import.py 2010-04-16 18:55:41 +0000 | |||
1389 | @@ -1,4 +1,5 @@ | |||
1390 | 1 | import builtins | 1 | import builtins |
1391 | 2 | import errno | ||
1392 | 2 | import imp | 3 | import imp |
1393 | 3 | import marshal | 4 | import marshal |
1394 | 4 | import os | 5 | import os |
1395 | @@ -8,8 +9,11 @@ | |||
1396 | 8 | import stat | 9 | import stat |
1397 | 9 | import sys | 10 | import sys |
1398 | 10 | import unittest | 11 | import unittest |
1401 | 11 | from test.support import (unlink, TESTFN, unload, run_unittest, is_jython, | 12 | |
1402 | 12 | check_warnings, EnvironmentVarGuard, swap_attr, swap_item) | 13 | from test.support import ( |
1403 | 14 | EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython, | ||
1404 | 15 | make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask, | ||
1405 | 16 | unlink, unload) | ||
1406 | 13 | 17 | ||
1407 | 14 | 18 | ||
1408 | 15 | def remove_files(name): | 19 | def remove_files(name): |
1409 | @@ -19,12 +23,18 @@ | |||
1410 | 19 | name + ".pyw", | 23 | name + ".pyw", |
1411 | 20 | name + "$py.class"): | 24 | name + "$py.class"): |
1412 | 21 | unlink(f) | 25 | unlink(f) |
1413 | 26 | try: | ||
1414 | 27 | shutil.rmtree('__pycache__') | ||
1415 | 28 | except OSError as error: | ||
1416 | 29 | if error.errno != errno.ENOENT: | ||
1417 | 30 | raise | ||
1418 | 22 | 31 | ||
1419 | 23 | 32 | ||
1420 | 24 | class ImportTests(unittest.TestCase): | 33 | class ImportTests(unittest.TestCase): |
1421 | 25 | 34 | ||
1422 | 26 | def tearDown(self): | 35 | def tearDown(self): |
1423 | 27 | unload(TESTFN) | 36 | unload(TESTFN) |
1424 | 37 | |||
1425 | 28 | setUp = tearDown | 38 | setUp = tearDown |
1426 | 29 | 39 | ||
1427 | 30 | def test_case_sensitivity(self): | 40 | def test_case_sensitivity(self): |
1428 | @@ -53,8 +63,8 @@ | |||
1429 | 53 | pyc = TESTFN + ".pyc" | 63 | pyc = TESTFN + ".pyc" |
1430 | 54 | 64 | ||
1431 | 55 | with open(source, "w") as f: | 65 | with open(source, "w") as f: |
1434 | 56 | print("# This tests Python's ability to import a", ext, "file.", | 66 | print("# This tests Python's ability to import a", |
1435 | 57 | file=f) | 67 | ext, "file.", file=f) |
1436 | 58 | a = random.randrange(1000) | 68 | a = random.randrange(1000) |
1437 | 59 | b = random.randrange(1000) | 69 | b = random.randrange(1000) |
1438 | 60 | print("a =", a, file=f) | 70 | print("a =", a, file=f) |
1439 | @@ -73,10 +83,10 @@ | |||
1440 | 73 | self.assertEqual(mod.b, b, | 83 | self.assertEqual(mod.b, b, |
1441 | 74 | "module loaded (%s) but contents invalid" % mod) | 84 | "module loaded (%s) but contents invalid" % mod) |
1442 | 75 | finally: | 85 | finally: |
1443 | 86 | forget(TESTFN) | ||
1444 | 76 | unlink(source) | 87 | unlink(source) |
1445 | 77 | unlink(pyc) | 88 | unlink(pyc) |
1446 | 78 | unlink(pyo) | 89 | unlink(pyo) |
1447 | 79 | unload(TESTFN) | ||
1448 | 80 | 90 | ||
1449 | 81 | sys.path.insert(0, os.curdir) | 91 | sys.path.insert(0, os.curdir) |
1450 | 82 | try: | 92 | try: |
1451 | @@ -87,32 +97,31 @@ | |||
1452 | 87 | finally: | 97 | finally: |
1453 | 88 | del sys.path[0] | 98 | del sys.path[0] |
1454 | 89 | 99 | ||
1456 | 90 | @unittest.skipUnless(os.name == 'posix', "test meaningful only on posix systems") | 100 | @unittest.skipUnless(os.name == 'posix', |
1457 | 101 | "test meaningful only on posix systems") | ||
1458 | 91 | def test_execute_bit_not_copied(self): | 102 | def test_execute_bit_not_copied(self): |
1459 | 92 | # Issue 6070: under posix .pyc files got their execute bit set if | 103 | # Issue 6070: under posix .pyc files got their execute bit set if |
1460 | 93 | # the .py file had the execute bit set, but they aren't executable. | 104 | # the .py file had the execute bit set, but they aren't executable. |
1472 | 94 | oldmask = os.umask(0o022) | 105 | with temp_umask(0o022): |
1473 | 95 | sys.path.insert(0, os.curdir) | 106 | sys.path.insert(0, os.curdir) |
1474 | 96 | try: | 107 | try: |
1475 | 97 | fname = TESTFN + os.extsep + "py" | 108 | fname = TESTFN + os.extsep + "py" |
1476 | 98 | f = open(fname, 'w').close() | 109 | f = open(fname, 'w').close() |
1477 | 99 | os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | | 110 | os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | |
1478 | 100 | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) | 111 | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) |
1479 | 101 | __import__(TESTFN) | 112 | __import__(TESTFN) |
1480 | 102 | fn = fname + 'c' | 113 | fn = imp.cache_from_source(fname) |
1470 | 103 | if not os.path.exists(fn): | ||
1471 | 104 | fn = fname + 'o' | ||
1481 | 105 | if not os.path.exists(fn): | 114 | if not os.path.exists(fn): |
1482 | 106 | self.fail("__import__ did not result in creation of " | 115 | self.fail("__import__ did not result in creation of " |
1483 | 107 | "either a .pyc or .pyo file") | 116 | "either a .pyc or .pyo file") |
1492 | 108 | s = os.stat(fn) | 117 | s = os.stat(fn) |
1493 | 109 | self.assertEqual(stat.S_IMODE(s.st_mode), | 118 | self.assertEqual( |
1494 | 110 | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) | 119 | stat.S_IMODE(s.st_mode), |
1495 | 111 | finally: | 120 | stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) |
1496 | 112 | os.umask(oldmask) | 121 | finally: |
1497 | 113 | remove_files(TESTFN) | 122 | del sys.path[0] |
1498 | 114 | unload(TESTFN) | 123 | remove_files(TESTFN) |
1499 | 115 | del sys.path[0] | 124 | unload(TESTFN) |
1500 | 116 | 125 | ||
1501 | 117 | def test_imp_module(self): | 126 | def test_imp_module(self): |
1502 | 118 | # Verify that the imp module can correctly load and find .py files | 127 | # Verify that the imp module can correctly load and find .py files |
1503 | @@ -144,10 +153,12 @@ | |||
1504 | 144 | f.write('"",\n') | 153 | f.write('"",\n') |
1505 | 145 | f.write(']') | 154 | f.write(']') |
1506 | 146 | 155 | ||
1508 | 147 | # Compile & remove .py file, we only need .pyc (or .pyo). | 156 | # Compile & remove .py file, we only need .pyc (or .pyo), but that |
1509 | 157 | # must be relocated to the PEP 3147 bytecode-only location. | ||
1510 | 148 | with open(filename, 'r') as f: | 158 | with open(filename, 'r') as f: |
1511 | 149 | py_compile.compile(filename) | 159 | py_compile.compile(filename) |
1512 | 150 | unlink(filename) | 160 | unlink(filename) |
1513 | 161 | make_legacy_pyc(filename) | ||
1514 | 151 | 162 | ||
1515 | 152 | # Need to be able to load from current dir. | 163 | # Need to be able to load from current dir. |
1516 | 153 | sys.path.append('') | 164 | sys.path.append('') |
1517 | @@ -247,8 +258,9 @@ | |||
1518 | 247 | self.assertTrue(mod.__file__.endswith('.py')) | 258 | self.assertTrue(mod.__file__.endswith('.py')) |
1519 | 248 | os.remove(source) | 259 | os.remove(source) |
1520 | 249 | del sys.modules[TESTFN] | 260 | del sys.modules[TESTFN] |
1521 | 261 | make_legacy_pyc(source) | ||
1522 | 250 | mod = __import__(TESTFN) | 262 | mod = __import__(TESTFN) |
1524 | 251 | ext = mod.__file__[-4:] | 263 | base, ext = os.path.splitext(mod.__file__) |
1525 | 252 | self.assertIn(ext, ('.pyc', '.pyo')) | 264 | self.assertIn(ext, ('.pyc', '.pyo')) |
1526 | 253 | finally: | 265 | finally: |
1527 | 254 | del sys.path[0] | 266 | del sys.path[0] |
1528 | @@ -298,7 +310,7 @@ | |||
1529 | 298 | """ | 310 | """ |
1530 | 299 | dir_name = os.path.abspath(TESTFN) | 311 | dir_name = os.path.abspath(TESTFN) |
1531 | 300 | file_name = os.path.join(dir_name, module_name) + os.extsep + "py" | 312 | file_name = os.path.join(dir_name, module_name) + os.extsep + "py" |
1533 | 301 | compiled_name = file_name + ("c" if __debug__ else "o") | 313 | compiled_name = imp.cache_from_source(file_name) |
1534 | 302 | 314 | ||
1535 | 303 | def setUp(self): | 315 | def setUp(self): |
1536 | 304 | self.sys_path = sys.path[:] | 316 | self.sys_path = sys.path[:] |
1537 | @@ -346,8 +358,9 @@ | |||
1538 | 346 | target = "another_module.py" | 358 | target = "another_module.py" |
1539 | 347 | py_compile.compile(self.file_name, dfile=target) | 359 | py_compile.compile(self.file_name, dfile=target) |
1540 | 348 | os.remove(self.file_name) | 360 | os.remove(self.file_name) |
1541 | 361 | pyc_file = make_legacy_pyc(self.file_name) | ||
1542 | 349 | mod = self.import_module() | 362 | mod = self.import_module() |
1544 | 350 | self.assertEqual(mod.module_filename, self.compiled_name) | 363 | self.assertEqual(mod.module_filename, pyc_file) |
1545 | 351 | self.assertEqual(mod.code_filename, target) | 364 | self.assertEqual(mod.code_filename, target) |
1546 | 352 | self.assertEqual(mod.func_filename, target) | 365 | self.assertEqual(mod.func_filename, target) |
1547 | 353 | 366 | ||
1548 | @@ -476,10 +489,143 @@ | |||
1549 | 476 | self.assertEqual(foo(), os) | 489 | self.assertEqual(foo(), os) |
1550 | 477 | 490 | ||
1551 | 478 | 491 | ||
1552 | 492 | class PycacheTests(unittest.TestCase): | ||
1553 | 493 | # Test the various PEP 3147 related behaviors. | ||
1554 | 494 | |||
1555 | 495 | tag = imp.get_tag() | ||
1556 | 496 | |||
1557 | 497 | def _clean(self): | ||
1558 | 498 | forget(TESTFN) | ||
1559 | 499 | rmtree('__pycache__') | ||
1560 | 500 | unlink(self.source) | ||
1561 | 501 | |||
1562 | 502 | def setUp(self): | ||
1563 | 503 | self.source = TESTFN + '.py' | ||
1564 | 504 | self._clean() | ||
1565 | 505 | with open(self.source, 'w') as fp: | ||
1566 | 506 | print('# This is a test file written by test_import.py', file=fp) | ||
1567 | 507 | sys.path.insert(0, os.curdir) | ||
1568 | 508 | |||
1569 | 509 | def tearDown(self): | ||
1570 | 510 | assert sys.path[0] == os.curdir, 'Unexpected sys.path[0]' | ||
1571 | 511 | del sys.path[0] | ||
1572 | 512 | self._clean() | ||
1573 | 513 | |||
1574 | 514 | def test_import_pyc_path(self): | ||
1575 | 515 | self.assertFalse(os.path.exists('__pycache__')) | ||
1576 | 516 | __import__(TESTFN) | ||
1577 | 517 | self.assertTrue(os.path.exists('__pycache__')) | ||
1578 | 518 | self.assertTrue(os.path.exists(os.path.join( | ||
1579 | 519 | '__pycache__', '{}.{}.pyc'.format(TESTFN, self.tag)))) | ||
1580 | 520 | |||
1581 | 521 | @unittest.skipUnless(os.name == 'posix', | ||
1582 | 522 | "test meaningful only on posix systems") | ||
1583 | 523 | def test_unwritable_directory(self): | ||
1584 | 524 | # When the umask causes the new __pycache__ directory to be | ||
1585 | 525 | # unwritable, the import still succeeds but no .pyc file is written. | ||
1586 | 526 | with temp_umask(0o222): | ||
1587 | 527 | __import__(TESTFN) | ||
1588 | 528 | self.assertTrue(os.path.exists('__pycache__')) | ||
1589 | 529 | self.assertFalse(os.path.exists(os.path.join( | ||
1590 | 530 | '__pycache__', '{}.{}.pyc'.format(TESTFN, self.tag)))) | ||
1591 | 531 | |||
1592 | 532 | def test_missing_source(self): | ||
1593 | 533 | # With PEP 3147 cache layout, removing the source but leaving the pyc | ||
1594 | 534 | # file does not satisfy the import. | ||
1595 | 535 | __import__(TESTFN) | ||
1596 | 536 | pyc_file = imp.cache_from_source(self.source) | ||
1597 | 537 | self.assertTrue(os.path.exists(pyc_file)) | ||
1598 | 538 | os.remove(self.source) | ||
1599 | 539 | forget(TESTFN) | ||
1600 | 540 | self.assertRaises(ImportError, __import__, TESTFN) | ||
1601 | 541 | |||
1602 | 542 | def test_missing_source_legacy(self): | ||
1603 | 543 | # Like test_missing_source() except that for backward compatibility, | ||
1604 | 544 | # when the pyc file lives where the py file would have been (and named | ||
1605 | 545 | # without the tag), it is importable. The __file__ of the imported | ||
1606 | 546 | # module is the pyc location. | ||
1607 | 547 | __import__(TESTFN) | ||
1608 | 548 | # pyc_file gets removed in _clean() via tearDown(). | ||
1609 | 549 | pyc_file = make_legacy_pyc(self.source) | ||
1610 | 550 | os.remove(self.source) | ||
1611 | 551 | unload(TESTFN) | ||
1612 | 552 | m = __import__(TESTFN) | ||
1613 | 553 | self.assertEqual(m.__file__, | ||
1614 | 554 | os.path.join(os.curdir, os.path.relpath(pyc_file))) | ||
1615 | 555 | |||
1616 | 556 | def test___cached__(self): | ||
1617 | 557 | # Modules now also have an __cached__ that points to the pyc file. | ||
1618 | 558 | m = __import__(TESTFN) | ||
1619 | 559 | pyc_file = imp.cache_from_source(TESTFN + '.py') | ||
1620 | 560 | self.assertEqual(m.__cached__, os.path.join(os.curdir, pyc_file)) | ||
1621 | 561 | |||
1622 | 562 | def test___cached___legacy_pyc(self): | ||
1623 | 563 | # Like test___cached__() except that for backward compatibility, | ||
1624 | 564 | # when the pyc file lives where the py file would have been (and named | ||
1625 | 565 | # without the tag), it is importable. The __cached__ of the imported | ||
1626 | 566 | # module is the pyc location. | ||
1627 | 567 | __import__(TESTFN) | ||
1628 | 568 | # pyc_file gets removed in _clean() via tearDown(). | ||
1629 | 569 | pyc_file = make_legacy_pyc(self.source) | ||
1630 | 570 | os.remove(self.source) | ||
1631 | 571 | unload(TESTFN) | ||
1632 | 572 | m = __import__(TESTFN) | ||
1633 | 573 | self.assertEqual(m.__cached__, | ||
1634 | 574 | os.path.join(os.curdir, os.path.relpath(pyc_file))) | ||
1635 | 575 | |||
1636 | 576 | def test_package___cached__(self): | ||
1637 | 577 | # Like test___cached__ but for packages. | ||
1638 | 578 | def cleanup(): | ||
1639 | 579 | shutil.rmtree('pep3147') | ||
1640 | 580 | os.mkdir('pep3147') | ||
1641 | 581 | self.addCleanup(cleanup) | ||
1642 | 582 | # Touch the __init__.py | ||
1643 | 583 | with open(os.path.join('pep3147', '__init__.py'), 'w'): | ||
1644 | 584 | pass | ||
1645 | 585 | with open(os.path.join('pep3147', 'foo.py'), 'w'): | ||
1646 | 586 | pass | ||
1647 | 587 | unload('pep3147.foo') | ||
1648 | 588 | unload('pep3147') | ||
1649 | 589 | m = __import__('pep3147.foo') | ||
1650 | 590 | init_pyc = imp.cache_from_source( | ||
1651 | 591 | os.path.join('pep3147', '__init__.py')) | ||
1652 | 592 | self.assertEqual(m.__cached__, os.path.join(os.curdir, init_pyc)) | ||
1653 | 593 | foo_pyc = imp.cache_from_source(os.path.join('pep3147', 'foo.py')) | ||
1654 | 594 | self.assertEqual(sys.modules['pep3147.foo'].__cached__, | ||
1655 | 595 | os.path.join(os.curdir, foo_pyc)) | ||
1656 | 596 | |||
1657 | 597 | def test_package___cached___from_pyc(self): | ||
1658 | 598 | # Like test___cached__ but ensuring __cached__ when imported from a | ||
1659 | 599 | # PEP 3147 pyc file. | ||
1660 | 600 | def cleanup(): | ||
1661 | 601 | shutil.rmtree('pep3147') | ||
1662 | 602 | os.mkdir('pep3147') | ||
1663 | 603 | self.addCleanup(cleanup) | ||
1664 | 604 | unload('pep3147.foo') | ||
1665 | 605 | unload('pep3147') | ||
1666 | 606 | # Touch the __init__.py | ||
1667 | 607 | with open(os.path.join('pep3147', '__init__.py'), 'w'): | ||
1668 | 608 | pass | ||
1669 | 609 | with open(os.path.join('pep3147', 'foo.py'), 'w'): | ||
1670 | 610 | pass | ||
1671 | 611 | m = __import__('pep3147.foo') | ||
1672 | 612 | unload('pep3147.foo') | ||
1673 | 613 | unload('pep3147') | ||
1674 | 614 | m = __import__('pep3147.foo') | ||
1675 | 615 | init_pyc = imp.cache_from_source( | ||
1676 | 616 | os.path.join('pep3147', '__init__.py')) | ||
1677 | 617 | self.assertEqual(m.__cached__, os.path.join(os.curdir, init_pyc)) | ||
1678 | 618 | foo_pyc = imp.cache_from_source(os.path.join('pep3147', 'foo.py')) | ||
1679 | 619 | self.assertEqual(sys.modules['pep3147.foo'].__cached__, | ||
1680 | 620 | os.path.join(os.curdir, foo_pyc)) | ||
1681 | 621 | |||
1682 | 622 | |||
1683 | 479 | def test_main(verbose=None): | 623 | def test_main(verbose=None): |
1685 | 480 | run_unittest(ImportTests, PycRewritingTests, PathsTests, RelativeImportTests, | 624 | run_unittest(ImportTests, PycacheTests, |
1686 | 625 | PycRewritingTests, PathsTests, RelativeImportTests, | ||
1687 | 481 | OverridingImportBuiltinTests) | 626 | OverridingImportBuiltinTests) |
1688 | 482 | 627 | ||
1689 | 628 | |||
1690 | 483 | if __name__ == '__main__': | 629 | if __name__ == '__main__': |
1691 | 484 | # Test needs to be a package, so we can do relative imports. | 630 | # Test needs to be a package, so we can do relative imports. |
1692 | 485 | from test.test_import import test_main | 631 | from test.test_import import test_main |
1693 | 486 | 632 | ||
1694 | === modified file 'Lib/test/test_pkg.py' | |||
1695 | --- Lib/test/test_pkg.py 2010-02-24 01:46:21 +0000 | |||
1696 | +++ Lib/test/test_pkg.py 2010-04-16 18:55:41 +0000 | |||
1697 | @@ -196,14 +196,14 @@ | |||
1698 | 196 | 196 | ||
1699 | 197 | import t5 | 197 | import t5 |
1700 | 198 | self.assertEqual(fixdir(dir(t5)), | 198 | self.assertEqual(fixdir(dir(t5)), |
1702 | 199 | ['__doc__', '__file__', '__name__', | 199 | ['__cached__', '__doc__', '__file__', '__name__', |
1703 | 200 | '__package__', '__path__', 'foo', 'string', 't5']) | 200 | '__package__', '__path__', 'foo', 'string', 't5']) |
1704 | 201 | self.assertEqual(fixdir(dir(t5.foo)), | 201 | self.assertEqual(fixdir(dir(t5.foo)), |
1707 | 202 | ['__doc__', '__file__', '__name__', '__package__', | 202 | ['__cached__', '__doc__', '__file__', '__name__', |
1708 | 203 | 'string']) | 203 | '__package__', 'string']) |
1709 | 204 | self.assertEqual(fixdir(dir(t5.string)), | 204 | self.assertEqual(fixdir(dir(t5.string)), |
1712 | 205 | ['__doc__', '__file__', '__name__','__package__', | 205 | ['__cached__', '__doc__', '__file__', '__name__', |
1713 | 206 | 'spam']) | 206 | '__package__', 'spam']) |
1714 | 207 | 207 | ||
1715 | 208 | def test_6(self): | 208 | def test_6(self): |
1716 | 209 | hier = [ | 209 | hier = [ |
1717 | @@ -218,13 +218,13 @@ | |||
1718 | 218 | 218 | ||
1719 | 219 | import t6 | 219 | import t6 |
1720 | 220 | self.assertEqual(fixdir(dir(t6)), | 220 | self.assertEqual(fixdir(dir(t6)), |
1722 | 221 | ['__all__', '__doc__', '__file__', | 221 | ['__all__', '__cached__', '__doc__', '__file__', |
1723 | 222 | '__name__', '__package__', '__path__']) | 222 | '__name__', '__package__', '__path__']) |
1724 | 223 | s = """ | 223 | s = """ |
1725 | 224 | import t6 | 224 | import t6 |
1726 | 225 | from t6 import * | 225 | from t6 import * |
1727 | 226 | self.assertEqual(fixdir(dir(t6)), | 226 | self.assertEqual(fixdir(dir(t6)), |
1729 | 227 | ['__all__', '__doc__', '__file__', | 227 | ['__all__', '__cached__', '__doc__', '__file__', |
1730 | 228 | '__name__', '__package__', '__path__', | 228 | '__name__', '__package__', '__path__', |
1731 | 229 | 'eggs', 'ham', 'spam']) | 229 | 'eggs', 'ham', 'spam']) |
1732 | 230 | self.assertEqual(dir(), ['eggs', 'ham', 'self', 'spam', 't6']) | 230 | self.assertEqual(dir(), ['eggs', 'ham', 'self', 'spam', 't6']) |
1733 | @@ -252,18 +252,18 @@ | |||
1734 | 252 | t7, sub, subsub = None, None, None | 252 | t7, sub, subsub = None, None, None |
1735 | 253 | import t7 as tas | 253 | import t7 as tas |
1736 | 254 | self.assertEqual(fixdir(dir(tas)), | 254 | self.assertEqual(fixdir(dir(tas)), |
1738 | 255 | ['__doc__', '__file__', '__name__', | 255 | ['__cached__', '__doc__', '__file__', '__name__', |
1739 | 256 | '__package__', '__path__']) | 256 | '__package__', '__path__']) |
1740 | 257 | self.assertFalse(t7) | 257 | self.assertFalse(t7) |
1741 | 258 | from t7 import sub as subpar | 258 | from t7 import sub as subpar |
1742 | 259 | self.assertEqual(fixdir(dir(subpar)), | 259 | self.assertEqual(fixdir(dir(subpar)), |
1744 | 260 | ['__doc__', '__file__', '__name__', | 260 | ['__cached__', '__doc__', '__file__', '__name__', |
1745 | 261 | '__package__', '__path__']) | 261 | '__package__', '__path__']) |
1746 | 262 | self.assertFalse(t7) | 262 | self.assertFalse(t7) |
1747 | 263 | self.assertFalse(sub) | 263 | self.assertFalse(sub) |
1748 | 264 | from t7.sub import subsub as subsubsub | 264 | from t7.sub import subsub as subsubsub |
1749 | 265 | self.assertEqual(fixdir(dir(subsubsub)), | 265 | self.assertEqual(fixdir(dir(subsubsub)), |
1751 | 266 | ['__doc__', '__file__', '__name__', | 266 | ['__cached__', '__doc__', '__file__', '__name__', |
1752 | 267 | '__package__', '__path__', 'spam']) | 267 | '__package__', '__path__', 'spam']) |
1753 | 268 | self.assertFalse(t7) | 268 | self.assertFalse(t7) |
1754 | 269 | self.assertFalse(sub) | 269 | self.assertFalse(sub) |
1755 | 270 | 270 | ||
1756 | === modified file 'Lib/test/test_pkgimport.py' | |||
1757 | --- Lib/test/test_pkgimport.py 2010-01-23 15:40:09 +0000 | |||
1758 | +++ Lib/test/test_pkgimport.py 2010-04-16 18:55:41 +0000 | |||
1759 | @@ -1,5 +1,12 @@ | |||
1761 | 1 | import os, sys, string, random, tempfile, unittest | 1 | import os |
1762 | 2 | import sys | ||
1763 | 3 | import shutil | ||
1764 | 4 | import string | ||
1765 | 5 | import random | ||
1766 | 6 | import tempfile | ||
1767 | 7 | import unittest | ||
1768 | 2 | 8 | ||
1769 | 9 | from imp import cache_from_source | ||
1770 | 3 | from test.support import run_unittest | 10 | from test.support import run_unittest |
1771 | 4 | 11 | ||
1772 | 5 | class TestImport(unittest.TestCase): | 12 | class TestImport(unittest.TestCase): |
1773 | @@ -26,22 +33,17 @@ | |||
1774 | 26 | self.module_path = os.path.join(self.package_dir, 'foo.py') | 33 | self.module_path = os.path.join(self.package_dir, 'foo.py') |
1775 | 27 | 34 | ||
1776 | 28 | def tearDown(self): | 35 | def tearDown(self): |
1781 | 29 | for file in os.listdir(self.package_dir): | 36 | shutil.rmtree(self.test_dir) |
1778 | 30 | os.remove(os.path.join(self.package_dir, file)) | ||
1779 | 31 | os.rmdir(self.package_dir) | ||
1780 | 32 | os.rmdir(self.test_dir) | ||
1782 | 33 | self.assertNotEqual(sys.path.count(self.test_dir), 0) | 37 | self.assertNotEqual(sys.path.count(self.test_dir), 0) |
1783 | 34 | sys.path.remove(self.test_dir) | 38 | sys.path.remove(self.test_dir) |
1784 | 35 | self.remove_modules() | 39 | self.remove_modules() |
1785 | 36 | 40 | ||
1786 | 37 | def rewrite_file(self, contents): | 41 | def rewrite_file(self, contents): |
1794 | 38 | for extension in "co": | 42 | compiled_path = cache_from_source(self.module_path) |
1795 | 39 | compiled_path = self.module_path + extension | 43 | if os.path.exists(compiled_path): |
1796 | 40 | if os.path.exists(compiled_path): | 44 | os.remove(compiled_path) |
1797 | 41 | os.remove(compiled_path) | 45 | with open(self.module_path, 'w') as f: |
1798 | 42 | f = open(self.module_path, 'w') | 46 | f.write(contents) |
1792 | 43 | f.write(contents) | ||
1793 | 44 | f.close() | ||
1799 | 45 | 47 | ||
1800 | 46 | def test_package_import__semantics(self): | 48 | def test_package_import__semantics(self): |
1801 | 47 | 49 | ||
1802 | 48 | 50 | ||
1803 | === modified file 'Lib/test/test_pydoc.py' | |||
1804 | --- Lib/test/test_pydoc.py 2010-03-31 02:19:28 +0000 | |||
1805 | +++ Lib/test/test_pydoc.py 2010-04-16 18:55:41 +0000 | |||
1806 | @@ -19,8 +19,7 @@ | |||
1807 | 19 | if hasattr(pydoc_mod, "__loader__"): | 19 | if hasattr(pydoc_mod, "__loader__"): |
1808 | 20 | del pydoc_mod.__loader__ | 20 | del pydoc_mod.__loader__ |
1809 | 21 | 21 | ||
1812 | 22 | expected_text_pattern = \ | 22 | expected_text_pattern = """ |
1811 | 23 | """ | ||
1813 | 24 | NAME | 23 | NAME |
1814 | 25 | test.pydoc_mod - This is a test module for test_pydoc | 24 | test.pydoc_mod - This is a test module for test_pydoc |
1815 | 26 | 25 | ||
1816 | @@ -87,8 +86,7 @@ | |||
1817 | 87 | Nobody | 86 | Nobody |
1818 | 88 | """.strip() | 87 | """.strip() |
1819 | 89 | 88 | ||
1822 | 90 | expected_html_pattern = \ | 89 | expected_html_pattern = """ |
1821 | 91 | """ | ||
1823 | 92 | <table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading"> | 90 | <table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading"> |
1824 | 93 | <tr bgcolor="#7799ee"> | 91 | <tr bgcolor="#7799ee"> |
1825 | 94 | <td valign=bottom> <br> | 92 | <td valign=bottom> <br> |
1826 | @@ -186,7 +184,7 @@ | |||
1827 | 186 | \x20\x20\x20\x20 | 184 | \x20\x20\x20\x20 |
1828 | 187 | <tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td> | 185 | <tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td> |
1829 | 188 | <td width="100%%">Nobody</td></tr></table> | 186 | <td width="100%%">Nobody</td></tr></table> |
1831 | 189 | """.strip() | 187 | """.strip() # ' <- emacs turd |
1832 | 190 | 188 | ||
1833 | 191 | 189 | ||
1834 | 192 | # output pattern for missing module | 190 | # output pattern for missing module |
1835 | @@ -287,7 +285,8 @@ | |||
1836 | 287 | ('i_am_not_here', 'i_am_not_here'), | 285 | ('i_am_not_here', 'i_am_not_here'), |
1837 | 288 | ('test.i_am_not_here_either', 'i_am_not_here_either'), | 286 | ('test.i_am_not_here_either', 'i_am_not_here_either'), |
1838 | 289 | ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'), | 287 | ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'), |
1840 | 290 | ('i_am_not_here.{}'.format(modname), 'i_am_not_here.{}'.format(modname)), | 288 | ('i_am_not_here.{}'.format(modname), |
1841 | 289 | 'i_am_not_here.{}'.format(modname)), | ||
1842 | 291 | ('test.{}'.format(modname), modname), | 290 | ('test.{}'.format(modname), modname), |
1843 | 292 | ) | 291 | ) |
1844 | 293 | 292 | ||
1845 | @@ -304,9 +303,8 @@ | |||
1846 | 304 | fullmodname = os.path.join(TESTFN, modname) | 303 | fullmodname = os.path.join(TESTFN, modname) |
1847 | 305 | sourcefn = fullmodname + os.extsep + "py" | 304 | sourcefn = fullmodname + os.extsep + "py" |
1848 | 306 | for importstring, expectedinmsg in testpairs: | 305 | for importstring, expectedinmsg in testpairs: |
1852 | 307 | f = open(sourcefn, 'w') | 306 | with open(sourcefn, 'w') as f: |
1853 | 308 | f.write("import {}\n".format(importstring)) | 307 | f.write("import {}\n".format(importstring)) |
1851 | 309 | f.close() | ||
1854 | 310 | try: | 308 | try: |
1855 | 311 | result = run_pydoc(modname).decode("ascii") | 309 | result = run_pydoc(modname).decode("ascii") |
1856 | 312 | finally: | 310 | finally: |
1857 | 313 | 311 | ||
1858 | === modified file 'Lib/test/test_runpy.py' | |||
1859 | --- Lib/test/test_runpy.py 2010-01-19 00:09:57 +0000 | |||
1860 | +++ Lib/test/test_runpy.py 2010-04-16 18:55:41 +0000 | |||
1861 | @@ -5,9 +5,10 @@ | |||
1862 | 5 | import sys | 5 | import sys |
1863 | 6 | import re | 6 | import re |
1864 | 7 | import tempfile | 7 | import tempfile |
1868 | 8 | from test.support import verbose, run_unittest, forget | 8 | import py_compile |
1869 | 9 | from test.script_helper import (temp_dir, make_script, compile_script, | 9 | from test.support import forget, make_legacy_pyc, run_unittest, verbose |
1870 | 10 | make_pkg, make_zip_script, make_zip_pkg) | 10 | from test.script_helper import ( |
1871 | 11 | make_pkg, make_script, make_zip_pkg, make_zip_script, temp_dir) | ||
1872 | 11 | 12 | ||
1873 | 12 | 13 | ||
1874 | 13 | from runpy import _run_code, _run_module_code, run_module, run_path | 14 | from runpy import _run_code, _run_module_code, run_module, run_path |
1875 | @@ -45,6 +46,7 @@ | |||
1876 | 45 | self.assertEqual(d["result"], self.expected_result) | 46 | self.assertEqual(d["result"], self.expected_result) |
1877 | 46 | self.assertIs(d["__name__"], None) | 47 | self.assertIs(d["__name__"], None) |
1878 | 47 | self.assertIs(d["__file__"], None) | 48 | self.assertIs(d["__file__"], None) |
1879 | 49 | self.assertIs(d["__cached__"], None) | ||
1880 | 48 | self.assertIs(d["__loader__"], None) | 50 | self.assertIs(d["__loader__"], None) |
1881 | 49 | self.assertIs(d["__package__"], None) | 51 | self.assertIs(d["__package__"], None) |
1882 | 50 | self.assertIs(d["run_argv0"], saved_argv0) | 52 | self.assertIs(d["run_argv0"], saved_argv0) |
1883 | @@ -73,6 +75,7 @@ | |||
1884 | 73 | self.assertTrue(d2["run_name_in_sys_modules"]) | 75 | self.assertTrue(d2["run_name_in_sys_modules"]) |
1885 | 74 | self.assertTrue(d2["module_in_sys_modules"]) | 76 | self.assertTrue(d2["module_in_sys_modules"]) |
1886 | 75 | self.assertIs(d2["__file__"], file) | 77 | self.assertIs(d2["__file__"], file) |
1887 | 78 | self.assertIs(d2["__cached__"], None) | ||
1888 | 76 | self.assertIs(d2["run_argv0"], file) | 79 | self.assertIs(d2["run_argv0"], file) |
1889 | 77 | self.assertIs(d2["__loader__"], loader) | 80 | self.assertIs(d2["__loader__"], loader) |
1890 | 78 | self.assertIs(d2["__package__"], package) | 81 | self.assertIs(d2["__package__"], package) |
1891 | @@ -170,6 +173,7 @@ | |||
1892 | 170 | del d1 # Ensure __loader__ entry doesn't keep file open | 173 | del d1 # Ensure __loader__ entry doesn't keep file open |
1893 | 171 | __import__(mod_name) | 174 | __import__(mod_name) |
1894 | 172 | os.remove(mod_fname) | 175 | os.remove(mod_fname) |
1895 | 176 | make_legacy_pyc(mod_fname) | ||
1896 | 173 | if verbose: print("Running from compiled:", mod_name) | 177 | if verbose: print("Running from compiled:", mod_name) |
1897 | 174 | d2 = run_module(mod_name) # Read from bytecode | 178 | d2 = run_module(mod_name) # Read from bytecode |
1898 | 175 | self.assertIn("x", d2) | 179 | self.assertIn("x", d2) |
1899 | @@ -192,6 +196,7 @@ | |||
1900 | 192 | del d1 # Ensure __loader__ entry doesn't keep file open | 196 | del d1 # Ensure __loader__ entry doesn't keep file open |
1901 | 193 | __import__(mod_name) | 197 | __import__(mod_name) |
1902 | 194 | os.remove(mod_fname) | 198 | os.remove(mod_fname) |
1903 | 199 | make_legacy_pyc(mod_fname) | ||
1904 | 195 | if verbose: print("Running from compiled:", pkg_name) | 200 | if verbose: print("Running from compiled:", pkg_name) |
1905 | 196 | d2 = run_module(pkg_name) # Read from bytecode | 201 | d2 = run_module(pkg_name) # Read from bytecode |
1906 | 197 | self.assertIn("x", d2) | 202 | self.assertIn("x", d2) |
1907 | @@ -246,6 +251,7 @@ | |||
1908 | 246 | del d1 # Ensure __loader__ entry doesn't keep file open | 251 | del d1 # Ensure __loader__ entry doesn't keep file open |
1909 | 247 | __import__(mod_name) | 252 | __import__(mod_name) |
1910 | 248 | os.remove(mod_fname) | 253 | os.remove(mod_fname) |
1911 | 254 | make_legacy_pyc(mod_fname) | ||
1912 | 249 | if verbose: print("Running from compiled:", mod_name) | 255 | if verbose: print("Running from compiled:", mod_name) |
1913 | 250 | d2 = run_module(mod_name, run_name=run_name) # Read from bytecode | 256 | d2 = run_module(mod_name, run_name=run_name) # Read from bytecode |
1914 | 251 | self.assertIn("__package__", d2) | 257 | self.assertIn("__package__", d2) |
1915 | @@ -313,6 +319,7 @@ | |||
1916 | 313 | result = run_path(script_name) | 319 | result = run_path(script_name) |
1917 | 314 | self.assertEqual(result["__name__"], expected_name) | 320 | self.assertEqual(result["__name__"], expected_name) |
1918 | 315 | self.assertEqual(result["__file__"], expected_file) | 321 | self.assertEqual(result["__file__"], expected_file) |
1919 | 322 | self.assertEqual(result["__cached__"], None) | ||
1920 | 316 | self.assertIn("argv0", result) | 323 | self.assertIn("argv0", result) |
1921 | 317 | self.assertEqual(result["argv0"], expected_argv0) | 324 | self.assertEqual(result["argv0"], expected_argv0) |
1922 | 318 | self.assertEqual(result["__package__"], expected_package) | 325 | self.assertEqual(result["__package__"], expected_package) |
1923 | @@ -332,7 +339,7 @@ | |||
1924 | 332 | with temp_dir() as script_dir: | 339 | with temp_dir() as script_dir: |
1925 | 333 | mod_name = 'script' | 340 | mod_name = 'script' |
1926 | 334 | script_name = self._make_test_script(script_dir, mod_name) | 341 | script_name = self._make_test_script(script_dir, mod_name) |
1928 | 335 | compiled_name = compile_script(script_name) | 342 | compiled_name = py_compile.compile(script_name, doraise=True) |
1929 | 336 | os.remove(script_name) | 343 | os.remove(script_name) |
1930 | 337 | self._check_script(compiled_name, "<run_path>", compiled_name, | 344 | self._check_script(compiled_name, "<run_path>", compiled_name, |
1931 | 338 | compiled_name, None) | 345 | compiled_name, None) |
1932 | @@ -348,9 +355,10 @@ | |||
1933 | 348 | with temp_dir() as script_dir: | 355 | with temp_dir() as script_dir: |
1934 | 349 | mod_name = '__main__' | 356 | mod_name = '__main__' |
1935 | 350 | script_name = self._make_test_script(script_dir, mod_name) | 357 | script_name = self._make_test_script(script_dir, mod_name) |
1937 | 351 | compiled_name = compile_script(script_name) | 358 | compiled_name = py_compile.compile(script_name, doraise=True) |
1938 | 352 | os.remove(script_name) | 359 | os.remove(script_name) |
1940 | 353 | self._check_script(script_dir, "<run_path>", compiled_name, | 360 | legacy_pyc = make_legacy_pyc(script_name) |
1941 | 361 | self._check_script(script_dir, "<run_path>", legacy_pyc, | ||
1942 | 354 | script_dir, '') | 362 | script_dir, '') |
1943 | 355 | 363 | ||
1944 | 356 | def test_directory_error(self): | 364 | def test_directory_error(self): |
1945 | @@ -371,8 +379,9 @@ | |||
1946 | 371 | with temp_dir() as script_dir: | 379 | with temp_dir() as script_dir: |
1947 | 372 | mod_name = '__main__' | 380 | mod_name = '__main__' |
1948 | 373 | script_name = self._make_test_script(script_dir, mod_name) | 381 | script_name = self._make_test_script(script_dir, mod_name) |
1951 | 374 | compiled_name = compile_script(script_name) | 382 | compiled_name = py_compile.compile(script_name, doraise=True) |
1952 | 375 | zip_name, fname = make_zip_script(script_dir, 'test_zip', compiled_name) | 383 | zip_name, fname = make_zip_script(script_dir, 'test_zip', |
1953 | 384 | compiled_name) | ||
1954 | 376 | self._check_script(zip_name, "<run_path>", fname, zip_name, '') | 385 | self._check_script(zip_name, "<run_path>", fname, zip_name, '') |
1955 | 377 | 386 | ||
1956 | 378 | def test_zipfile_error(self): | 387 | def test_zipfile_error(self): |
1957 | 379 | 388 | ||
1958 | === modified file 'Lib/test/test_site.py' | |||
1959 | --- Lib/test/test_site.py 2010-01-29 11:41:03 +0000 | |||
1960 | +++ Lib/test/test_site.py 2010-04-16 18:55:41 +0000 | |||
1961 | @@ -258,19 +258,38 @@ | |||
1962 | 258 | """Restore sys.path""" | 258 | """Restore sys.path""" |
1963 | 259 | sys.path[:] = self.sys_path | 259 | sys.path[:] = self.sys_path |
1964 | 260 | 260 | ||
1978 | 261 | def test_abs__file__(self): | 261 | def test_abs_paths(self): |
1979 | 262 | # Make sure all imported modules have their __file__ attribute | 262 | # Make sure all imported modules have their __file__ and __cached__ |
1980 | 263 | # as an absolute path. | 263 | # attributes as absolute paths. Arranging to put the Lib directory on |
1981 | 264 | # Handled by abs__file__() | 264 | # PYTHONPATH would cause the os module to have a relative path for |
1982 | 265 | site.abs__file__() | 265 | # __file__ if abs_paths() does not get run. sys and builtins (the |
1983 | 266 | for module in (sys, os, builtins): | 266 | # only other modules imported before site.py runs) do not have |
1984 | 267 | try: | 267 | # __file__ or __cached__ because they are built-in. |
1985 | 268 | self.assertTrue(os.path.isabs(module.__file__), repr(module)) | 268 | parent = os.path.relpath(os.path.dirname(os.__file__)) |
1986 | 269 | except AttributeError: | 269 | env = os.environ.copy() |
1987 | 270 | continue | 270 | env['PYTHONPATH'] = parent |
1988 | 271 | # We could try everything in sys.modules; however, when regrtest.py | 271 | command = 'import os; print(os.__file__, os.__cached__)' |
1989 | 272 | # runs something like test_frozen before test_site, then we will | 272 | # First, prove that with -S (no 'import site'), the paths are |
1990 | 273 | # be testing things loaded *after* test_site did path normalization | 273 | # relative. |
1991 | 274 | proc = subprocess.Popen([sys.executable, '-S', '-c', command], | ||
1992 | 275 | env=env, | ||
1993 | 276 | stdout=subprocess.PIPE, | ||
1994 | 277 | stderr=subprocess.PIPE) | ||
1995 | 278 | stdout, stderr = proc.communicate() | ||
1996 | 279 | self.assertEqual(proc.returncode, 0) | ||
1997 | 280 | os__file__, os__cached__ = stdout.split() | ||
1998 | 281 | self.assertFalse(os.path.isabs(os__file__)) | ||
1999 | 282 | self.assertFalse(os.path.isabs(os__cached__)) | ||
2000 | 283 | # Now, with 'import site', it works. | ||
2001 | 284 | proc = subprocess.Popen([sys.executable, '-c', command], | ||
2002 | 285 | env=env, | ||
2003 | 286 | stdout=subprocess.PIPE, | ||
2004 | 287 | stderr=subprocess.PIPE) | ||
2005 | 288 | stdout, stderr = proc.communicate() | ||
2006 | 289 | self.assertEqual(proc.returncode, 0) | ||
2007 | 290 | os__file__, os__cached__ = stdout.split() | ||
2008 | 291 | self.assertTrue(os.path.isabs(os__file__)) | ||
2009 | 292 | self.assertTrue(os.path.isabs(os__cached__)) | ||
2010 | 274 | 293 | ||
2011 | 275 | def test_no_duplicate_paths(self): | 294 | def test_no_duplicate_paths(self): |
2012 | 276 | # No duplicate paths should exist in sys.path | 295 | # No duplicate paths should exist in sys.path |
2013 | 277 | 296 | ||
2014 | === modified file 'Lib/test/test_zipfile.py' | |||
2015 | --- Lib/test/test_zipfile.py 2010-02-07 20:24:02 +0000 | |||
2016 | +++ Lib/test/test_zipfile.py 2010-04-16 18:55:41 +0000 | |||
2017 | @@ -6,6 +6,7 @@ | |||
2018 | 6 | 6 | ||
2019 | 7 | import io | 7 | import io |
2020 | 8 | import os | 8 | import os |
2021 | 9 | import imp | ||
2022 | 9 | import time | 10 | import time |
2023 | 10 | import shutil | 11 | import shutil |
2024 | 11 | import struct | 12 | import struct |
2025 | @@ -587,7 +588,13 @@ | |||
2026 | 587 | with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp: | 588 | with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp: |
2027 | 588 | fn = __file__ | 589 | fn = __file__ |
2028 | 589 | if fn.endswith('.pyc') or fn.endswith('.pyo'): | 590 | if fn.endswith('.pyc') or fn.endswith('.pyo'): |
2030 | 590 | fn = fn[:-1] | 591 | path_split = fn.split(os.sep) |
2031 | 592 | if os.altsep is not None: | ||
2032 | 593 | path_split.extend(fn.split(os.altsep)) | ||
2033 | 594 | if '__pycache__' in path_split: | ||
2034 | 595 | fn = imp.source_from_cache(fn) | ||
2035 | 596 | else: | ||
2036 | 597 | fn = fn[:-1] | ||
2037 | 591 | 598 | ||
2038 | 592 | zipfp.writepy(fn) | 599 | zipfp.writepy(fn) |
2039 | 593 | 600 | ||
2040 | 594 | 601 | ||
2041 | === modified file 'Lib/test/test_zipimport.py' | |||
2042 | --- Lib/test/test_zipimport.py 2010-03-14 10:23:39 +0000 | |||
2043 | +++ Lib/test/test_zipimport.py 2010-04-16 18:55:41 +0000 | |||
2044 | @@ -48,17 +48,14 @@ | |||
2045 | 48 | test_pyc = make_pyc(test_co, NOW) | 48 | test_pyc = make_pyc(test_co, NOW) |
2046 | 49 | 49 | ||
2047 | 50 | 50 | ||
2048 | 51 | if __debug__: | ||
2049 | 52 | pyc_ext = ".pyc" | ||
2050 | 53 | else: | ||
2051 | 54 | pyc_ext = ".pyo" | ||
2052 | 55 | |||
2053 | 56 | |||
2054 | 57 | TESTMOD = "ziptestmodule" | 51 | TESTMOD = "ziptestmodule" |
2055 | 58 | TESTPACK = "ziptestpackage" | 52 | TESTPACK = "ziptestpackage" |
2056 | 59 | TESTPACK2 = "ziptestpackage2" | 53 | TESTPACK2 = "ziptestpackage2" |
2057 | 60 | TEMP_ZIP = os.path.abspath("junk95142.zip") | 54 | TEMP_ZIP = os.path.abspath("junk95142.zip") |
2058 | 61 | 55 | ||
2059 | 56 | pyc_file = imp.cache_from_source(TESTMOD + '.py') | ||
2060 | 57 | pyc_ext = ('.pyc' if __debug__ else '.pyo') | ||
2061 | 58 | |||
2062 | 62 | 59 | ||
2063 | 63 | class UncompressedZipImportTestCase(ImportHooksBaseTestCase): | 60 | class UncompressedZipImportTestCase(ImportHooksBaseTestCase): |
2064 | 64 | 61 | ||
2065 | @@ -83,14 +80,11 @@ | |||
2066 | 83 | stuff = kw.get("stuff", None) | 80 | stuff = kw.get("stuff", None) |
2067 | 84 | if stuff is not None: | 81 | if stuff is not None: |
2068 | 85 | # Prepend 'stuff' to the start of the zipfile | 82 | # Prepend 'stuff' to the start of the zipfile |
2077 | 86 | f = open(TEMP_ZIP, "rb") | 83 | with open(TEMP_ZIP, "rb") as f: |
2078 | 87 | data = f.read() | 84 | data = f.read() |
2079 | 88 | f.close() | 85 | with open(TEMP_ZIP, "wb") as f: |
2080 | 89 | 86 | f.write(stuff) | |
2081 | 90 | f = open(TEMP_ZIP, "wb") | 87 | f.write(data) |
2074 | 91 | f.write(stuff) | ||
2075 | 92 | f.write(data) | ||
2076 | 93 | f.close() | ||
2082 | 94 | 88 | ||
2083 | 95 | sys.path.insert(0, TEMP_ZIP) | 89 | sys.path.insert(0, TEMP_ZIP) |
2084 | 96 | 90 | ||
2085 | @@ -180,8 +174,9 @@ | |||
2086 | 180 | 174 | ||
2087 | 181 | def testBadMTime(self): | 175 | def testBadMTime(self): |
2088 | 182 | badtime_pyc = bytearray(test_pyc) | 176 | badtime_pyc = bytearray(test_pyc) |
2091 | 183 | badtime_pyc[7] ^= 0x02 # flip the second bit -- not the first as that one | 177 | # flip the second bit -- not the first as that one isn't stored in the |
2092 | 184 | # isn't stored in the .py's mtime in the zip archive. | 178 | # .py's mtime in the zip archive. |
2093 | 179 | badtime_pyc[7] ^= 0x02 | ||
2094 | 185 | files = {TESTMOD + ".py": (NOW, test_src), | 180 | files = {TESTMOD + ".py": (NOW, test_src), |
2095 | 186 | TESTMOD + pyc_ext: (NOW, badtime_pyc)} | 181 | TESTMOD + pyc_ext: (NOW, badtime_pyc)} |
2096 | 187 | self.doTest(".py", files, TESTMOD) | 182 | self.doTest(".py", files, TESTMOD) |
2097 | @@ -232,7 +227,8 @@ | |||
2098 | 232 | self.assertEquals(zi.get_source(TESTPACK), None) | 227 | self.assertEquals(zi.get_source(TESTPACK), None) |
2099 | 233 | self.assertEquals(zi.get_source(mod_path), None) | 228 | self.assertEquals(zi.get_source(mod_path), None) |
2100 | 234 | self.assertEquals(zi.get_filename(mod_path), mod.__file__) | 229 | self.assertEquals(zi.get_filename(mod_path), mod.__file__) |
2102 | 235 | # To pass in the module name instead of the path, we must use the right importer | 230 | # To pass in the module name instead of the path, we must use the |
2103 | 231 | # right importer | ||
2104 | 236 | loader = mod.__loader__ | 232 | loader = mod.__loader__ |
2105 | 237 | self.assertEquals(loader.get_source(mod_name), None) | 233 | self.assertEquals(loader.get_source(mod_name), None) |
2106 | 238 | self.assertEquals(loader.get_filename(mod_name), mod.__file__) | 234 | self.assertEquals(loader.get_filename(mod_name), mod.__file__) |
2107 | @@ -266,8 +262,10 @@ | |||
2108 | 266 | mod = zi.load_module(TESTPACK2) | 262 | mod = zi.load_module(TESTPACK2) |
2109 | 267 | self.assertEquals(zi.get_filename(TESTPACK2), mod.__file__) | 263 | self.assertEquals(zi.get_filename(TESTPACK2), mod.__file__) |
2110 | 268 | 264 | ||
2113 | 269 | self.assertEquals(zi.is_package(TESTPACK2 + os.sep + '__init__'), False) | 265 | self.assertEquals( |
2114 | 270 | self.assertEquals(zi.is_package(TESTPACK2 + os.sep + TESTMOD), False) | 266 | zi.is_package(TESTPACK2 + os.sep + '__init__'), False) |
2115 | 267 | self.assertEquals( | ||
2116 | 268 | zi.is_package(TESTPACK2 + os.sep + TESTMOD), False) | ||
2117 | 271 | 269 | ||
2118 | 272 | mod_path = TESTPACK2 + os.sep + TESTMOD | 270 | mod_path = TESTPACK2 + os.sep + TESTMOD |
2119 | 273 | mod_name = module_path_to_dotted_name(mod_path) | 271 | mod_name = module_path_to_dotted_name(mod_path) |
2120 | @@ -276,7 +274,8 @@ | |||
2121 | 276 | self.assertEquals(zi.get_source(TESTPACK2), None) | 274 | self.assertEquals(zi.get_source(TESTPACK2), None) |
2122 | 277 | self.assertEquals(zi.get_source(mod_path), None) | 275 | self.assertEquals(zi.get_source(mod_path), None) |
2123 | 278 | self.assertEquals(zi.get_filename(mod_path), mod.__file__) | 276 | self.assertEquals(zi.get_filename(mod_path), mod.__file__) |
2125 | 279 | # To pass in the module name instead of the path, we must use the right importer | 277 | # To pass in the module name instead of the path, we must use the |
2126 | 278 | # right importer | ||
2127 | 280 | loader = mod.__loader__ | 279 | loader = mod.__loader__ |
2128 | 281 | self.assertEquals(loader.get_source(mod_name), None) | 280 | self.assertEquals(loader.get_source(mod_name), None) |
2129 | 282 | self.assertEquals(loader.get_filename(mod_name), mod.__file__) | 281 | self.assertEquals(loader.get_filename(mod_name), mod.__file__) |
2130 | 283 | 282 | ||
2131 | === modified file 'Lib/zipfile.py' | |||
2132 | --- Lib/zipfile.py 2010-02-07 20:24:02 +0000 | |||
2133 | +++ Lib/zipfile.py 2010-04-16 18:55:41 +0000 | |||
2134 | @@ -3,10 +3,17 @@ | |||
2135 | 3 | 3 | ||
2136 | 4 | XXX references to utf-8 need further investigation. | 4 | XXX references to utf-8 need further investigation. |
2137 | 5 | """ | 5 | """ |
2138 | 6 | import struct, os, time, sys, shutil | ||
2139 | 7 | import binascii, io, stat | ||
2140 | 8 | import io | 6 | import io |
2141 | 7 | import os | ||
2142 | 9 | import re | 8 | import re |
2143 | 9 | import imp | ||
2144 | 10 | import sys | ||
2145 | 11 | import time | ||
2146 | 12 | import stat | ||
2147 | 13 | import shutil | ||
2148 | 14 | import struct | ||
2149 | 15 | import binascii | ||
2150 | 16 | |||
2151 | 10 | 17 | ||
2152 | 11 | try: | 18 | try: |
2153 | 12 | import zlib # We may need its compression method | 19 | import zlib # We may need its compression method |
2154 | @@ -1303,22 +1310,42 @@ | |||
2155 | 1303 | file_py = pathname + ".py" | 1310 | file_py = pathname + ".py" |
2156 | 1304 | file_pyc = pathname + ".pyc" | 1311 | file_pyc = pathname + ".pyc" |
2157 | 1305 | file_pyo = pathname + ".pyo" | 1312 | file_pyo = pathname + ".pyo" |
2163 | 1306 | if os.path.isfile(file_pyo) and \ | 1313 | pycache_pyc = imp.cache_from_source(file_py, True) |
2164 | 1307 | os.stat(file_pyo).st_mtime >= os.stat(file_py).st_mtime: | 1314 | pycache_pyo = imp.cache_from_source(file_py, False) |
2165 | 1308 | fname = file_pyo # Use .pyo file | 1315 | if (os.path.isfile(file_pyo) and |
2166 | 1309 | elif not os.path.isfile(file_pyc) or \ | 1316 | os.stat(file_pyo).st_mtime >= os.stat(file_py).st_mtime): |
2167 | 1310 | os.stat(file_pyc).st_mtime < os.stat(file_py).st_mtime: | 1317 | # Use .pyo file. |
2168 | 1318 | arcname = fname = file_pyo | ||
2169 | 1319 | elif (os.path.isfile(file_pyc) and | ||
2170 | 1320 | os.stat(file_pyc).st_mtime >= os.stat(file_py).st_mtime): | ||
2171 | 1321 | # Use .pyc file. | ||
2172 | 1322 | arcname = fname = file_pyc | ||
2173 | 1323 | elif (os.path.isfile(pycache_pyc) and | ||
2174 | 1324 | os.stat(pycache_pyc).st_mtime >= os.stat(file_py).st_mtime): | ||
2175 | 1325 | # Use the __pycache__/*.pyc file, but write it to the legacy pyc | ||
2176 | 1326 | # file name in the archive. | ||
2177 | 1327 | fname = pycache_pyc | ||
2178 | 1328 | arcname = file_pyc | ||
2179 | 1329 | elif (os.path.isfile(pycache_pyo) and | ||
2180 | 1330 | os.stat(pycache_pyo).st_mtime >= os.stat(file_py).st_mtime): | ||
2181 | 1331 | # Use the __pycache__/*.pyo file, but write it to the legacy pyo | ||
2182 | 1332 | # file name in the archive. | ||
2183 | 1333 | fname = pycache_pyo | ||
2184 | 1334 | arcname = file_pyo | ||
2185 | 1335 | else: | ||
2186 | 1336 | # Compile py into PEP 3147 pyc file. | ||
2187 | 1311 | import py_compile | 1337 | import py_compile |
2188 | 1312 | if self.debug: | 1338 | if self.debug: |
2189 | 1313 | print("Compiling", file_py) | 1339 | print("Compiling", file_py) |
2190 | 1314 | try: | 1340 | try: |
2193 | 1315 | py_compile.compile(file_py, file_pyc, None, True) | 1341 | py_compile.compile(file_py, doraise=True) |
2194 | 1316 | except py_compile.PyCompileError as err: | 1342 | except py_compile.PyCompileError as error: |
2195 | 1317 | print(err.msg) | 1343 | print(err.msg) |
2200 | 1318 | fname = file_pyc | 1344 | fname = file_py |
2201 | 1319 | else: | 1345 | else: |
2202 | 1320 | fname = file_pyc | 1346 | fname = (pycache_pyc if __debug__ else pycache_pyo) |
2203 | 1321 | archivename = os.path.split(fname)[1] | 1347 | arcname = (file_pyc if __debug__ else file_pyo) |
2204 | 1348 | archivename = os.path.split(arcname)[1] | ||
2205 | 1322 | if basename: | 1349 | if basename: |
2206 | 1323 | archivename = "%s/%s" % (basename, archivename) | 1350 | archivename = "%s/%s" % (basename, archivename) |
2207 | 1324 | return (fname, archivename) | 1351 | return (fname, archivename) |
2208 | 1325 | 1352 | ||
2209 | === modified file 'Makefile.pre.in' | |||
2210 | --- Makefile.pre.in 2010-04-11 23:16:50 +0000 | |||
2211 | +++ Makefile.pre.in 2010-04-16 18:55:41 +0000 | |||
2212 | @@ -1161,6 +1161,7 @@ | |||
2213 | 1161 | # files, which clobber removes as well | 1161 | # files, which clobber removes as well |
2214 | 1162 | pycremoval: | 1162 | pycremoval: |
2215 | 1163 | find $(srcdir) -name '*.py[co]' -exec rm -f {} ';' | 1163 | find $(srcdir) -name '*.py[co]' -exec rm -f {} ';' |
2216 | 1164 | find $(srcdir) -name '__pycache__' | xargs rmdir | ||
2217 | 1164 | 1165 | ||
2218 | 1165 | rmtestturds: | 1166 | rmtestturds: |
2219 | 1166 | -rm -f *BAD *GOOD *SKIPPED | 1167 | -rm -f *BAD *GOOD *SKIPPED |
2220 | 1167 | 1168 | ||
2221 | === modified file 'Python/import.c' | |||
2222 | --- Python/import.c 2010-03-25 23:30:20 +0000 | |||
2223 | +++ Python/import.c 2010-04-16 18:55:41 +0000 | |||
2224 | @@ -43,6 +43,15 @@ | |||
2225 | 43 | The current working scheme is to increment the previous value by | 43 | The current working scheme is to increment the previous value by |
2226 | 44 | 10. | 44 | 10. |
2227 | 45 | 45 | ||
2228 | 46 | Starting with the adoption of PEP 3147 in Python 3.2, every bump in magic | ||
2229 | 47 | number also includes a new "magic tag", i.e. a human readable string used | ||
2230 | 48 | to represent the magic number in __pycache__ directories. When you change | ||
2231 | 49 | the magic number, you must also set a new unique magic tag. Generally this | ||
2232 | 50 | can be named after the Python major version of the magic number bump, but | ||
2233 | 51 | it can really be anything, as long as it's different than anything else | ||
2234 | 52 | that's come before. The tags are included in the following table, starting | ||
2235 | 53 | with Python 3.2a0. | ||
2236 | 54 | |||
2237 | 46 | Known values: | 55 | Known values: |
2238 | 47 | Python 1.5: 20121 | 56 | Python 1.5: 20121 |
2239 | 48 | Python 1.5.1: 20121 | 57 | Python 1.5.1: 20121 |
2240 | @@ -91,11 +100,18 @@ | |||
2241 | 91 | Python 3.1a0: 3151 (optimize conditional branches: | 100 | Python 3.1a0: 3151 (optimize conditional branches: |
2242 | 92 | introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE) | 101 | introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE) |
2243 | 93 | Python 3.2a0: 3160 (add SETUP_WITH) | 102 | Python 3.2a0: 3160 (add SETUP_WITH) |
2244 | 103 | tag: cpython-32 | ||
2245 | 94 | */ | 104 | */ |
2246 | 95 | 105 | ||
2247 | 106 | /* If you change MAGIC, you must change TAG and you must insert the old value | ||
2248 | 107 | into _PyMagicNumberTags below. | ||
2249 | 108 | */ | ||
2250 | 96 | #define MAGIC (3160 | ((long)'\r'<<16) | ((long)'\n'<<24)) | 109 | #define MAGIC (3160 | ((long)'\r'<<16) | ((long)'\n'<<24)) |
2252 | 97 | /* Magic word as global */ | 110 | #define TAG "cpython-32" |
2253 | 111 | #define CACHEDIR "__pycache__" | ||
2254 | 112 | /* Current magic word and string tag as globals. */ | ||
2255 | 98 | static long pyc_magic = MAGIC; | 113 | static long pyc_magic = MAGIC; |
2256 | 114 | static const char *pyc_tag = TAG; | ||
2257 | 99 | 115 | ||
2258 | 100 | /* See _PyImport_FixupExtension() below */ | 116 | /* See _PyImport_FixupExtension() below */ |
2259 | 101 | static PyObject *extensions = NULL; | 117 | static PyObject *extensions = NULL; |
2260 | @@ -517,7 +533,7 @@ | |||
2261 | 517 | } | 533 | } |
2262 | 518 | 534 | ||
2263 | 519 | 535 | ||
2265 | 520 | /* Helper for pythonrun.c -- return magic number */ | 536 | /* Helper for pythonrun.c -- return magic number and tag. */ |
2266 | 521 | 537 | ||
2267 | 522 | long | 538 | long |
2268 | 523 | PyImport_GetMagicNumber(void) | 539 | PyImport_GetMagicNumber(void) |
2269 | @@ -526,6 +542,12 @@ | |||
2270 | 526 | } | 542 | } |
2271 | 527 | 543 | ||
2272 | 528 | 544 | ||
2273 | 545 | const char * | ||
2274 | 546 | PyImport_GetMagicTag(void) | ||
2275 | 547 | { | ||
2276 | 548 | return pyc_tag; | ||
2277 | 549 | } | ||
2278 | 550 | |||
2279 | 529 | /* Magic for extension modules (built-in as well as dynamically | 551 | /* Magic for extension modules (built-in as well as dynamically |
2280 | 530 | loaded). To prevent initializing an extension module more than | 552 | loaded). To prevent initializing an extension module more than |
2281 | 531 | once, we keep a static dictionary 'extensions' keyed by module name | 553 | once, we keep a static dictionary 'extensions' keyed by module name |
2282 | @@ -671,7 +693,10 @@ | |||
2283 | 671 | "sys.modules failed"); | 693 | "sys.modules failed"); |
2284 | 672 | } | 694 | } |
2285 | 673 | 695 | ||
2287 | 674 | static PyObject * get_sourcefile(const char *file); | 696 | static PyObject * get_sourcefile(char *file); |
2288 | 697 | static char *make_source_pathname(char *pathname, char *buf); | ||
2289 | 698 | static char *make_compiled_pathname(char *pathname, char *buf, size_t buflen, | ||
2290 | 699 | int debug); | ||
2291 | 675 | 700 | ||
2292 | 676 | /* Execute a code object in a module and return the module object | 701 | /* Execute a code object in a module and return the module object |
2293 | 677 | * WITH INCREMENTED REFERENCE COUNT. If an error occurs, name is | 702 | * WITH INCREMENTED REFERENCE COUNT. If an error occurs, name is |
2294 | @@ -679,16 +704,28 @@ | |||
2295 | 679 | * in sys.modules. The caller may wish to restore the original | 704 | * in sys.modules. The caller may wish to restore the original |
2296 | 680 | * module object (if any) in this case; PyImport_ReloadModule is an | 705 | * module object (if any) in this case; PyImport_ReloadModule is an |
2297 | 681 | * example. | 706 | * example. |
2298 | 707 | * | ||
2299 | 708 | * Note that PyImport_ExecCodeModuleWithPathnames() is the preferred, richer | ||
2300 | 709 | * interface. The other two exist primarily for backward compatibility. | ||
2301 | 682 | */ | 710 | */ |
2302 | 683 | PyObject * | 711 | PyObject * |
2303 | 684 | PyImport_ExecCodeModule(char *name, PyObject *co) | 712 | PyImport_ExecCodeModule(char *name, PyObject *co) |
2304 | 685 | { | 713 | { |
2306 | 686 | return PyImport_ExecCodeModuleEx(name, co, (char *)NULL); | 714 | return PyImport_ExecCodeModuleWithPathnames( |
2307 | 715 | name, co, (char *)NULL, (char *)NULL); | ||
2308 | 687 | } | 716 | } |
2309 | 688 | 717 | ||
2310 | 689 | PyObject * | 718 | PyObject * |
2311 | 690 | PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname) | 719 | PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname) |
2312 | 691 | { | 720 | { |
2313 | 721 | return PyImport_ExecCodeModuleWithPathnames( | ||
2314 | 722 | name, co, pathname, (char *)NULL); | ||
2315 | 723 | } | ||
2316 | 724 | |||
2317 | 725 | PyObject * | ||
2318 | 726 | PyImport_ExecCodeModuleWithPathnames(char *name, PyObject *co, char *pathname, | ||
2319 | 727 | char *cpathname) | ||
2320 | 728 | { | ||
2321 | 692 | PyObject *modules = PyImport_GetModuleDict(); | 729 | PyObject *modules = PyImport_GetModuleDict(); |
2322 | 693 | PyObject *m, *d, *v; | 730 | PyObject *m, *d, *v; |
2323 | 694 | 731 | ||
2324 | @@ -718,6 +755,20 @@ | |||
2325 | 718 | PyErr_Clear(); /* Not important enough to report */ | 755 | PyErr_Clear(); /* Not important enough to report */ |
2326 | 719 | Py_DECREF(v); | 756 | Py_DECREF(v); |
2327 | 720 | 757 | ||
2328 | 758 | /* Remember the pyc path name as the __cached__ attribute. */ | ||
2329 | 759 | if (cpathname == NULL) { | ||
2330 | 760 | v = Py_None; | ||
2331 | 761 | Py_INCREF(v); | ||
2332 | 762 | } | ||
2333 | 763 | else if ((v = PyUnicode_FromString(cpathname)) == NULL) { | ||
2334 | 764 | PyErr_Clear(); /* Not important enough to report */ | ||
2335 | 765 | v = Py_None; | ||
2336 | 766 | Py_INCREF(v); | ||
2337 | 767 | } | ||
2338 | 768 | if (PyDict_SetItemString(d, "__cached__", v) != 0) | ||
2339 | 769 | PyErr_Clear(); /* Not important enough to report */ | ||
2340 | 770 | Py_DECREF(v); | ||
2341 | 771 | |||
2342 | 721 | v = PyEval_EvalCode((PyCodeObject *)co, d, d); | 772 | v = PyEval_EvalCode((PyCodeObject *)co, d, d); |
2343 | 722 | if (v == NULL) | 773 | if (v == NULL) |
2344 | 723 | goto error; | 774 | goto error; |
2345 | @@ -740,31 +791,188 @@ | |||
2346 | 740 | } | 791 | } |
2347 | 741 | 792 | ||
2348 | 742 | 793 | ||
2349 | 794 | /* Like strrchr(string, '/') but searches for the rightmost of either SEP | ||
2350 | 795 | or ALTSEP, if the latter is defined. | ||
2351 | 796 | */ | ||
2352 | 797 | static char * | ||
2353 | 798 | rightmost_sep(char *s) | ||
2354 | 799 | { | ||
2355 | 800 | char *found, c; | ||
2356 | 801 | for (found = NULL; (c = *s); s++) { | ||
2357 | 802 | if (c == SEP | ||
2358 | 803 | #ifdef ALTSEP | ||
2359 | 804 | || c == ALTSEP | ||
2360 | 805 | #endif | ||
2361 | 806 | ) | ||
2362 | 807 | { | ||
2363 | 808 | found = s; | ||
2364 | 809 | } | ||
2365 | 810 | } | ||
2366 | 811 | return found; | ||
2367 | 812 | } | ||
2368 | 813 | |||
2369 | 814 | |||
2370 | 743 | /* Given a pathname for a Python source file, fill a buffer with the | 815 | /* Given a pathname for a Python source file, fill a buffer with the |
2371 | 744 | pathname for the corresponding compiled file. Return the pathname | 816 | pathname for the corresponding compiled file. Return the pathname |
2372 | 745 | for the compiled file, or NULL if there's no space in the buffer. | 817 | for the compiled file, or NULL if there's no space in the buffer. |
2373 | 746 | Doesn't set an exception. */ | 818 | Doesn't set an exception. */ |
2374 | 747 | 819 | ||
2375 | 748 | static char * | 820 | static char * |
2377 | 749 | make_compiled_pathname(char *pathname, char *buf, size_t buflen) | 821 | make_compiled_pathname(char *pathname, char *buf, size_t buflen, int debug) |
2378 | 750 | { | 822 | { |
2379 | 823 | /* foo.py -> __pycache__/foo.<tag>.pyc */ | ||
2380 | 751 | size_t len = strlen(pathname); | 824 | size_t len = strlen(pathname); |
2382 | 752 | if (len+2 > buflen) | 825 | size_t i, save; |
2383 | 826 | char *pos; | ||
2384 | 827 | int sep = SEP; | ||
2385 | 828 | |||
2386 | 829 | /* Sanity check that the buffer has roughly enough space to hold what | ||
2387 | 830 | will eventually be the full path to the compiled file. The 5 extra | ||
2388 | 831 | bytes include the slash afer __pycache__, the two extra dots, the | ||
2389 | 832 | extra trailing character ('c' or 'o') and null. This isn't exact | ||
2390 | 833 | because the contents of the buffer can affect how many actual | ||
2391 | 834 | characters of the string get into the buffer. We'll do a final | ||
2392 | 835 | sanity check before writing the extension to ensure we do not | ||
2393 | 836 | overflow the buffer. | ||
2394 | 837 | */ | ||
2395 | 838 | if (len + strlen(CACHEDIR) + strlen(pyc_tag) + 5 > buflen) | ||
2396 | 753 | return NULL; | 839 | return NULL; |
2397 | 754 | 840 | ||
2403 | 755 | #ifdef MS_WINDOWS | 841 | /* Find the last path separator and copy everything from the start of |
2404 | 756 | /* Treat .pyw as if it were .py. The case of ".pyw" must match | 842 | the source string up to and including the separator. |
2405 | 757 | that used in _PyImport_StandardFiletab. */ | 843 | */ |
2406 | 758 | if (len >= 4 && strcmp(&pathname[len-4], ".pyw") == 0) | 844 | if ((pos = rightmost_sep(pathname)) == NULL) { |
2407 | 759 | --len; /* pretend 'w' isn't there */ | 845 | i = 0; |
2408 | 846 | } | ||
2409 | 847 | else { | ||
2410 | 848 | sep = *pos; | ||
2411 | 849 | i = pos - pathname + 1; | ||
2412 | 850 | strncpy(buf, pathname, i); | ||
2413 | 851 | } | ||
2414 | 852 | |||
2415 | 853 | save = i; | ||
2416 | 854 | buf[i++] = '\0'; | ||
2417 | 855 | /* Add __pycache__/ */ | ||
2418 | 856 | strcat(buf, CACHEDIR); | ||
2419 | 857 | i += strlen(CACHEDIR) - 1; | ||
2420 | 858 | buf[i++] = sep; | ||
2421 | 859 | buf[i++] = '\0'; | ||
2422 | 860 | /* Add the base filename, but remove the .py or .pyw extension, since | ||
2423 | 861 | the tag name must go before the extension. | ||
2424 | 862 | */ | ||
2425 | 863 | strcat(buf, pathname + save); | ||
2426 | 864 | if ((pos = strrchr(buf, '.')) != NULL) | ||
2427 | 865 | *++pos = '\0'; | ||
2428 | 866 | strcat(buf, pyc_tag); | ||
2429 | 867 | /* The length test above assumes that we're only adding one character | ||
2430 | 868 | to the end of what would normally be the extension. What if there | ||
2431 | 869 | is no extension, or the string ends in '.' or '.p', and otherwise | ||
2432 | 870 | fills the buffer? By appending 4 more characters onto the string | ||
2433 | 871 | here, we could overrun the buffer. | ||
2434 | 872 | |||
2435 | 873 | As a simple example, let's say buflen=32 and the input string is | ||
2436 | 874 | 'xxx.py'. strlen() would be 6 and the test above would yield: | ||
2437 | 875 | |||
2438 | 876 | (6 + 11 + 10 + 5 == 32) > 32 | ||
2439 | 877 | |||
2440 | 878 | which is false and so the name mangling would continue. This would | ||
2441 | 879 | be fine because we'd end up with this string in buf: | ||
2442 | 880 | |||
2443 | 881 | __pycache__/xxx.cpython-32.pyc\0 | ||
2444 | 882 | |||
2445 | 883 | strlen(of that) == 30 + the nul fits inside a 32 character buffer. | ||
2446 | 884 | We can even handle an input string of say 'xxxxx' above because | ||
2447 | 885 | that's (5 + 11 + 10 + 5 == 31) > 32 which is also false. Name | ||
2448 | 886 | mangling that yields: | ||
2449 | 887 | |||
2450 | 888 | __pycache__/xxxxxcpython-32.pyc\0 | ||
2451 | 889 | |||
2452 | 890 | which is 32 characters including the nul, and thus fits in the | ||
2453 | 891 | buffer. However, an input string of 'xxxxxx' would yield a result | ||
2454 | 892 | string of: | ||
2455 | 893 | |||
2456 | 894 | __pycache__/xxxxxxcpython-32.pyc\0 | ||
2457 | 895 | |||
2458 | 896 | which is 33 characters long (including the nul), thus overflowing | ||
2459 | 897 | the buffer, even though the first test would fail, i.e.: the input | ||
2460 | 898 | string is also 6 characters long, so 32 > 32 is false. | ||
2461 | 899 | |||
2462 | 900 | The reason the first test fails but we still overflow the buffer is | ||
2463 | 901 | that the test above only expects to add one extra character to be | ||
2464 | 902 | added to the extension, and here we're adding three (pyc). We | ||
2465 | 903 | don't add the first dot, so that reclaims one of expected | ||
2466 | 904 | positions, leaving us overflowing by 1 byte (3 extra - 1 reclaimed | ||
2467 | 905 | dot - 1 expected extra == 1 overflowed). | ||
2468 | 906 | |||
2469 | 907 | The best we can do is ensure that we still have enough room in the | ||
2470 | 908 | target buffer before we write the extension. Because it's always | ||
2471 | 909 | only the extension that can cause the overflow, and never the other | ||
2472 | 910 | path bytes we've written, it's sufficient to just do one more test | ||
2473 | 911 | here. Still, the assertion that follows can't hurt. | ||
2474 | 912 | */ | ||
2475 | 913 | #if 0 | ||
2476 | 914 | printf("strlen(buf): %d; buflen: %d\n", (int)strlen(buf), (int)buflen); | ||
2477 | 760 | #endif | 915 | #endif |
2485 | 761 | memcpy(buf, pathname, len); | 916 | if (strlen(buf) + 5 > buflen) |
2486 | 762 | buf[len] = Py_OptimizeFlag ? 'o' : 'c'; | 917 | return NULL; |
2487 | 763 | buf[len+1] = '\0'; | 918 | strcat(buf, debug ? ".pyc" : ".pyo"); |
2488 | 764 | 919 | assert(strlen(buf) < buflen); | |
2489 | 765 | return buf; | 920 | return buf; |
2490 | 766 | } | 921 | } |
2491 | 767 | 922 | ||
2492 | 923 | |||
2493 | 924 | /* Given a pathname to a Python byte compiled file, return the path to the | ||
2494 | 925 | source file, if the path matches the PEP 3147 format. This does not check | ||
2495 | 926 | for any file existence, however, if the pyc file name does not match PEP | ||
2496 | 927 | 3147 style, NULL is returned. buf must be at least as big as pathname; | ||
2497 | 928 | the resulting path will always be shorter. */ | ||
2498 | 929 | |||
2499 | 930 | static char * | ||
2500 | 931 | make_source_pathname(char *pathname, char *buf) | ||
2501 | 932 | { | ||
2502 | 933 | /* __pycache__/foo.<tag>.pyc -> foo.py */ | ||
2503 | 934 | size_t i, j; | ||
2504 | 935 | char *left, *right, *dot0, *dot1, sep; | ||
2505 | 936 | |||
2506 | 937 | /* Look back two slashes from the end. In between these two slashes | ||
2507 | 938 | must be the string __pycache__ or this is not a PEP 3147 style | ||
2508 | 939 | path. It's possible for there to be only one slash. | ||
2509 | 940 | */ | ||
2510 | 941 | if ((right = rightmost_sep(pathname)) == NULL) | ||
2511 | 942 | return NULL; | ||
2512 | 943 | sep = *right; | ||
2513 | 944 | *right = '\0'; | ||
2514 | 945 | left = rightmost_sep(pathname); | ||
2515 | 946 | *right = sep; | ||
2516 | 947 | if (left == NULL) | ||
2517 | 948 | left = pathname; | ||
2518 | 949 | else | ||
2519 | 950 | left++; | ||
2520 | 951 | if (right-left != strlen(CACHEDIR) || | ||
2521 | 952 | strncmp(left, CACHEDIR, right-left) != 0) | ||
2522 | 953 | return NULL; | ||
2523 | 954 | |||
2524 | 955 | /* Now verify that the path component to the right of the last slash | ||
2525 | 956 | has two dots in it. | ||
2526 | 957 | */ | ||
2527 | 958 | if ((dot0 = strchr(right + 1, '.')) == NULL) | ||
2528 | 959 | return NULL; | ||
2529 | 960 | if ((dot1 = strchr(dot0 + 1, '.')) == NULL) | ||
2530 | 961 | return NULL; | ||
2531 | 962 | /* Too many dots? */ | ||
2532 | 963 | if (strchr(dot1 + 1, '.') != NULL) | ||
2533 | 964 | return NULL; | ||
2534 | 965 | |||
2535 | 966 | /* This is a PEP 3147 path. Start by copying everything from the | ||
2536 | 967 | start of pathname up to and including the leftmost slash. Then | ||
2537 | 968 | copy the file's basename, removing the magic tag and adding a .py | ||
2538 | 969 | suffix. | ||
2539 | 970 | */ | ||
2540 | 971 | strncpy(buf, pathname, (i=left-pathname)); | ||
2541 | 972 | strncpy(buf+i, right+1, (j=dot0-right)); | ||
2542 | 973 | strcpy(buf+i+j, "py"); | ||
2543 | 974 | return buf; | ||
2544 | 975 | } | ||
2545 | 768 | 976 | ||
2546 | 769 | /* Given a pathname for a Python source file, its time of last | 977 | /* Given a pathname for a Python source file, its time of last |
2547 | 770 | modification, and a pathname for a compiled file, check whether the | 978 | modification, and a pathname for a compiled file, check whether the |
2548 | @@ -846,7 +1054,8 @@ | |||
2549 | 846 | if (Py_VerboseFlag) | 1054 | if (Py_VerboseFlag) |
2550 | 847 | PySys_WriteStderr("import %s # precompiled from %s\n", | 1055 | PySys_WriteStderr("import %s # precompiled from %s\n", |
2551 | 848 | name, cpathname); | 1056 | name, cpathname); |
2553 | 849 | m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, cpathname); | 1057 | m = PyImport_ExecCodeModuleWithPathnames( |
2554 | 1058 | name, (PyObject *)co, cpathname, cpathname); | ||
2555 | 850 | Py_DECREF(co); | 1059 | Py_DECREF(co); |
2556 | 851 | 1060 | ||
2557 | 852 | return m; | 1061 | return m; |
2558 | @@ -919,12 +1128,41 @@ | |||
2559 | 919 | write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat) | 1128 | write_compiled_module(PyCodeObject *co, char *cpathname, struct stat *srcstat) |
2560 | 920 | { | 1129 | { |
2561 | 921 | FILE *fp; | 1130 | FILE *fp; |
2562 | 1131 | char *dirpath; | ||
2563 | 922 | time_t mtime = srcstat->st_mtime; | 1132 | time_t mtime = srcstat->st_mtime; |
2564 | 923 | #ifdef MS_WINDOWS /* since Windows uses different permissions */ | 1133 | #ifdef MS_WINDOWS /* since Windows uses different permissions */ |
2565 | 924 | mode_t mode = srcstat->st_mode & ~S_IEXEC; | 1134 | mode_t mode = srcstat->st_mode & ~S_IEXEC; |
2566 | 1135 | mode_t dirmode = srcstat->st_mode | S_IEXEC; /* XXX Is this correct | ||
2567 | 1136 | for Windows? | ||
2568 | 1137 | 2010-04-07 BAW */ | ||
2569 | 925 | #else | 1138 | #else |
2570 | 926 | mode_t mode = srcstat->st_mode & ~S_IXUSR & ~S_IXGRP & ~S_IXOTH; | 1139 | mode_t mode = srcstat->st_mode & ~S_IXUSR & ~S_IXGRP & ~S_IXOTH; |
2571 | 1140 | mode_t dirmode = (srcstat->st_mode | | ||
2572 | 1141 | S_IXUSR | S_IXGRP | S_IXOTH | | ||
2573 | 1142 | S_IWUSR | S_IWGRP | S_IWOTH); | ||
2574 | 927 | #endif | 1143 | #endif |
2575 | 1144 | int saved; | ||
2576 | 1145 | |||
2577 | 1146 | /* Ensure that the __pycache__ directory exists. */ | ||
2578 | 1147 | dirpath = rightmost_sep(cpathname); | ||
2579 | 1148 | if (dirpath == NULL) { | ||
2580 | 1149 | if (Py_VerboseFlag) | ||
2581 | 1150 | PySys_WriteStderr( | ||
2582 | 1151 | "# no %s path found %s\n", | ||
2583 | 1152 | CACHEDIR, cpathname); | ||
2584 | 1153 | return; | ||
2585 | 1154 | } | ||
2586 | 1155 | saved = *dirpath; | ||
2587 | 1156 | *dirpath = '\0'; | ||
2588 | 1157 | /* XXX call os.mkdir() or maybe CreateDirectoryA() on Windows? */ | ||
2589 | 1158 | if (mkdir(cpathname, dirmode) < 0 && errno != EEXIST) { | ||
2590 | 1159 | *dirpath = saved; | ||
2591 | 1160 | if (Py_VerboseFlag) | ||
2592 | 1161 | PySys_WriteStderr( | ||
2593 | 1162 | "# cannot create cache dir %s\n", cpathname); | ||
2594 | 1163 | return; | ||
2595 | 1164 | } | ||
2596 | 1165 | *dirpath = saved; | ||
2597 | 928 | 1166 | ||
2598 | 929 | fp = open_exclusive(cpathname, mode); | 1167 | fp = open_exclusive(cpathname, mode); |
2599 | 930 | if (fp == NULL) { | 1168 | if (fp == NULL) { |
2600 | @@ -1032,8 +1270,8 @@ | |||
2601 | 1032 | return NULL; | 1270 | return NULL; |
2602 | 1033 | } | 1271 | } |
2603 | 1034 | #endif | 1272 | #endif |
2606 | 1035 | cpathname = make_compiled_pathname(pathname, buf, | 1273 | cpathname = make_compiled_pathname( |
2607 | 1036 | (size_t)MAXPATHLEN + 1); | 1274 | pathname, buf, (size_t)MAXPATHLEN + 1, !Py_OptimizeFlag); |
2608 | 1037 | if (cpathname != NULL && | 1275 | if (cpathname != NULL && |
2609 | 1038 | (fpc = check_compiled_module(pathname, st.st_mtime, cpathname))) { | 1276 | (fpc = check_compiled_module(pathname, st.st_mtime, cpathname))) { |
2610 | 1039 | co = read_compiled_module(cpathname, fpc); | 1277 | co = read_compiled_module(cpathname, fpc); |
2611 | @@ -1060,7 +1298,8 @@ | |||
2612 | 1060 | write_compiled_module(co, cpathname, &st); | 1298 | write_compiled_module(co, cpathname, &st); |
2613 | 1061 | } | 1299 | } |
2614 | 1062 | } | 1300 | } |
2616 | 1063 | m = PyImport_ExecCodeModuleEx(name, (PyObject *)co, pathname); | 1301 | m = PyImport_ExecCodeModuleWithPathnames( |
2617 | 1302 | name, (PyObject *)co, pathname, cpathname); | ||
2618 | 1064 | Py_DECREF(co); | 1303 | Py_DECREF(co); |
2619 | 1065 | 1304 | ||
2620 | 1066 | return m; | 1305 | return m; |
2621 | @@ -1070,7 +1309,7 @@ | |||
2622 | 1070 | * Returns the path to the py file if available, else the given path | 1309 | * Returns the path to the py file if available, else the given path |
2623 | 1071 | */ | 1310 | */ |
2624 | 1072 | static PyObject * | 1311 | static PyObject * |
2626 | 1073 | get_sourcefile(const char *file) | 1312 | get_sourcefile(char *file) |
2627 | 1074 | { | 1313 | { |
2628 | 1075 | char py[MAXPATHLEN + 1]; | 1314 | char py[MAXPATHLEN + 1]; |
2629 | 1076 | Py_ssize_t len; | 1315 | Py_ssize_t len; |
2630 | @@ -1087,8 +1326,15 @@ | |||
2631 | 1087 | return PyUnicode_DecodeFSDefault(file); | 1326 | return PyUnicode_DecodeFSDefault(file); |
2632 | 1088 | } | 1327 | } |
2633 | 1089 | 1328 | ||
2636 | 1090 | strncpy(py, file, len-1); | 1329 | /* Start by trying to turn PEP 3147 path into source path. If that |
2637 | 1091 | py[len-1] = '\0'; | 1330 | * fails, just chop off the trailing character, i.e. legacy pyc path |
2638 | 1331 | * to py. | ||
2639 | 1332 | */ | ||
2640 | 1333 | if (make_source_pathname(file, py) == NULL) { | ||
2641 | 1334 | strncpy(py, file, len-1); | ||
2642 | 1335 | py[len-1] = '\0'; | ||
2643 | 1336 | } | ||
2644 | 1337 | |||
2645 | 1092 | if (stat(py, &statbuf) == 0 && | 1338 | if (stat(py, &statbuf) == 0 && |
2646 | 1093 | S_ISREG(statbuf.st_mode)) { | 1339 | S_ISREG(statbuf.st_mode)) { |
2647 | 1094 | u = PyUnicode_DecodeFSDefault(py); | 1340 | u = PyUnicode_DecodeFSDefault(py); |
2648 | @@ -2813,16 +3059,28 @@ | |||
2649 | 2813 | */ | 3059 | */ |
2650 | 2814 | 3060 | ||
2651 | 2815 | static PyObject * | 3061 | static PyObject * |
2653 | 2816 | imp_get_magic(PyObject *self, PyObject *noargs) | 3062 | imp_make_magic(long magic) |
2654 | 2817 | { | 3063 | { |
2655 | 2818 | char buf[4]; | 3064 | char buf[4]; |
2656 | 2819 | 3065 | ||
2661 | 2820 | buf[0] = (char) ((pyc_magic >> 0) & 0xff); | 3066 | buf[0] = (char) ((magic >> 0) & 0xff); |
2662 | 2821 | buf[1] = (char) ((pyc_magic >> 8) & 0xff); | 3067 | buf[1] = (char) ((magic >> 8) & 0xff); |
2663 | 2822 | buf[2] = (char) ((pyc_magic >> 16) & 0xff); | 3068 | buf[2] = (char) ((magic >> 16) & 0xff); |
2664 | 2823 | buf[3] = (char) ((pyc_magic >> 24) & 0xff); | 3069 | buf[3] = (char) ((magic >> 24) & 0xff); |
2665 | 2824 | 3070 | ||
2666 | 2825 | return PyBytes_FromStringAndSize(buf, 4); | 3071 | return PyBytes_FromStringAndSize(buf, 4); |
2667 | 3072 | }; | ||
2668 | 3073 | |||
2669 | 3074 | static PyObject * | ||
2670 | 3075 | imp_get_magic(PyObject *self, PyObject *noargs) | ||
2671 | 3076 | { | ||
2672 | 3077 | return imp_make_magic(pyc_magic); | ||
2673 | 3078 | } | ||
2674 | 3079 | |||
2675 | 3080 | static PyObject * | ||
2676 | 3081 | imp_get_tag(PyObject *self, PyObject *noargs) | ||
2677 | 3082 | { | ||
2678 | 3083 | return PyUnicode_FromString(pyc_tag); | ||
2679 | 2826 | } | 3084 | } |
2680 | 2827 | 3085 | ||
2681 | 2828 | static PyObject * | 3086 | static PyObject * |
2682 | @@ -3190,6 +3448,75 @@ | |||
2683 | 3190 | \n\ | 3448 | \n\ |
2684 | 3191 | Reload the module. The module must have been successfully imported before."); | 3449 | Reload the module. The module must have been successfully imported before."); |
2685 | 3192 | 3450 | ||
2686 | 3451 | static PyObject * | ||
2687 | 3452 | imp_cache_from_source(PyObject *self, PyObject *args, PyObject *kws) | ||
2688 | 3453 | { | ||
2689 | 3454 | static char *kwlist[] = {"path", "debug_override", NULL}; | ||
2690 | 3455 | |||
2691 | 3456 | char buf[MAXPATHLEN+1]; | ||
2692 | 3457 | char *pathname, *cpathname; | ||
2693 | 3458 | PyObject *debug_override = Py_None; | ||
2694 | 3459 | int debug = !Py_OptimizeFlag; | ||
2695 | 3460 | |||
2696 | 3461 | if (!PyArg_ParseTupleAndKeywords( | ||
2697 | 3462 | args, kws, "es|O", kwlist, | ||
2698 | 3463 | Py_FileSystemDefaultEncoding, &pathname, &debug_override)) | ||
2699 | 3464 | return NULL; | ||
2700 | 3465 | |||
2701 | 3466 | if (debug_override != Py_None) | ||
2702 | 3467 | if ((debug = PyObject_IsTrue(debug_override)) < 0) | ||
2703 | 3468 | return NULL; | ||
2704 | 3469 | |||
2705 | 3470 | cpathname = make_compiled_pathname(pathname, buf, MAXPATHLEN+1, debug); | ||
2706 | 3471 | PyMem_Free(pathname); | ||
2707 | 3472 | |||
2708 | 3473 | if (cpathname == NULL) { | ||
2709 | 3474 | PyErr_Format(PyExc_SystemError, "path buffer too short"); | ||
2710 | 3475 | return NULL; | ||
2711 | 3476 | } | ||
2712 | 3477 | return PyUnicode_FromString(buf); | ||
2713 | 3478 | } | ||
2714 | 3479 | |||
2715 | 3480 | PyDoc_STRVAR(doc_cache_from_source, | ||
2716 | 3481 | "Given the path to a .py file, return the path to its .pyc/.pyo file.\n\ | ||
2717 | 3482 | \n\ | ||
2718 | 3483 | The .py file does not need to exist; this simply returns the path to the\n\ | ||
2719 | 3484 | .pyc/.pyo file calculated as if the .py file were imported. The extension\n\ | ||
2720 | 3485 | will be .pyc unless __debug__ is not defined, then it will be .pyo.\n\ | ||
2721 | 3486 | \n\ | ||
2722 | 3487 | If debug_override is not None, then it must be a boolean and is taken as\n\ | ||
2723 | 3488 | the value of __debug__ instead."); | ||
2724 | 3489 | |||
2725 | 3490 | static PyObject * | ||
2726 | 3491 | imp_source_from_cache(PyObject *self, PyObject *args, PyObject *kws) | ||
2727 | 3492 | { | ||
2728 | 3493 | static char *kwlist[] = {"path", NULL}; | ||
2729 | 3494 | |||
2730 | 3495 | char *pathname; | ||
2731 | 3496 | char buf[MAXPATHLEN+1]; | ||
2732 | 3497 | |||
2733 | 3498 | if (!PyArg_ParseTupleAndKeywords( | ||
2734 | 3499 | args, kws, "es", kwlist, | ||
2735 | 3500 | Py_FileSystemDefaultEncoding, &pathname)) | ||
2736 | 3501 | return NULL; | ||
2737 | 3502 | |||
2738 | 3503 | if (make_source_pathname(pathname, buf) == NULL) { | ||
2739 | 3504 | PyErr_Format(PyExc_ValueError, "Not a PEP 3147 pyc path: %s", | ||
2740 | 3505 | pathname); | ||
2741 | 3506 | PyMem_Free(pathname); | ||
2742 | 3507 | return NULL; | ||
2743 | 3508 | } | ||
2744 | 3509 | PyMem_Free(pathname); | ||
2745 | 3510 | return PyUnicode_FromString(buf); | ||
2746 | 3511 | } | ||
2747 | 3512 | |||
2748 | 3513 | PyDoc_STRVAR(doc_source_from_cache, | ||
2749 | 3514 | "Given the path to a .pyc./.pyo file, return the path to its .py file.\n\ | ||
2750 | 3515 | \n\ | ||
2751 | 3516 | The .pyc/.pyo file does not need to exist; this simply returns the path to\n\ | ||
2752 | 3517 | the .py file calculated to correspond to the .pyc/.pyo file. If path\n\ | ||
2753 | 3518 | does not conform to PEP 3147 format, ValueError will be raised."); | ||
2754 | 3519 | |||
2755 | 3193 | /* Doc strings */ | 3520 | /* Doc strings */ |
2756 | 3194 | 3521 | ||
2757 | 3195 | PyDoc_STRVAR(doc_imp, | 3522 | PyDoc_STRVAR(doc_imp, |
2758 | @@ -3212,6 +3539,10 @@ | |||
2759 | 3212 | "get_magic() -> string\n\ | 3539 | "get_magic() -> string\n\ |
2760 | 3213 | Return the magic number for .pyc or .pyo files."); | 3540 | Return the magic number for .pyc or .pyo files."); |
2761 | 3214 | 3541 | ||
2762 | 3542 | PyDoc_STRVAR(doc_get_tag, | ||
2763 | 3543 | "get_tag() -> string\n\ | ||
2764 | 3544 | Return the magic tag for .pyc or .pyo files."); | ||
2765 | 3545 | |||
2766 | 3215 | PyDoc_STRVAR(doc_get_suffixes, | 3546 | PyDoc_STRVAR(doc_get_suffixes, |
2767 | 3216 | "get_suffixes() -> [(suffix, mode, type), ...]\n\ | 3547 | "get_suffixes() -> [(suffix, mode, type), ...]\n\ |
2768 | 3217 | Return a list of (suffix, mode, type) tuples describing the files\n\ | 3548 | Return a list of (suffix, mode, type) tuples describing the files\n\ |
2769 | @@ -3242,6 +3573,7 @@ | |||
2770 | 3242 | static PyMethodDef imp_methods[] = { | 3573 | static PyMethodDef imp_methods[] = { |
2771 | 3243 | {"find_module", imp_find_module, METH_VARARGS, doc_find_module}, | 3574 | {"find_module", imp_find_module, METH_VARARGS, doc_find_module}, |
2772 | 3244 | {"get_magic", imp_get_magic, METH_NOARGS, doc_get_magic}, | 3575 | {"get_magic", imp_get_magic, METH_NOARGS, doc_get_magic}, |
2773 | 3576 | {"get_tag", imp_get_tag, METH_NOARGS, doc_get_tag}, | ||
2774 | 3245 | {"get_suffixes", imp_get_suffixes, METH_NOARGS, doc_get_suffixes}, | 3577 | {"get_suffixes", imp_get_suffixes, METH_NOARGS, doc_get_suffixes}, |
2775 | 3246 | {"load_module", imp_load_module, METH_VARARGS, doc_load_module}, | 3578 | {"load_module", imp_load_module, METH_VARARGS, doc_load_module}, |
2776 | 3247 | {"new_module", imp_new_module, METH_VARARGS, doc_new_module}, | 3579 | {"new_module", imp_new_module, METH_VARARGS, doc_new_module}, |
2777 | @@ -3249,6 +3581,10 @@ | |||
2778 | 3249 | {"acquire_lock", imp_acquire_lock, METH_NOARGS, doc_acquire_lock}, | 3581 | {"acquire_lock", imp_acquire_lock, METH_NOARGS, doc_acquire_lock}, |
2779 | 3250 | {"release_lock", imp_release_lock, METH_NOARGS, doc_release_lock}, | 3582 | {"release_lock", imp_release_lock, METH_NOARGS, doc_release_lock}, |
2780 | 3251 | {"reload", imp_reload, METH_O, doc_reload}, | 3583 | {"reload", imp_reload, METH_O, doc_reload}, |
2781 | 3584 | {"cache_from_source", (PyCFunction)imp_cache_from_source, | ||
2782 | 3585 | METH_VARARGS | METH_KEYWORDS, doc_cache_from_source}, | ||
2783 | 3586 | {"source_from_cache", (PyCFunction)imp_source_from_cache, | ||
2784 | 3587 | METH_VARARGS | METH_KEYWORDS, doc_source_from_cache}, | ||
2785 | 3252 | /* The rest are obsolete */ | 3588 | /* The rest are obsolete */ |
2786 | 3253 | {"get_frozen_object", imp_get_frozen_object, METH_VARARGS}, | 3589 | {"get_frozen_object", imp_get_frozen_object, METH_VARARGS}, |
2787 | 3254 | {"is_frozen_package", imp_is_frozen_package, METH_VARARGS}, | 3590 | {"is_frozen_package", imp_is_frozen_package, METH_VARARGS}, |
2788 | @@ -3436,7 +3772,6 @@ | |||
2789 | 3436 | failure: | 3772 | failure: |
2790 | 3437 | Py_XDECREF(m); | 3773 | Py_XDECREF(m); |
2791 | 3438 | return NULL; | 3774 | return NULL; |
2792 | 3439 | |||
2793 | 3440 | } | 3775 | } |
2794 | 3441 | 3776 | ||
2795 | 3442 | 3777 | ||
2796 | 3443 | 3778 | ||
2797 | === modified file 'Python/pythonrun.c' | |||
2798 | --- Python/pythonrun.c 2010-03-14 06:49:55 +0000 | |||
2799 | +++ Python/pythonrun.c 2010-04-16 18:55:41 +0000 | |||
2800 | @@ -1155,6 +1155,8 @@ | |||
2801 | 1155 | Py_DECREF(f); | 1155 | Py_DECREF(f); |
2802 | 1156 | return -1; | 1156 | return -1; |
2803 | 1157 | } | 1157 | } |
2804 | 1158 | if (PyDict_SetItemString(d, "__cached__", Py_None) < 0) | ||
2805 | 1159 | return -1; | ||
2806 | 1158 | set_file_name = 1; | 1160 | set_file_name = 1; |
2807 | 1159 | Py_DECREF(f); | 1161 | Py_DECREF(f); |
2808 | 1160 | } | 1162 | } |