[pypy-svn] pypy improve-unwrap_spec: Modern unwrap_spec in binascii

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


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: improve-unwrap_spec
Changeset: r42072:85b507b48d1a
Date: 2011-02-16 16:42 +0100
http://bitbucket.org/pypy/pypy/changeset/85b507b48d1a/

Log:	Modern unwrap_spec in binascii

diff --git a/pypy/module/binascii/interp_qp.py b/pypy/module/binascii/interp_qp.py
--- a/pypy/module/binascii/interp_qp.py
+++ b/pypy/module/binascii/interp_qp.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.rstring import StringBuilder
 
 MAXLINESIZE = 76
@@ -14,6 +14,7 @@
         return ord(c) - (ord('a') - 10)
 hexval._always_inline_ = True
 
+ at unwrap_spec(data='bufferstr', header=int)
 def a2b_qp(space, data, header=0):
     "Decode a string of qp-encoded data."
 
@@ -56,7 +57,6 @@
                 c = ' '
             odata.append(c)
     return space.wrap(odata.build())
-a2b_qp.unwrap_spec = [ObjSpace, 'bufferstr', int]
 
 # ____________________________________________________________
 
@@ -92,6 +92,7 @@
         self._flush()
         return self.builder.build()
 
+ at unwrap_spec(data='bufferstr', quotetabs=int, istext=int, header=int)
 def b2a_qp(space, data, quotetabs=0, istext=1, header=0):
     """Encode a string using quoted-printable encoding.
 
@@ -159,4 +160,3 @@
                 inp += 1
 
     return space.wrap(odata.build())
-b2a_qp.unwrap_spec = [ObjSpace, 'bufferstr', int, int, int]

diff --git a/pypy/module/binascii/interp_uu.py b/pypy/module/binascii/interp_uu.py
--- a/pypy/module/binascii/interp_uu.py
+++ b/pypy/module/binascii/interp_uu.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.rstring import StringBuilder
 from pypy.module.binascii.interp_binascii import raise_Error
 
@@ -29,6 +29,7 @@
 _a2b_write._always_inline_ = True
 
 
+ at unwrap_spec(ascii='bufferstr')
 def a2b_uu(space, ascii):
     "Decode a line of uuencoded data."
 
@@ -52,7 +53,6 @@
     if remaining > 0:
         res.append_multiple_char('\x00', remaining)
     return space.wrap(res.build())
-a2b_uu.unwrap_spec = [ObjSpace, 'bufferstr']
 
 # ____________________________________________________________
 
@@ -63,6 +63,7 @@
         return 0
 _a2b_read._always_inline_ = True
 
+ at unwrap_spec(bin='bufferstr')
 def b2a_uu(space, bin):
     "Uuencode a line of data."
 
@@ -84,4 +85,3 @@
 
     res.append('\n')
     return space.wrap(res.build())
-b2a_uu.unwrap_spec = [ObjSpace, 'bufferstr']

diff --git a/pypy/module/binascii/interp_base64.py b/pypy/module/binascii/interp_base64.py
--- a/pypy/module/binascii/interp_base64.py
+++ b/pypy/module/binascii/interp_base64.py
@@ -1,5 +1,5 @@
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.rstring import StringBuilder
 from pypy.module.binascii.interp_binascii import raise_Error
 from pypy.rlib.rarithmetic import ovfcheck
@@ -35,6 +35,7 @@
 assert len(table_a2b_base64) == 256
 
 
+ at unwrap_spec(ascii='bufferstr')
 def a2b_base64(space, ascii):
     "Decode a line of base64 data."
 
@@ -71,13 +72,13 @@
             raise_Error(space, "Incorrect padding")
 
     return space.wrap(res.build())
-a2b_base64.unwrap_spec = [ObjSpace, 'bufferstr']
 
 # ____________________________________________________________
 
 table_b2a_base64 = (
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")
 
+ at unwrap_spec(bin='bufferstr')
 def b2a_base64(space, bin):
     "Base64-code line of data."
 
@@ -110,4 +111,3 @@
         res.append(PAD)
     res.append('\n')
     return space.wrap(res.build())
-b2a_base64.unwrap_spec = [ObjSpace, 'bufferstr']

diff --git a/pypy/module/binascii/interp_crc32.py b/pypy/module/binascii/interp_crc32.py
--- a/pypy/module/binascii/interp_crc32.py
+++ b/pypy/module/binascii/interp_crc32.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.rarithmetic import r_uint, intmask
 from pypy.rpython.lltypesystem import rffi
 
@@ -61,6 +61,7 @@
 crc_32_tab = map(r_uint, crc_32_tab)
 
 
+ at unwrap_spec(data='bufferstr', oldcrc='c_int')
 def crc32(space, data, oldcrc=0):
     "Compute the CRC-32 incrementally."
 
@@ -72,4 +73,3 @@
 
     crc = ~intmask(rffi.cast(rffi.INT, crc))   # unsigned => 32-bit signed
     return space.wrap(crc)
-crc32.unwrap_spec = [ObjSpace, 'bufferstr', 'c_int']

diff --git a/pypy/module/binascii/interp_hexlify.py b/pypy/module/binascii/interp_hexlify.py
--- a/pypy/module/binascii/interp_hexlify.py
+++ b/pypy/module/binascii/interp_hexlify.py
@@ -1,5 +1,5 @@
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.rstring import StringBuilder
 from pypy.rlib.rarithmetic import ovfcheck
 
@@ -12,6 +12,7 @@
         return chr((ord('a')-10) + value)
 _value2char._always_inline_ = True
 
+ at unwrap_spec(data='bufferstr')
 def hexlify(space, data):
     '''Hexadecimal representation of binary data.
 This function is also available as "hexlify()".'''
@@ -24,7 +25,6 @@
         res.append(_value2char(ord(c) >> 4))
         res.append(_value2char(ord(c) & 0xf))
     return space.wrap(res.build())
-hexlify.unwrap_spec = [ObjSpace, 'bufferstr']
 
 # ____________________________________________________________
 
@@ -42,6 +42,7 @@
                          space.wrap('Non-hexadecimal digit found'))
 _char2value._always_inline_ = True
 
+ at unwrap_spec(hexstr='bufferstr')
 def unhexlify(space, hexstr):
     '''Binary data of hexadecimal representation.
 hexstr must contain an even number of hex digits (upper or lower case).
@@ -55,4 +56,3 @@
         b = _char2value(space, hexstr[i+1])
         res.append(chr((a << 4) | b))
     return space.wrap(res.build())
-unhexlify.unwrap_spec = [ObjSpace, 'bufferstr']

diff --git a/pypy/module/binascii/interp_hqx.py b/pypy/module/binascii/interp_hqx.py
--- a/pypy/module/binascii/interp_hqx.py
+++ b/pypy/module/binascii/interp_hqx.py
@@ -1,5 +1,5 @@
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.rlib.rstring import StringBuilder
 from pypy.module.binascii.interp_binascii import raise_Error, raise_Incomplete
 from pypy.rlib.rarithmetic import ovfcheck
@@ -62,6 +62,7 @@
 ]
 table_a2b_hqx = ''.join(map(chr, table_a2b_hqx))
 
+ at unwrap_spec(ascii='bufferstr')
 def a2b_hqx(space, ascii):
     """Decode .hqx coding.  Returns (bin, done)."""
 
@@ -97,13 +98,13 @@
         if pending_bits > 0:
             raise_Incomplete(space, 'String has incomplete number of bytes')
     return space.newtuple([space.wrap(res.build()), space.wrap(done)])
-a2b_hqx.unwrap_spec = [ObjSpace, 'bufferstr']
 
 # ____________________________________________________________
 
 hqx_encoding = (
     '!"#$%&\'()*+,-012345689 at ABCDEFGHIJKLMNPQRSTUVXYZ[`abcdefhijklmpqr')
 
+ at unwrap_spec(bin='bufferstr')
 def b2a_hqx(space, bin):
     "Encode .hqx data."
     extra = (len(bin) + 2) // 3
@@ -128,10 +129,10 @@
         leftchar <<= (6 - leftbits)
         res.append(hqx_encoding[leftchar & 0x3f])
     return space.wrap(res.build())
-b2a_hqx.unwrap_spec = [ObjSpace, 'bufferstr']
 
 # ____________________________________________________________
 
+ at unwrap_spec(hexbin='bufferstr')
 def rledecode_hqx(space, hexbin):
     "Decode hexbin RLE-coded string."
 
@@ -160,10 +161,10 @@
                     raise_Error(space, 'String starts with the RLE code \x90')
                 res.append_multiple_char(chr(lastpushed), count)
     return space.wrap(res.build())
-rledecode_hqx.unwrap_spec = [ObjSpace, 'bufferstr']
 
 # ____________________________________________________________
 
+ at unwrap_spec(data='bufferstr')
 def rlecode_hqx(space, data):
     "Binhex RLE-code binary data."
 
@@ -197,7 +198,6 @@
     # some programs somewhere that would start failing obscurely in rare
     # cases.
     return space.wrap(res.build())
-rlecode_hqx.unwrap_spec = [ObjSpace, 'bufferstr']
 
 # ____________________________________________________________
 
@@ -236,10 +236,10 @@
         0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
 ]
 
+ at unwrap_spec(data='bufferstr', oldcrc=int)
 def crc_hqx(space, data, oldcrc):
     "Compute hqx CRC incrementally."
     crc = oldcrc
     for c in data:
         crc = ((crc << 8) & 0xff00) ^ crctab_hqx[((crc >> 8) & 0xff) ^ ord(c)]
     return space.wrap(crc)
-crc_hqx.unwrap_spec = [ObjSpace, 'bufferstr', int]


More information about the Pypy-commit mailing list