Author: Amaury Forgeot d'Arc <[email protected]>
Branch:
Changeset: r52818:4f01039bfe04
Date: 2012-02-23 00:38 +0100
http://bitbucket.org/pypy/pypy/changeset/4f01039bfe04/
Log: cpyext: implement remaining Py_UNICODE_IS* functions
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -1853,26 +1853,6 @@
"""
raise NotImplementedError
-@cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
-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, error=CANNOT_FAIL)
-def Py_UNICODE_ISDIGIT(space, ch):
- """Return 1 or 0 depending on whether ch is a digit character."""
- raise NotImplementedError
-
-@cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
-def Py_UNICODE_ISNUMERIC(space, ch):
- """Return 1 or 0 depending on whether ch is a numeric character."""
- raise NotImplementedError
-
-@cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
-def Py_UNICODE_ISALPHA(space, ch):
- """Return 1 or 0 depending on whether ch is an alphabetic character."""
- raise NotImplementedError
-
@cpython_api([rffi.CCHARP], PyObject)
def PyUnicode_FromFormat(space, format):
"""Take a C printf()-style format string and a variable number of
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py
b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -204,8 +204,18 @@
assert api.Py_UNICODE_ISSPACE(unichr(char))
assert not api.Py_UNICODE_ISSPACE(u'a')
+ assert api.Py_UNICODE_ISALPHA(u'a')
+ assert not api.Py_UNICODE_ISALPHA(u'0')
+ assert api.Py_UNICODE_ISALNUM(u'a')
+ assert api.Py_UNICODE_ISALNUM(u'0')
+ assert not api.Py_UNICODE_ISALNUM(u'+')
+
assert api.Py_UNICODE_ISDECIMAL(u'\u0660')
assert not api.Py_UNICODE_ISDECIMAL(u'a')
+ assert api.Py_UNICODE_ISDIGIT(u'9')
+ assert not api.Py_UNICODE_ISDIGIT(u'@')
+ assert api.Py_UNICODE_ISNUMERIC(u'9')
+ assert not api.Py_UNICODE_ISNUMERIC(u'@')
for char in [0x0a, 0x0d, 0x1c, 0x1d, 0x1e, 0x85, 0x2028, 0x2029]:
assert api.Py_UNICODE_ISLINEBREAK(unichr(char))
@@ -216,6 +226,9 @@
assert not api.Py_UNICODE_ISUPPER(u'a')
assert not api.Py_UNICODE_ISLOWER(u'�')
assert api.Py_UNICODE_ISUPPER(u'�')
+ assert not api.Py_UNICODE_ISTITLE(u'A')
+ assert api.Py_UNICODE_ISTITLE(
+ u'\N{LATIN CAPITAL LETTER L WITH SMALL LETTER J}')
def test_TOLOWER(self, space, api):
assert api.Py_UNICODE_TOLOWER(u'�') == u'�'
diff --git a/pypy/module/cpyext/unicodeobject.py
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -89,6 +89,11 @@
return unicodedb.isspace(ord(ch))
@cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISALPHA(space, ch):
+ """Return 1 or 0 depending on whether ch is an alphabetic character."""
+ return unicodedb.isalpha(ord(ch))
+
+@cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
def Py_UNICODE_ISALNUM(space, ch):
"""Return 1 or 0 depending on whether ch is an alphanumeric character."""
return unicodedb.isalnum(ord(ch))
@@ -104,6 +109,16 @@
return unicodedb.isdecimal(ord(ch))
@cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISDIGIT(space, ch):
+ """Return 1 or 0 depending on whether ch is a digit character."""
+ return unicodedb.isdigit(ord(ch))
+
+@cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISNUMERIC(space, ch):
+ """Return 1 or 0 depending on whether ch is a numeric character."""
+ return unicodedb.isnumeric(ord(ch))
+
+@cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
def Py_UNICODE_ISLOWER(space, ch):
"""Return 1 or 0 depending on whether ch is a lowercase character."""
return unicodedb.islower(ord(ch))
@@ -113,6 +128,11 @@
"""Return 1 or 0 depending on whether ch is an uppercase character."""
return unicodedb.isupper(ord(ch))
+@cpython_api([Py_UNICODE], rffi.INT_real, error=CANNOT_FAIL)
+def Py_UNICODE_ISTITLE(space, ch):
+ """Return 1 or 0 depending on whether ch is a titlecase character."""
+ return unicodedb.istitle(ord(ch))
+
@cpython_api([Py_UNICODE], Py_UNICODE, error=CANNOT_FAIL)
def Py_UNICODE_TOLOWER(space, ch):
"""Return the character ch converted to lower case."""
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit