[pypy-svn] r73388 - in pypy/branch/cpython-extension/pypy/module/cpyext: . test

trundle at codespeak.net trundle at codespeak.net
Mon Apr 5 01:08:53 CEST 2010


Author: trundle
Date: Mon Apr  5 01:08:51 2010
New Revision: 73388

Added:
   pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py
   pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py
Modified:
   pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
   pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
Log:
Add various Py_UNICODE_IS* functions and Py_UNICODE_TOLOWER.


Modified: pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/__init__.py	Mon Apr  5 01:08:51 2010
@@ -50,6 +50,7 @@
 import pypy.module.cpyext.import_
 import pypy.module.cpyext.mapping
 import pypy.module.cpyext.iterator
+import pypy.module.cpyext.unicodeobject
 
 # now that all rffi_platform.Struct types are registered, configure them
 api.configure_types()

Modified: pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	(original)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/stubs.py	Mon Apr  5 01:08:51 2010
@@ -5690,36 +5690,11 @@
     raise NotImplementedError
 
 @cpython_api([{Py_UNICODE}], rffi.INT_real)
-def Py_UNICODE_ISSPACE(space, ch):
-    """Return 1 or 0 depending on whether ch is a whitespace character."""
-    raise NotImplementedError
-
- at cpython_api([{Py_UNICODE}], rffi.INT_real)
-def Py_UNICODE_ISLOWER(space, ch):
-    """Return 1 or 0 depending on whether ch is a lowercase character."""
-    raise NotImplementedError
-
- at cpython_api([{Py_UNICODE}], rffi.INT_real)
-def Py_UNICODE_ISUPPER(space, ch):
-    """Return 1 or 0 depending on whether ch is an uppercase character."""
-    raise NotImplementedError
-
- at cpython_api([{Py_UNICODE}], rffi.INT_real)
 def Py_UNICODE_ISTITLE(space, ch):
     """Return 1 or 0 depending on whether ch is a titlecase character."""
     raise NotImplementedError
 
 @cpython_api([{Py_UNICODE}], rffi.INT_real)
-def Py_UNICODE_ISLINEBREAK(space, ch):
-    """Return 1 or 0 depending on whether ch is a linebreak character."""
-    raise NotImplementedError
-
- at cpython_api([{Py_UNICODE}], rffi.INT_real)
-def Py_UNICODE_ISDECIMAL(space, ch):
-    """Return 1 or 0 depending on whether ch is a decimal character."""
-    raise NotImplementedError
-
- at cpython_api([{Py_UNICODE}], rffi.INT_real)
 def Py_UNICODE_ISDIGIT(space, ch):
     """Return 1 or 0 depending on whether ch is a digit character."""
     raise NotImplementedError
@@ -5734,16 +5709,6 @@
     """Return 1 or 0 depending on whether ch is an alphabetic character."""
     raise NotImplementedError
 
- at cpython_api([{Py_UNICODE}], rffi.INT_real)
-def Py_UNICODE_ISALNUM(space, ch):
-    """Return 1 or 0 depending on whether ch is an alphanumeric character."""
-    raise NotImplementedError
-
- at cpython_api([{Py_UNICODE}], {Py_UNICODE})
-def Py_UNICODE_TOLOWER(space, ch):
-    """Return the character ch converted to lower case."""
-    raise NotImplementedError
-
 @cpython_api([{Py_UNICODE}], {Py_UNICODE})
 def Py_UNICODE_TOUPPER(space, ch):
     """Return the character ch converted to upper case."""

