Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r60955:81cb7e69c819 Date: 2013-02-08 09:05 +0100 http://bitbucket.org/pypy/pypy/changeset/81cb7e69c819/
Log: merge heads diff --git a/pypy/module/zipimport/interp_zipimport.py b/pypy/module/zipimport/interp_zipimport.py --- a/pypy/module/zipimport/interp_zipimport.py +++ b/pypy/module/zipimport/interp_zipimport.py @@ -172,24 +172,24 @@ return mtime def check_newer_pyfile(self, space, filename, timestamp): + # check if the timestamp stored in the .pyc is matching + # the actual timestamp of the .py file, if any mtime = self._parse_mtime(space, filename) if mtime == 0: return False - return mtime > timestamp - - def check_compatible_mtime(self, space, filename, timestamp): - mtime = self._parse_mtime(space, filename) - if mtime == 0 or mtime != (timestamp & (~1)): - return False - return True + # Lenient date/time comparison function. The precision of the mtime + # in the archive is lower than the mtime stored in a .pyc: we + # must allow a difference of at most one second. + d = mtime - timestamp + if d < 0: + d = -d + return d > 1 # more than one second => different def can_use_pyc(self, space, filename, magic, timestamp): if magic != importing.get_pyc_magic(space): return False if self.check_newer_pyfile(space, filename[:-1], timestamp): return False - if not self.check_compatible_mtime(space, filename, timestamp): - return False return True def import_pyc_file(self, space, modname, filename, buf, pkgpath): diff --git a/pypy/module/zipimport/test/test_zipimport.py b/pypy/module/zipimport/test/test_zipimport.py --- a/pypy/module/zipimport/test/test_zipimport.py +++ b/pypy/module/zipimport/test/test_zipimport.py @@ -95,6 +95,9 @@ """) self.w_modules = [] + def w_now_in_the_future(self, delta): + self.now += delta + def w_writefile(self, filename, data): import sys import time @@ -264,10 +267,12 @@ import os import zipimport data = "saddsadsa" + pyc_data = self.test_pyc + self.now_in_the_future(+5) # write the zipfile 5 secs after the .pyc self.writefile("xxx", data) self.writefile("xx/__init__.py", "5") self.writefile("yy.py", "3") - self.writefile('uu.pyc', self.test_pyc) + self.writefile('uu.pyc', pyc_data) z = zipimport.zipimporter(self.zipfile) assert z.get_data(self.zipfile + os.sep + "xxx") == data assert z.is_package("xx") @@ -277,6 +282,7 @@ raises(ImportError, "z.get_source('zz')") #assert z.get_code('yy') == py.code.Source('3').compile() #assert z.get_code('uu') == self.co + assert z.get_code('uu') assert z.get_code('xx') assert z.get_source('xx') == "5" assert z.archive == self.zipfile _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit