[pypy-svn] pypy improve-unwrap_spec: Update unwrap_spec in zlib and bz2 modules

amauryfa commits-noreply at bitbucket.org
Wed Feb 16 19:19:24 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: improve-unwrap_spec
Changeset: r42058:4e1db4dc3384
Date: 2011-02-16 11:59 +0100
http://bitbucket.org/pypy/pypy/changeset/4e1db4dc3384/

Log:	Update unwrap_spec in zlib and bz2 modules

diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py
--- a/pypy/module/bz2/interp_bz2.py
+++ b/pypy/module/bz2/interp_bz2.py
@@ -6,7 +6,7 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.interpreter.typedef import interp_attrproperty
-from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped, interp2app, Arguments
+from pypy.interpreter.gateway import NoneNotWrapped, interp2app, unwrap_spec
 from pypy.rlib.streamio import Stream
 from pypy.translator.tool.cbuild import ExternalCompilationInfo
 from pypy.translator.platform import platform as compiler
@@ -246,6 +246,7 @@
             raise operationerrfmt(space.w_ValueError,
                                   "invalid mode: '%s'", mode)
 
+    @unwrap_spec(mode=str, buffering=int, compresslevel=int)
     def direct_bz2__init__(self, w_name, mode='r', buffering=-1,
                            compresslevel=9):
         self.direct_close()
@@ -259,8 +260,8 @@
         self.fdopenstream(stream, fd, mode, w_name)
 
     _exposed_method_names = []
-    W_File._decl.im_func(locals(), "bz2__init__", ['self', W_Root, str, int, int],
-          """Opens a BZ2-compressed file.""")
+    W_File._decl.im_func(locals(), "bz2__init__",
+                         """Opens a BZ2-compressed file.""")
     # XXX ^^^ hacking hacking... can't just use the name "__init__" again
     # because the RTyper is confused about the two direct__init__() with
     # a different signature, confusion caused by the fact that
@@ -278,13 +279,11 @@
         info = "%s bz2.BZ2File %s, mode '%s'" % (head, self.getdisplayname(),
                                                  self.mode)
         return self.getrepr(self.space, info)
-    file_bz2__repr__.unwrap_spec = ['self']
 
-def descr_bz2file__new__(space, w_subtype, args):
+def descr_bz2file__new__(space, w_subtype, __args__):
     bz2file = space.allocate_instance(W_BZ2File, w_subtype)
     W_BZ2File.__init__(bz2file, space)
     return space.wrap(bz2file)
-descr_bz2file__new__.unwrap_spec = [ObjSpace, W_Root, Arguments]
 
 same_attributes_as_in_file = list(W_File._exposed_method_names)
 same_attributes_as_in_file.remove('__init__')
@@ -485,12 +484,12 @@
     def try_to_find_file_descriptor(self):
         return self.stream.try_to_find_file_descriptor()
 
+ at unwrap_spec(compresslevel=int)
 def descr_compressor__new__(space, w_subtype, compresslevel=9):
     x = space.allocate_instance(W_BZ2Compressor, w_subtype)
     x = space.interp_w(W_BZ2Compressor, x)
     W_BZ2Compressor.__init__(x, space, compresslevel)
     return space.wrap(x)
-descr_compressor__new__.unwrap_spec = [ObjSpace, W_Root, int]
 
 class W_BZ2Compressor(Wrappable):
     """BZ2Compressor([compresslevel=9]) -> compressor object
@@ -504,7 +503,6 @@
         self.bzs = lltype.malloc(bz_stream.TO, flavor='raw', zero=True)
         self.running = False
         self._init_bz2comp(compresslevel)
-    __init__.unwrap_spec = ['self', ObjSpace, int]
         
     def _init_bz2comp(self, compresslevel):
         if compresslevel < 1 or compresslevel > 9:
@@ -521,6 +519,7 @@
         BZ2_bzCompressEnd(self.bzs)
         lltype.free(self.bzs, flavor='raw')
     
+    @unwrap_spec(data='bufferstr')
     def compress(self, data):
         """compress(data) -> string
 
