[pypy-commit] pypy space-newtext: start replacing str in unwrap_spec with 'text' or 'bytes'

cfbolz pypy.commits at gmail.com
Tue Dec 6 09:27:57 EST 2016


Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch: space-newtext
Changeset: r88902:52a246e29cf5
Date: 2016-12-06 15:27 +0100
http://bitbucket.org/pypy/pypy/changeset/52a246e29cf5/

Log:	start replacing str in unwrap_spec with 'text' or 'bytes'

diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -364,9 +364,9 @@
         return w_result
 
     @unwrap_spec(argcount=int, nlocals=int, stacksize=int, flags=int,
-                 codestring=str,
-                 filename=str, name=str, firstlineno=int,
-                 lnotab=str, magic=int)
+                 codestring='bytes',
+                 filename='text', name='text', firstlineno=int,
+                 lnotab='bytes', magic=int)
     def descr_code__new__(space, w_subtype,
                           argcount, nlocals, stacksize, flags,
                           codestring, w_constants, w_names,
diff --git a/pypy/module/__builtin__/compiling.py b/pypy/module/__builtin__/compiling.py
--- a/pypy/module/__builtin__/compiling.py
+++ b/pypy/module/__builtin__/compiling.py
@@ -8,7 +8,7 @@
 from pypy.interpreter.gateway import unwrap_spec
 
 
- at unwrap_spec(filename=str, mode=str, flags=int, dont_inherit=int)
+ at unwrap_spec(filename='text', mode='text', flags=int, dont_inherit=int)
 def compile(space, w_source, filename, mode, flags=0, dont_inherit=0):
     """Compile the source string (a Python module, statement or expression)
 into a code object that can be executed by the exec statement or eval().
diff --git a/pypy/module/__builtin__/interp_classobj.py b/pypy/module/__builtin__/interp_classobj.py
--- a/pypy/module/__builtin__/interp_classobj.py
+++ b/pypy/module/__builtin__/interp_classobj.py
@@ -103,7 +103,7 @@
                 return w_result
         return None
 
-    @unwrap_spec(name=str)
+    @unwrap_spec(name='text')
     def descr_getattribute(self, space, name):
         if name and name[0] == "_":
             if name == "__dict__":
@@ -351,7 +351,7 @@
         else:
             return None
 
-    @unwrap_spec(name=str)
+    @unwrap_spec(name='text')
     def descr_getattribute(self, space, name):
         if len(name) >= 8 and name[0] == '_':
             if name == "__dict__":
diff --git a/pypy/module/__pypy__/interp_debug.py b/pypy/module/__pypy__/interp_debug.py
--- a/pypy/module/__pypy__/interp_debug.py
+++ b/pypy/module/__pypy__/interp_debug.py
@@ -3,7 +3,7 @@
 
 
 @jit.dont_look_inside
- at unwrap_spec(category=str)
+ at unwrap_spec(category='text')
 def debug_start(space, category):
     debug.debug_start(category)
 
@@ -13,12 +13,12 @@
     debug.debug_print(' '.join(parts))
 
 @jit.dont_look_inside
- at unwrap_spec(category=str)
+ at unwrap_spec(category='text')
 def debug_stop(space, category):
     debug.debug_stop(category)
 
 
- at unwrap_spec(category=str)
+ at unwrap_spec(category='text')
 def debug_print_once(space, category, args_w):
     debug_start(space, category)
     debug_print(space, args_w)
diff --git a/pypy/module/__pypy__/interp_dict.py b/pypy/module/__pypy__/interp_dict.py
--- a/pypy/module/__pypy__/interp_dict.py
+++ b/pypy/module/__pypy__/interp_dict.py
@@ -2,7 +2,7 @@
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import unwrap_spec
 
- at unwrap_spec(type=str)
+ at unwrap_spec(type='text')
 def newdict(space, type):
     """ newdict(type)
 
diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -22,7 +22,7 @@
     attach_gdb()
 
 
- at unwrap_spec(name=str)
+ at unwrap_spec(name='text')
 def method_cache_counter(space, name):
     """Return a tuple (method_cache_hits, method_cache_misses) for calls to
     methods with the name."""
@@ -41,7 +41,7 @@
     cache.misses = {}
     cache.hits = {}
 
- at unwrap_spec(name=str)
+ at unwrap_spec(name='text')
 def mapdict_cache_counter(space, name):
     """Return a tuple (index_cache_hits, index_cache_misses) for lookups
     in the mapdict cache with the given attribute name."""
@@ -75,7 +75,7 @@
     operr = space.getexecutioncontext().sys_exc_info(for_hidden=True)
     return space.w_None if operr is None else operr.get_w_traceback(space)
 
- at unwrap_spec(meth=str)
+ at unwrap_spec(meth='text')
 def lookup_special(space, w_obj, meth):
     """Lookup up a special method on an object."""
     if space.is_oldstyle_instance(w_obj):
@@ -163,7 +163,7 @@
     else:
         cache._code_hook = w_callable
 
- at unwrap_spec(string=str, byteorder=str, signed=int)
+ at unwrap_spec(string='bytes', byteorder='text', signed=int)
 def decode_long(space, string, byteorder='little', signed=1):
     from rpython.rlib.rbigint import rbigint, InvalidEndiannessError
     try:
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -121,7 +121,7 @@
         raise oefmt(space.w_TypeError, "argument must be callable")
 
 
- at unwrap_spec(encoding=str)
+ at unwrap_spec(encoding='text')
 def lookup_codec(space, encoding):
     """lookup(encoding) -> (encoder, decoder, stream_reader, stream_writer)
     Looks up a codec tuple in the Python codec registry and returns
@@ -278,7 +278,7 @@
                 globals()[name]).spacebind(space)
 
 
- at unwrap_spec(errors=str)
+ at unwrap_spec(errors='text')
 def lookup_error(space, errors):
     """lookup_error(errors) -> handler
 
@@ -295,7 +295,7 @@
     return w_err_handler
 
 
- at unwrap_spec(errors=str)
+ at unwrap_spec(errors='text')
 def encode(space, w_obj, w_encoding=None, errors='strict'):
     """encode(obj, [encoding[,errors]]) -> object
 
@@ -324,7 +324,7 @@
     s = space.getarg_w('t#', w_data)
     return space.newtuple([space.newbytes(s), space.newint(len(s))])
 
- at unwrap_spec(errors=str)
+ at unwrap_spec(errors='text')
 def decode(space, w_obj, w_encoding=None, errors='strict'):
     """decode(obj, [encoding[,errors]]) -> object
 
@@ -349,7 +349,7 @@
     else:
         assert 0, "XXX, what to do here?"
 
- at unwrap_spec(errors=str)
+ at unwrap_spec(errors='text')
 def register_error(space, errors, w_handler):
     """register_error(errors, handler)
 
@@ -685,7 +685,7 @@
 # support for the "string escape" codec
 # This is a bytes-to bytes transformation
 
- at unwrap_spec(data=str, errors='str_or_None')
+ at unwrap_spec(data='bytes', errors='str_or_None')
 def escape_encode(space, data, errors='strict'):
     from pypy.objspace.std.bytesobject import string_escape_encode
     result = string_escape_encode(data, quote="'")
@@ -695,7 +695,7 @@
     w_result = space.newbytes(result[start:end])
     return space.newtuple([w_result, space.newint(len(data))])
 
- at unwrap_spec(data=str, errors='str_or_None')
+ at unwrap_spec(data='bytes', errors='str_or_None')
 def escape_decode(space, data, errors='strict'):
     from pypy.interpreter.pyparser.parsestring import PyString_DecodeEscape
     result = PyString_DecodeEscape(space, data, errors, None)
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -132,7 +132,7 @@
     # The 'direct_' methods assume that the caller already acquired the
     # file lock.  They don't convert StreamErrors to OperationErrors, too.
 
-    @unwrap_spec(mode=str, buffering=int)
+    @unwrap_spec(mode='text', buffering=int)
     def direct___init__(self, w_name, mode='r', buffering=-1):
         self.direct_close()
         self.w_name = w_name
@@ -550,7 +550,7 @@
     W_File.__init__(file, space)
     return file
 
- at unwrap_spec(fd=int, mode=str, buffering=int)
+ at unwrap_spec(fd=int, mode='text', buffering=int)
 def descr_file_fdopen(space, w_subtype, fd, mode='r', buffering=-1):
     file = space.allocate_instance(W_File, w_subtype)
     W_File.__init__(file, space)
diff --git a/pypy/module/_file/interp_stream.py b/pypy/module/_file/interp_stream.py
--- a/pypy/module/_file/interp_stream.py
+++ b/pypy/module/_file/interp_stream.py
@@ -105,6 +105,7 @@
 
 for name, argtypes in streamio.STREAM_METHODS.iteritems():
     numargs = len(argtypes)
+    argtypes = [typ if typ is not str else 'bytes' for typ in argtypes]
     args = ", ".join(["v%s" % i for i in range(numargs)])
     exec py.code.Source("""
     def %(name)s(self, space, %(args)s):
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -128,7 +128,7 @@
         W_FileIO.__init__(self, space)
         return self
 
-    @unwrap_spec(mode=str, closefd=int)
+    @unwrap_spec(mode='text', closefd=int)
     def descr_init(self, space, w_name, mode='r', closefd=True):
         if space.isinstance_w(w_name, space.w_float):
             raise oefmt(space.w_TypeError,
diff --git a/pypy/module/_io/interp_io.py b/pypy/module/_io/interp_io.py
--- a/pypy/module/_io/interp_io.py
+++ b/pypy/module/_io/interp_io.py
@@ -40,7 +40,7 @@
 
 DEFAULT_BUFFER_SIZE = 8 * 1024
 
- at unwrap_spec(mode=str, buffering=int,
+ at unwrap_spec(mode='text', buffering=int,
              encoding="str_or_None", errors="str_or_None",
              newline="str_or_None", closefd=bool)
 def open(space, w_file, mode="r", buffering=-1, encoding=None, errors=None,
diff --git a/pypy/module/_pickle_support/maker.py b/pypy/module/_pickle_support/maker.py
--- a/pypy/module/_pickle_support/maker.py
+++ b/pypy/module/_pickle_support/maker.py
@@ -73,7 +73,7 @@
     new_iter = W_XRangeIterator(space, current, remaining, step)
     return new_iter
 
- at unwrap_spec(identifier=str)
+ at unwrap_spec(identifier='text')
 def builtin_code(space, identifier):
     from pypy.interpreter import gateway
     try:
@@ -82,7 +82,7 @@
         raise oefmt(space.w_RuntimeError,
                     "cannot unpickle builtin code: %s", identifier)
 
- at unwrap_spec(identifier=str)
+ at unwrap_spec(identifier='text')
 def builtin_function(space, identifier):
     from pypy.interpreter import function
     try:
diff --git a/pypy/module/_socket/interp_func.py b/pypy/module/_socket/interp_func.py
--- a/pypy/module/_socket/interp_func.py
+++ b/pypy/module/_socket/interp_func.py
@@ -20,7 +20,7 @@
         raise converted_error(space, e)
     return space.newtext(res)
 
- at unwrap_spec(host=str)
+ at unwrap_spec(host='text')
 def gethostbyname(space, host):
     """gethostbyname(host) -> address
 
@@ -53,7 +53,7 @@
         raise converted_error(space, e)
     return common_wrapgethost(space, res)
 
- at unwrap_spec(host=str)
+ at unwrap_spec(host='text')
 def gethostbyaddr(space, host):
     """gethostbyaddr(host) -> (name, aliaslist, addresslist)
 
@@ -66,7 +66,7 @@
         raise converted_error(space, e)
     return common_wrapgethost(space, res)
 
- at unwrap_spec(name=str, w_proto = WrappedDefault(None))
+ at unwrap_spec(name='text', w_proto = WrappedDefault(None))
 def getservbyname(space, name, w_proto):
     """getservbyname(servicename[, protocolname]) -> integer
 
@@ -106,7 +106,7 @@
         raise converted_error(space, e)
     return space.newtext(service)
 
- at unwrap_spec(name=str)
+ at unwrap_spec(name='text')
 def getprotobyname(space, name):
     """getprotobyname(name) -> integer
 
@@ -198,7 +198,7 @@
     """
     return space.newint(rsocket.htonl(x))
 
- at unwrap_spec(ip=str)
+ at unwrap_spec(ip='text')
 def inet_aton(space, ip):
     """inet_aton(string) -> packed 32-bit IP representation
 
@@ -211,7 +211,7 @@
         raise converted_error(space, e)
     return space.newbytes(buf)
 
- at unwrap_spec(packed=str)
+ at unwrap_spec(packed='text')
 def inet_ntoa(space, packed):
     """inet_ntoa(packed_ip) -> ip_address_string
 
@@ -223,7 +223,7 @@
         raise converted_error(space, e)
     return space.newtext(ip)
 
- at unwrap_spec(family=int, ip=str)
+ at unwrap_spec(family=int, ip='text')
 def inet_pton(space, family, ip):
     """inet_pton(family, ip) -> packed IP address string
 
@@ -236,7 +236,7 @@
         raise converted_error(space, e)
     return space.newbytes(buf)
 
- at unwrap_spec(family=int, packed=str)
+ at unwrap_spec(family=int, packed='bufferstr')
 def inet_ntop(space, family, packed):
     """inet_ntop(family, packed_ip) -> string formatted IP address
 
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -226,7 +226,7 @@
 
 if HAVE_OPENSSL_RAND:
     # helper routines for seeding the SSL PRNG
-    @unwrap_spec(string=str, entropy=float)
+    @unwrap_spec(string='bytes', entropy=float)
     def RAND_add(space, string, entropy):
         """RAND_add(string, entropy)
 
@@ -247,7 +247,7 @@
         return space.newint(res)
 
     if HAVE_OPENSSL_RAND_EGD:
-        @unwrap_spec(path=str)
+        @unwrap_spec(path='text')
         def RAND_egd(space, path):
             """RAND_egd(path) -> bytes
 
@@ -263,7 +263,7 @@
             return space.newint(bytes)
     else:
         # Dummy func for platforms missing RAND_egd(). Most likely LibreSSL.
-        @unwrap_spec(path=str)
+        @unwrap_spec(path='text')
         def RAND_egd(space, path):
             raise ssl_error(space, "RAND_egd unavailable")
 
@@ -1150,7 +1150,7 @@
     return getattr(space.fromcache(Cache), name)
 
 
- at unwrap_spec(filename=str)
+ at unwrap_spec(filename='text')
 def _test_decode_cert(space, filename):
     cert = libssl_BIO_new(libssl_BIO_s_file())
     if not cert:
@@ -1334,7 +1334,7 @@
     def descr_wrap_socket(self, space, w_sock, server_side, w_server_hostname=None, w_ssl_sock=None):
         return _SSLSocket.descr_new(space, self, w_sock, server_side, w_server_hostname, w_ssl_sock)
 
-    @unwrap_spec(cipherlist=str)
+    @unwrap_spec(cipherlist='text')
     def descr_set_ciphers(self, space, cipherlist):
         ret = libssl_SSL_CTX_set_cipher_list(self.ctx, cipherlist)
         if ret == 0:
@@ -1499,7 +1499,7 @@
             libssl_SSL_CTX_set_default_passwd_cb_userdata(
                 self.ctx, None)
 
-    @unwrap_spec(filepath=str)
+    @unwrap_spec(filepath='text')
     def load_dh_params_w(self, space, filepath):
         bio = libssl_BIO_new_file(filepath, "r")
         if not bio:
@@ -1688,7 +1688,7 @@
                 rlist.append(_decode_certificate(space, cert))
         return space.newlist(rlist)
 
-    @unwrap_spec(name=str)
+    @unwrap_spec(name='text')
     def set_ecdh_curve_w(self, space, name):
         nid = libssl_OBJ_sn2nid(name)
         if nid == 0:
@@ -1767,7 +1767,7 @@
     return space.newtuple([space.newint(nid), w_sn, w_ln, w_buf])
 
 
- at unwrap_spec(txt=str, name=bool)
+ at unwrap_spec(txt='bytes', name=bool)
 def txt2obj(space, txt, name=False):
     obj = libssl_OBJ_txt2obj(txt, not name)
     if not obj:
diff --git a/pypy/module/imp/interp_imp.py b/pypy/module/imp/interp_imp.py
--- a/pypy/module/imp/interp_imp.py
+++ b/pypy/module/imp/interp_imp.py
@@ -132,7 +132,7 @@
     return _run_compiled_module(space, w_modulename, filename, w_file, w_mod,
                                 check_afterwards=True)
 
- at unwrap_spec(filename=str)
+ at unwrap_spec(filename='text')
 def load_dynamic(space, w_modulename, filename, w_file=None):
     if not importing.has_so_extension(space):
         raise oefmt(space.w_ImportError, "Not implemented")
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -1017,7 +1017,7 @@
     except OSError as e:
         raise wrap_oserror(space, e)
 
- at unwrap_spec(username=str, gid=c_gid_t)
+ at unwrap_spec(username='text', gid=c_gid_t)
 def initgroups(space, username, gid):
     """ initgroups(username, gid) -> None
     
diff --git a/pypy/module/struct/interp_struct.py b/pypy/module/struct/interp_struct.py
--- a/pypy/module/struct/interp_struct.py
+++ b/pypy/module/struct/interp_struct.py
@@ -32,7 +32,7 @@
     return fmtiter.totalsize
 
 
- at unwrap_spec(format=str)
+ at unwrap_spec(format='text')
 def calcsize(space, format):
     return space.newint(_calcsize(space, format))
 
@@ -52,13 +52,13 @@
     return fmtiter.result.build()
 
 
- at unwrap_spec(format=str)
+ at unwrap_spec(format='text')
 def pack(space, format, args_w):
     return space.newbytes(_pack(space, format, args_w))
 
 
 # XXX inefficient
- at unwrap_spec(format=str, offset=int)
+ at unwrap_spec(format='text', offset=int)
 def pack_into(space, format, w_buffer, offset, args_w):
     res = _pack(space, format, args_w)
     buf = space.getarg_w('w*', w_buffer)
@@ -83,13 +83,13 @@
     return space.newtuple(fmtiter.result_w[:])
 
 
- at unwrap_spec(format=str)
+ at unwrap_spec(format='text')
 def unpack(space, format, w_str):
     buf = space.getarg_w('s*', w_str)
     return _unpack(space, format, buf)
 
 
- at unwrap_spec(format=str, offset=int)
+ at unwrap_spec(format='text', offset=int)
 def unpack_from(space, format, w_buffer, offset=0):
     size = _calcsize(space, format)
     buf = space.getarg_w('z*', w_buffer)
@@ -112,7 +112,7 @@
         self.format = format
         self.size = _calcsize(space, format)
 
-    @unwrap_spec(format=str)
+    @unwrap_spec(format='text')
     def descr__new__(space, w_subtype, format):
         self = space.allocate_instance(W_Struct, w_subtype)
         W_Struct.__init__(self, space, format)
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -224,7 +224,7 @@
         return w_obj
 
     @staticmethod
-    @unwrap_spec(kind=str)
+    @unwrap_spec(kind='text')
     def descr___getformat__(space, w_cls, kind):
         if kind == "float":
             return space.newtext(_float_format)
@@ -233,7 +233,7 @@
         raise oefmt(space.w_ValueError, "only float and double are valid")
 
     @staticmethod
-    @unwrap_spec(s=str)
+    @unwrap_spec(s='text')
     def descr_fromhex(space, w_cls, s):
         length = len(s)
         i = 0


More information about the pypy-commit mailing list