[pypy-svn] pypy improve-unwrap_spec: progress: _locale module.

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


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

Log:	progress: _locale module.

diff --git a/pypy/module/_locale/interp_locale.py b/pypy/module/_locale/interp_locale.py
--- a/pypy/module/_locale/interp_locale.py
+++ b/pypy/module/_locale/interp_locale.py
@@ -3,7 +3,7 @@
 from pypy.rlib.rarithmetic import intmask
 
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import ObjSpace, W_Root
+from pypy.interpreter.gateway import unwrap_spec
 
 from pypy.rlib import rlocale
 from pypy.module.exceptions.interp_exceptions import _new_exception, W_Exception
@@ -45,6 +45,7 @@
             ul.append(chr(c))
     space.setattr(stringmod, space.wrap('letters'), space.wrap(''.join(ul)))
 
+ at unwrap_spec(category=int)
 def setlocale(space, category, w_locale=None):
     "(integer,string=None) -> string. Activates/queries locale processing."
 
@@ -63,8 +64,6 @@
 
     return space.wrap(result)
 
-setlocale.unwrap_spec = [ObjSpace, int, W_Root]
-
 def _w_copy_grouping(space, text):
     groups = [ space.wrap(ord(group)) for group in text ]
     if groups:
@@ -117,8 +116,6 @@
 
     return w_result
 
-localeconv.unwrap_spec = [ObjSpace]
-
 _strcoll = rlocale.external('strcoll', [rffi.CCHARP, rffi.CCHARP], rffi.INT)
 _wcscoll = rlocale.external('wcscoll', [rffi.CWCHARP, rffi.CWCHARP], rffi.INT)
 
@@ -154,11 +151,10 @@
 
     return space.wrap(result)
 
-strcoll.unwrap_spec = [ObjSpace, W_Root, W_Root]
-
 _strxfrm = rlocale.external('strxfrm',
                     [rffi.CCHARP, rffi.CCHARP, rffi.SIZE_T], rffi.SIZE_T)
 
+ at unwrap_spec(s=str)
 def strxfrm(space, s):
     "string -> string. Returns a string that behaves for cmp locale-aware."
     n1 = len(s) + 1
@@ -185,10 +181,9 @@
 
     return space.wrap(val)
 
-strxfrm.unwrap_spec = [ObjSpace, str]
-
 if rlocale.HAVE_LANGINFO:
 
+    @unwrap_spec(key=int)
     def nl_langinfo(space, key):
         """nl_langinfo(key) -> string
         Return the value for the locale information associated with key."""
@@ -199,14 +194,13 @@
             raise OperationError(space.w_ValueError,
                                  space.wrap("unsupported langinfo constant"))
 
-    nl_langinfo.unwrap_spec = [ObjSpace, int]
-
 #___________________________________________________________________
 # HAVE_LIBINTL dependence
 
 if rlocale.HAVE_LIBINTL:
     _gettext = rlocale.external('gettext', [rffi.CCHARP], rffi.CCHARP)
 
+    @unwrap_spec(msg=str)
     def gettext(space, msg):
         """gettext(msg) -> string
         Return translation of msg."""
@@ -216,10 +210,9 @@
         finally:
             rffi.free_charp(msg_c)
 
-    gettext.unwrap_spec = [ObjSpace, str]
-
     _dgettext = rlocale.external('dgettext', [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP)
 
+    @unwrap_spec(msg=str)
     def dgettext(space, w_domain, msg):
         """dgettext(domain, msg) -> string
         Return translation of msg in domain."""
@@ -242,11 +235,10 @@
 
         return space.wrap(rffi.charp2str(result))
 
-    dgettext.unwrap_spec = [ObjSpace, W_Root, str]
-
     _dcgettext = rlocale.external('dcgettext', [rffi.CCHARP, rffi.CCHARP, rffi.INT],
                                                                 rffi.CCHARP)
 
+    @unwrap_spec(msg=str, category=int)
     def dcgettext(space, w_domain, msg, category):
         """dcgettext(domain, msg, category) -> string
         Return translation of msg in domain and category."""
@@ -271,8 +263,6 @@
 
         return space.wrap(rffi.charp2str(result))
 
-    dcgettext.unwrap_spec = [ObjSpace, W_Root, str, int]
-
 
     _textdomain = rlocale.external('textdomain', [rffi.CCHARP], rffi.CCHARP)
 
@@ -293,11 +283,10 @@
 
         return space.wrap(rffi.charp2str(result))
 
-    textdomain.unwrap_spec = [ObjSpace, W_Root]
-
     _bindtextdomain = rlocale.external('bindtextdomain', [rffi.CCHARP, rffi.CCHARP],
                                                                 rffi.CCHARP)
 
+    @unwrap_spec(domain=str)
     def bindtextdomain(space, domain, w_dir):
         """bindtextdomain(domain, dir) -> string
         Bind the C library's domain to dir."""
@@ -324,12 +313,11 @@
             raise OperationError(space.w_OSError, space.wrap(errno))
         return space.wrap(rffi.charp2str(dirname))
 
-    bindtextdomain.unwrap_spec = [ObjSpace, str, W_Root]
-
     _bind_textdomain_codeset = rlocale.external('bind_textdomain_codeset',
                                     [rffi.CCHARP, rffi.CCHARP], rffi.CCHARP)
 
     if rlocale.HAVE_BIND_TEXTDOMAIN_CODESET:
+        @unwrap_spec(domain=str)
         def bind_textdomain_codeset(space, domain, w_codeset):
             """bind_textdomain_codeset(domain, codeset) -> string
             Bind the C library's domain to codeset."""
@@ -356,8 +344,6 @@
             else:
                 return space.wrap(rffi.charp2str(result))
 
-        bind_textdomain_codeset.unwrap_spec = [ObjSpace, str, W_Root]
-
 if sys.platform == 'win32':
     def getdefaultlocale(space):
         language, encoding = rlocale.getdefaultlocale()


More information about the Pypy-commit mailing list