Added: pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/test/test_unicodeobject.py	Mon Apr  5 01:08:51 2010
@@ -0,0 +1,31 @@
+# encoding: iso-8859-15
+from pypy.module.cpyext.test.test_api import BaseApiTest
+
+class TestUnicode(BaseApiTest):
+    def test_IS(self, space, api):
+        for char in [0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x1c, 0x1d, 0x1e, 0x1f,
+                     0x20, 0x85, 0xa0, 0x1680, 0x2000, 0x2001, 0x2002,
+                     0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008,
+                     0x2009, 0x200a,
+                     #0x200b is in Other_Default_Ignorable_Code_Point in 4.1.0
+                     0x2028, 0x2029, 0x202f, 0x205f, 0x3000]:
+            assert api.Py_UNICODE_ISSPACE(char)
+        assert not api.Py_UNICODE_ISSPACE(ord(u'a'))
+
+        assert api.Py_UNICODE_ISDECIMAL(ord(u'\u0660'))
+        assert not api.Py_UNICODE_ISDECIMAL(ord(u'a'))
+
+        for char in [0x0a, 0x0d, 0x1c, 0x1d, 0x1e, 0x85, 0x2028, 0x2029]:
+            assert api.Py_UNICODE_ISLINEBREAK(char)
+
+        assert api.Py_UNICODE_ISLOWER(ord(u'ä'))
+        assert not api.Py_UNICODE_ISUPPER(ord(u'ä'))
+        assert api.Py_UNICODE_ISLOWER(ord(u'a'))
+        assert not api.Py_UNICODE_ISUPPER(ord(u'a'))
+        assert not api.Py_UNICODE_ISLOWER(ord(u'Ä'))
+        assert api.Py_UNICODE_ISUPPER(ord(u'Ä'))
+
+    def test_TOLOWER(self, space, api):
+        assert api.Py_UNICODE_TOLOWER(ord(u'ä')) == ord(u'ä')
+        assert api.Py_UNICODE_TOLOWER(ord(u'Ä')) == ord(u'ä')
+

Added: pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py
==============================================================================
--- (empty file)
+++ pypy/branch/cpython-extension/pypy/module/cpyext/unicodeobject.py	Mon Apr  5 01:08:51 2010
@@ -0,0 +1,53 @@
+from pypy.rpython.lltypesystem import rffi
+from pypy.module.unicodedata import unicodedb_4_1_0 as unicodedb
+from pypy.module.cpyext.api import CANNOT_FAIL, build_type_checkers, cpython_api
+
+PyUnicode_Check, PyUnicode_CheckExact = build_type_checkers("Unicode", "w_unicode")
+
+# XXX
+Py_UNICODE = rffi.UINT
+
+ at cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISSPACE(space, w_ch):
+    """Return 1 or 0 depending on whether ch is a whitespace character."""
+    return unicodedb.isspace(w_ch)
+
+ at cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISALNUM(space, w_ch):
+    """Return 1 or 0 depending on whether ch is an alphanumeric character."""
+    return unicodedb.isalnum(w_ch)
+
+ at cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISLINEBREAK(space, w_ch):
+    """Return 1 or 0 depending on whether ch is a linebreak character."""
+    return unicodedb.islinebreak(w_ch)
+
+ at cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISSPACE(space, w_ch):
+    """Return 1 or 0 depending on whether ch is a whitespace character."""
+    return unicodedb.isspace(w_ch)
+
+ at cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISALNUM(space, w_ch):
+    """Return 1 or 0 depending on whether ch is an alphanumeric character."""
+    return unicodedb.isalnum(w_ch)
+
+ at cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISDECIMAL(space, w_ch):
+    """Return 1 or 0 depending on whether ch is a decimal character."""
+    return unicodedb.isdecimal(w_ch)
+
+ at cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISLOWER(space, w_ch):
+    """Return 1 or 0 depending on whether ch is a lowercase character."""
+    return unicodedb.islower(w_ch)
+
+ at cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISUPPER(space, w_ch):
+    """Return 1 or 0 depending on whether ch is an uppercase character."""
+    return unicodedb.isupper(w_ch)
+
+ at cpython_api([Py_UNICODE], Py_UNICODE, error=CANNOT_FAIL)
+def Py_UNICODE_TOLOWER(space, w_ch):
+    """Return the character ch converted to lower case."""
+    return unicodedb.tolower(w_ch)



More information about the Pypy-commit mailing list