Author: Amaury Forgeot d'Arc <[email protected]>
Branch: py3k
Changeset: r53509:0be9d04c92e6
Date: 2012-03-13 23:44 +0100
http://bitbucket.org/pypy/pypy/changeset/0be9d04c92e6/
Log: Fix most failures in zipimport module
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
@@ -275,10 +275,9 @@
@unwrap_spec(filename=str)
def get_data(self, space, filename):
filename = self._find_relative_path(filename)
- w = space.wrap
try:
data = self.zip_file.read(filename)
- return w(data)
+ return space.wrapbytes(data)
except (KeyError, OSError, BadZipfile):
raise OperationError(space.w_IOError, space.wrap("Error reading
file"))
@@ -346,7 +345,6 @@
@unwrap_spec(name='str0')
def descr_new_zipimporter(space, w_type, name):
- w = space.wrap
ok = False
parts_ends = [i for i in range(0, len(name))
if name[i] == os.path.sep or name[i] == ZIPSEP]
diff --git a/pypy/module/zipimport/test/test_undocumented.py
b/pypy/module/zipimport/test/test_undocumented.py
--- a/pypy/module/zipimport/test/test_undocumented.py
+++ b/pypy/module/zipimport/test/test_undocumented.py
@@ -19,7 +19,7 @@
class AppTestZipImport:
def setup_class(cls):
- space = gettestobjspace(usemodules=['zipimport', 'rctime'])
+ space = gettestobjspace(usemodules=['zipimport', 'rctime', 'struct'])
cls.space = space
cls.w_created_paths = space.wrap(created_paths)
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
@@ -39,6 +39,7 @@
# using the host python compiler, but then in the tests we load it
# with py.py. It works (mostly by chance) because the two functions
# are very simple and the bytecodes are compatible enough.
+ # XXX with py3k this does not work anymore.
co = py.code.Source("""
def get_name():
return __name__
@@ -46,17 +47,17 @@
return __file__
""").compile()
+ usemodules = ['zipimport', 'rctime', 'struct']
if cls.compression == ZIP_DEFLATED:
- space = gettestobjspace(usemodules=['zipimport', 'zlib', 'rctime'])
- else:
- space = gettestobjspace(usemodules=['zipimport', 'rctime'])
+ usemodules.append('zlib')
+ space = gettestobjspace(usemodules=usemodules)
cls.space = space
tmpdir = udir.ensure('zipimport_%s' % cls.__name__, dir=1)
now = time.time()
cls.w_now = space.wrap(now)
test_pyc = cls.make_pyc(space, co, now)
- cls.w_test_pyc = space.wrap(test_pyc)
+ cls.w_test_pyc = space.wrapbytes(test_pyc)
cls.w_compression = space.wrap(cls.compression)
cls.w_pathsep = space.wrap(cls.pathsep)
#ziptestmodule = tmpdir.ensure('ziptestmodule.zip').write(
@@ -155,7 +156,7 @@
import sys, os
self.writefile("uuu.py", "def f(x): return x")
mod = __import__('uuu', globals(), locals(), [])
- print mod
+ print(mod)
assert mod.f(3) == 3
expected = {
'__doc__' : None,
@@ -185,32 +186,32 @@
import zipimport
z = zipimport.zipimporter(self.zipfile)
code = z.get_code('uuu')
- assert isinstance(code, type((lambda:0).func_code))
+ assert isinstance(code, type((lambda:0).__code__))
def test_bad_pyc(self):
import zipimport
import sys
- m0 = ord(self.test_pyc[0])
+ m0 = self.test_pyc[0]
m0 ^= 0x04
- test_pyc = chr(m0) + self.test_pyc[1:]
+ test_pyc = bytes([m0]) + self.test_pyc[1:]
self.writefile("uu.pyc", test_pyc)
raises(ImportError, "__import__('uu', globals(), locals(), [])")
assert 'uu' not in sys.modules
def test_force_py(self):
import sys
- m0 = ord(self.test_pyc[0])
+ m0 = self.test_pyc[0]
m0 ^= 0x04
- test_pyc = chr(m0) + self.test_pyc[1:]
+ test_pyc = bytes([m0]) + self.test_pyc[1:]
self.writefile("uu.pyc", test_pyc)
self.writefile("uu.py", "def f(x): return x")
mod = __import__("uu", globals(), locals(), [])
assert mod.f(3) == 3
def test_sys_modules(self):
- m0 = ord(self.test_pyc[0])
+ m0 = self.test_pyc[0]
m0 ^= 0x04
- test_pyc = chr(m0) + self.test_pyc[1:]
+ test_pyc = bytes([m0]) + self.test_pyc[1:]
self.writefile("uuu.pyc", test_pyc)
import sys
import zipimport
@@ -232,8 +233,8 @@
def test_package_bug(self):
import os, sys
- import new
- mod = new.module('xxuuv')
+ import types
+ mod = types.ModuleType('xxuuv')
mod.__path__ = [self.zipfile + '/xxuuv']
sys.modules['xxuuv'] = mod
#
@@ -247,8 +248,8 @@
def test_pyc_in_package(self):
import os, sys
- import new
- mod = new.module('xxuuw')
+ import types
+ mod = types.ModuleType('xxuuw')
mod.__path__ = [self.zipfile + '/xxuuw']
sys.modules['xxuuw'] = mod
#
@@ -264,7 +265,7 @@
def test_functions(self):
import os
import zipimport
- data = "saddsadsa"
+ data = b"saddsadsa"
self.writefile("xxx", data)
self.writefile("xx/__init__.py", "5")
self.writefile("yy.py", "3")
@@ -273,13 +274,13 @@
assert z.get_data(self.zipfile + os.sep + "xxx") == data
assert z.is_package("xx")
assert not z.is_package("yy")
- assert z.get_source("yy") == '3'
+ assert z.get_source("yy") == b'3'
assert z.get_source('uu') is None
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('xx')
- assert z.get_source('xx') == "5"
+ assert z.get_source('xx') == b"5"
assert z.archive == self.zipfile
mod = z.load_module('xx')
assert z.get_filename('xx') == mod.__file__
@@ -319,7 +320,7 @@
self.writefile("package/subpackage/__init__.py", "")
self.writefile("package/subpackage/foo.py", "")
import sys
- print sys.path
+ print(sys.path)
mod = __import__('package.subpackage.foo', None, None, [])
assert mod
@@ -341,7 +342,7 @@
def test_co_filename(self):
self.writefile('mymodule.py', """
def get_co_filename():
- return get_co_filename.func_code.co_filename
+ return get_co_filename.__code__.co_filename
""")
import os
expected = self.zipfile + os.sep + 'mymodule.py'
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit