Author: Ronan Lamy <[email protected]>
Branch: py3.7
Changeset: r97358:f765d10dbfa2
Date: 2019-09-01 00:30 +0100
http://bitbucket.org/pypy/pypy/changeset/f765d10dbfa2/

Log:    Implement str.isascii

diff --git a/pypy/objspace/std/test/test_unicodeobject.py 
b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -355,6 +355,12 @@
         # single surrogate character
         assert not "\ud800".isprintable()
 
+    def test_isascii(self):
+        assert "".isascii()
+        assert "abcdefg\t".isascii()
+        assert not "abc\u0374".isascii()
+        assert not "\ud800abc".isascii()
+
     @py.test.mark.skipif("not config.option.runappdirect and sys.maxunicode == 
0xffff")
     def test_isprintable_wide(self):
         assert '\U0001F46F'.isprintable()  # Since unicode 6.0
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -1035,6 +1035,9 @@
     def is_ascii(self):
         return self._length == len(self._utf8)
 
+    def descr_isascii(self, space):
+        return space.newbool(self.is_ascii())
+
     def _index_to_byte(self, index):
         if self.is_ascii():
             assert index >= 0
@@ -1506,6 +1509,13 @@
         and there is at least one character in S, False otherwise.
         """
 
+    def isascii():
+        """Return True if all characters in the string are ASCII, False 
otherwise.
+
+        ASCII characters have code points in the range U+0000-U+007F.
+        Empty string is ASCII too.
+        """
+
     def casefold():
         """S.casefold() -> str
 
@@ -1824,6 +1834,8 @@
                          doc=UnicodeDocstrings.isalnum.__doc__),
     isalpha = interp2app(W_UnicodeObject.descr_isalpha,
                          doc=UnicodeDocstrings.isalpha.__doc__),
+    isascii = interp2app(W_UnicodeObject.descr_isascii,
+                         doc=UnicodeDocstrings.isascii.__doc__),
     isdecimal = interp2app(W_UnicodeObject.descr_isdecimal,
                            doc=UnicodeDocstrings.isdecimal.__doc__),
     isdigit = interp2app(W_UnicodeObject.descr_isdigit,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to