@@ -561,8 +560,6 @@
 
                 res = out.make_result_string()
                 return self.space.wrap(res)
-
-    compress.unwrap_spec = ['self', 'bufferstr']
     
     def flush(self):
         if not self.running:
@@ -583,7 +580,6 @@
 
             res = out.make_result_string()
             return self.space.wrap(res)
-    flush.unwrap_spec = ['self']
 
 W_BZ2Compressor.typedef = TypeDef("BZ2Compressor",
     __doc__ = W_BZ2Compressor.__doc__,
@@ -598,7 +594,6 @@
     x = space.interp_w(W_BZ2Decompressor, x)
     W_BZ2Decompressor.__init__(x, space)
     return space.wrap(x)
-descr_decompressor__new__.unwrap_spec = [ObjSpace, W_Root]
 
 class W_BZ2Decompressor(Wrappable):
     """BZ2Decompressor() -> decompressor object
@@ -626,7 +621,8 @@
     def __del__(self):
         BZ2_bzDecompressEnd(self.bzs)
         lltype.free(self.bzs, flavor='raw')
-    
+
+    @unwrap_spec(data='bufferstr')
     def decompress(self, data):
         """decompress(data) -> string
 
@@ -673,8 +669,6 @@
                 res = out.make_result_string()
                 return self.space.wrap(res)
 
-    decompress.unwrap_spec = ['self', 'bufferstr']
-
 
 W_BZ2Decompressor.typedef = TypeDef("BZ2Decompressor",
     __doc__ = W_BZ2Decompressor.__doc__,
@@ -684,6 +678,7 @@
 )
 
 
+ at unwrap_spec(data='bufferstr', compresslevel=int)
 def compress(space, data, compresslevel=9):
     """compress(data [, compresslevel=9]) -> string
 
@@ -727,8 +722,8 @@
                 res = out.make_result_string()
                 BZ2_bzCompressEnd(bzs)
                 return space.wrap(res)
-compress.unwrap_spec = [ObjSpace, 'bufferstr', int]
 
+ at unwrap_spec(data='bufferstr')
 def decompress(space, data):
     """decompress(data) -> decompressed data
 
@@ -769,4 +764,3 @@
                 res = out.make_result_string()
                 BZ2_bzDecompressEnd(bzs)
                 return space.wrap(res)
-decompress.unwrap_spec = [ObjSpace, 'bufferstr']

diff --git a/pypy/module/zlib/interp_zlib.py b/pypy/module/zlib/interp_zlib.py
--- a/pypy/module/zlib/interp_zlib.py
+++ b/pypy/module/zlib/interp_zlib.py
@@ -1,5 +1,5 @@
 import sys
-from pypy.interpreter.gateway import ObjSpace, W_Root, interp2app
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.typedef import TypeDef, interp_attrproperty
 from pypy.interpreter.error import OperationError
@@ -20,6 +20,7 @@
         return intmask((x ^ SIGN_EXTEND2) - SIGN_EXTEND2)
 
 
+ at unwrap_spec(string='bufferstr')
 def crc32(space, string, w_start = rzlib.CRC32_DEFAULT_START):
     """
     crc32(string[, start]) -- Compute a CRC-32 checksum of string.
@@ -48,10 +49,10 @@
     checksum = unsigned_to_signed_32bit(checksum)
 
     return space.wrap(checksum)
-crc32.unwrap_spec = [ObjSpace, 'bufferstr', W_Root]
 
 
-def adler32(space, string, start = rzlib.ADLER32_DEFAULT_START):
+ at unwrap_spec(string='bufferstr', start=r_uint)
+def adler32(space, string, start=rzlib.ADLER32_DEFAULT_START):
     """
     adler32(string[, start]) -- Compute an Adler-32 checksum of string.
 
@@ -63,7 +64,6 @@
     checksum = unsigned_to_signed_32bit(checksum)
 
     return space.wrap(checksum)
-adler32.unwrap_spec = [ObjSpace, 'bufferstr', r_uint]
 
 
 def zlib_error(space, msg):
@@ -72,6 +72,7 @@
     return OperationError(w_error, space.wrap(msg))
 
 
+ at unwrap_spec(string='bufferstr', level=int)
 def compress(space, string, level=rzlib.Z_DEFAULT_COMPRESSION):
     """
     compress(string[, level]) -- Returned compressed string.
@@ -90,9 +91,9 @@
     except rzlib.RZlibError, e:
         raise zlib_error(space, e.msg)
     return space.wrap(result)
-compress.unwrap_spec = [ObjSpace, 'bufferstr', int]
 
 
+ at unwrap_spec(string='bufferstr', wbits=int, bufsize=int)
 def decompress(space, string, wbits=rzlib.MAX_WBITS, bufsize=0):
     """
     decompress(string[, wbits[, bufsize]]) -- Return decompressed string.
@@ -112,7 +113,6 @@
     except rzlib.RZlibError, e:
         raise zlib_error(space, e.msg)
     return space.wrap(result)
-decompress.unwrap_spec = [ObjSpace, 'bufferstr', int, int]
 
 
 class ZLibObject(Wrappable):
@@ -164,6 +164,7 @@
             self.stream = rzlib.null_stream
 
 
+    @unwrap_spec(data='bufferstr')
     def compress(self, data):
         """
         compress(data) -- Return a string containing data compressed.
@@ -185,9 +186,9 @@
         except rzlib.RZlibError, e:
             raise zlib_error(self.space, e.msg)
         return self.space.wrap(result)
-    compress.unwrap_spec = ['self', 'bufferstr']
 
 
+    @unwrap_spec(mode=int)
     def flush(self, mode=rzlib.Z_FINISH):
         """
         flush( [mode] ) -- Return a string containing any remaining compressed
@@ -215,9 +216,9 @@
         except rzlib.RZlibError, e:
             raise zlib_error(self.space, e.msg)
         return self.space.wrap(result)
-    flush.unwrap_spec = ['self', int]
 
 
+ at unwrap_spec(level=int, method=int, wbits=int, memLevel=int, strategy=int)
 def Compress___new__(space, w_subtype, level=rzlib.Z_DEFAULT_COMPRESSION,
                      method=rzlib.Z_DEFLATED,             # \
                      wbits=rzlib.MAX_WBITS,               #  \   undocumented
@@ -231,7 +232,6 @@
     Compress.__init__(stream, space, level,
                       method, wbits, memLevel, strategy)
     return space.wrap(stream)
-Compress___new__.unwrap_spec = [ObjSpace, W_Root, int, int, int, int, int]
 
 
 Compress.typedef = TypeDef(
@@ -277,6 +277,7 @@
             self.stream = rzlib.null_stream
 
 
+    @unwrap_spec(data='bufferstr', max_length=int)
     def decompress(self, data, max_length=0):
         """
         decompress(data[, max_length]) -- Return a string containing the
@@ -312,9 +313,9 @@
         else:
             self.unconsumed_tail = tail
         return self.space.wrap(string)
-    decompress.unwrap_spec = ['self', 'bufferstr', int]
 
 
+    @unwrap_spec(length=int)
     def flush(self, length=sys.maxint):
         """
         flush( [length] ) -- This is kept for backward compatibility,
@@ -330,9 +331,9 @@
         # I could not figure out a case in which flush() in CPython
         # doesn't simply return an empty string without complaining.
         return self.space.wrap("")
-    flush.unwrap_spec = ['self', int]
 
 
+ at unwrap_spec(wbits=int)
 def Decompress___new__(space, w_subtype, wbits=rzlib.MAX_WBITS):
     """
     Create a new Decompress and call its initializer.
@@ -341,7 +342,6 @@
     stream = space.interp_w(Decompress, stream)
     Decompress.__init__(stream, space, wbits)
     return space.wrap(stream)
-Decompress___new__.unwrap_spec = [ObjSpace, W_Root, int]
 
 
 Decompress.typedef = TypeDef(


More information about the Pypy-commit mailing list