[pypy-svn] pypy improve-unwrap_spec: update zipimport to the new unwrap_spec
amauryfa
commits-noreply at bitbucket.org
Wed Feb 16 19:20:25 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: improve-unwrap_spec
Changeset: r42087:318d10258aa1
Date: 2011-02-16 18:50 +0100
http://bitbucket.org/pypy/pypy/changeset/318d10258aa1/
Log: update zipimport to the new unwrap_spec
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
@@ -1,8 +1,7 @@
-from pypy.interpreter.baseobjspace import W_Root, ObjSpace, Wrappable, \
- Arguments
+from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.interpreter.module import Module
from pypy.module.imp import importing
@@ -36,7 +35,8 @@
# -------------- dict-like interface -----------------
# I don't care about speed of those, they're obscure anyway
# THIS IS A TERRIBLE HACK TO BE CPYTHON COMPATIBLE
-
+
+ @unwrap_spec(name=str)
def getitem(self, space, name):
try:
w_zipimporter = self.cache[name]
@@ -53,49 +53,41 @@
w(info.file_size), w(info.file_offset), w(info.dostime),
w(info.dosdate), w(info.CRC)]))
return w_d
- getitem.unwrap_spec = ['self', ObjSpace, str]
def keys(self, space):
return space.newlist([space.wrap(s)
for s in self.cache.keys()])
- keys.unwrap_spec = ['self', ObjSpace]
def values(self, space):
keys = self.cache.keys()
values_w = [self.getitem(space, key) for key in keys]
return space.newlist(values_w)
- values.unwrap_spec = ['self', ObjSpace]
def items(self, space):
w = space.wrap
items_w = [space.newtuple([w(key), self.getitem(space, key)])
for key in self.cache.keys()]
return space.newlist(items_w)
- items.unwrap_spec = ['self', ObjSpace]
def iterkeys(self, space):
return space.iter(self.keys(space))
- iterkeys.unwrap_spec = ['self', ObjSpace]
def itervalues(self, space):
return space.iter(self.values(space))
- itervalues.unwrap_spec = ['self', ObjSpace]
def iteritems(self, space):
return space.iter(self.items(space))
- iteritems.unwrap_spec = ['self', ObjSpace]
+ @unwrap_spec(name=str)
def contains(self, space, name):
return space.newbool(name in self.cache)
- contains.unwrap_spec = ['self', ObjSpace, str]
def clear(self, space):
self.cache = {}
- clear.unwrap_spec = ['self', ObjSpace]
+ @unwrap_spec(name=str)
def delitem(self, space, name):
del self.cache[name]
- delitem.unwrap_spec = ['self', ObjSpace, str]
W_ZipCache.typedef = TypeDef(
'zip_dict',
@@ -218,12 +210,12 @@
except KeyError:
return False
+ @unwrap_spec(fullname=str)
def find_module(self, space, fullname, w_path=None):
filename = self.make_filename(fullname)
for _, _, ext in ENUMERATE_EXTS:
if self.have_modulefile(space, filename + ext):
return space.wrap(self)
- find_module.unwrap_spec = ['self', ObjSpace, str, W_Root]
def make_filename(self, fullname):
startpos = fullname.rfind('.') + 1 # 0 when not found
@@ -231,6 +223,7 @@
subname = fullname[startpos:]
return self.prefix + subname.replace('.', '/')
+ @unwrap_spec(fullname=str)
def load_module(self, space, fullname):
w = space.wrap
filename = self.make_filename(fullname)
@@ -266,8 +259,8 @@
raise OperationError(self.w_ZipImportError, last_exc.get_w_value(space))
# should never happen I think
return space.w_None
- load_module.unwrap_spec = ['self', ObjSpace, str]
+ @unwrap_spec(filename=str)
def get_data(self, space, filename):
filename = self._find_relative_path(filename)
w = space.wrap
@@ -280,8 +273,8 @@
return w(data)
except (KeyError, OSError):
raise OperationError(space.w_IOError, space.wrap("Error reading file"))
- get_data.unwrap_spec = ['self', ObjSpace, str]
+ @unwrap_spec(fullname=str)
def get_code(self, space, fullname):
filename = self.make_filename(fullname)
for compiled, _, ext in ENUMERATE_EXTS:
@@ -302,8 +295,8 @@
return space.wrap(code_w)
raise operationerrfmt(self.w_ZipImportError,
"Cannot find source or code for %s in %s", filename, self.name)
- get_code.unwrap_spec = ['self', ObjSpace, str]
+ @unwrap_spec(fullname=str)
def get_source(self, space, fullname):
filename = self.make_filename(fullname)
found = False
@@ -318,8 +311,8 @@
return space.w_None
raise operationerrfmt(self.w_ZipImportError,
"Cannot find source for %s in %s", filename, self.name)
- get_source.unwrap_spec = ['self', ObjSpace, str]
+ @unwrap_spec(fullname=str)
def get_filename(self, space, fullname):
filename = self.make_filename(fullname)
for _, is_package, ext in ENUMERATE_EXTS:
@@ -328,8 +321,8 @@
self.corr_zname(filename + ext))
raise operationerrfmt(self.w_ZipImportError,
"Cannot find module %s in %s", filename, self.name)
- get_filename.unwrap_spec = ['self', ObjSpace, str]
+ @unwrap_spec(fullname=str)
def is_package(self, space, fullname):
filename = self.make_filename(fullname)
for _, is_package, ext in ENUMERATE_EXTS:
@@ -337,12 +330,12 @@
return space.wrap(is_package)
raise operationerrfmt(self.w_ZipImportError,
"Cannot find module %s in %s", filename, self.name)
- is_package.unwrap_spec = ['self', ObjSpace, str]
def getarchive(space, self):
space = self.space
return space.wrap(self.filename)
+ at unwrap_spec(name=str)
def descr_new_zipimporter(space, w_type, name):
w = space.wrap
w_ZipImportError = space.getattr(space.getbuiltinmodule('zipimport'),
@@ -391,8 +384,6 @@
zip_cache.set(filename, w_result)
return w_result
-descr_new_zipimporter.unwrap_spec = [ObjSpace, W_Root, str]
-
W_ZipImporter.typedef = TypeDef(
'zipimporter',
__new__ = interp2app(descr_new_zipimporter),
More information about the Pypy-commit
mailing list