[pypy-svn] r12043 - in pypy/dist/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Sat May 7 01:15:34 CEST 2005


Author: arigo
Date: Sat May  7 01:15:34 2005
New Revision: 12043

Modified:
   pypy/dist/pypy/objspace/std/stringobject.py
   pypy/dist/pypy/objspace/std/test/test_stringobject.py
Log:
We tested an incorrect behavior of str.islower() and str.isupper().
Fixed the test, and fixed the implementation.



Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/stringobject.py	Sat May  7 01:15:34 2005
@@ -67,7 +67,6 @@
         c = v[0]
         return space.newbool(fun(c))
     else:
-        res = 1
         for idx in range(len(v)):
             if not fun(v[idx]):
                 return space.w_False
@@ -100,10 +99,36 @@
     return _is_generic(w_self, _isalnum)
 
 def str_isupper__String(space, w_self):
-    return _is_generic(w_self, _isupper)
+    """Return True if all cased characters in S are uppercase and there is
+at least one cased character in S, False otherwise."""
+    space = w_self.space   
+    v = w_self._value
+    if len(v) == 1:
+        c = v[0]
+        return space.newbool(_isupper(c))
+    cased = False
+    for idx in range(len(v)):
+        if _islower(v[idx]):
+            return space.w_False
+        elif not cased and _isupper(v[idx]):
+            cased = True
+    return space.newbool(cased)
 
 def str_islower__String(space, w_self):
-    return _is_generic(w_self, _islower)
+    """Return True if all cased characters in S are lowercase and there is
+at least one cased character in S, False otherwise."""
+    space = w_self.space   
+    v = w_self._value
+    if len(v) == 1:
+        c = v[0]
+        return space.newbool(_islower(c))
+    cased = False
+    for idx in range(len(v)):
+        if _isupper(v[idx]):
+            return space.w_False
+        elif not cased and _islower(v[idx]):
+            cased = True
+    return space.newbool(cased)
 
 def str_istitle__String(space, w_self):
     input = w_self._value

Modified: pypy/dist/pypy/objspace/std/test/test_stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_stringobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_stringobject.py	Sat May  7 01:15:34 2005
@@ -468,7 +468,7 @@
         assert "\t\t\b\b\n".islower() == False
         assert "b".islower() == True
         assert "bbb".islower() == True
-        assert "!bbb".islower() == False
+        assert "!bbb".islower() == True
         assert "BBB".islower() == False
         assert "bbbBBB".islower() == False
 
@@ -478,7 +478,7 @@
         assert "\t\t\b\b\n".isupper() == False
         assert "B".isupper() == True
         assert "BBB".isupper() == True
-        assert "!BBB".isupper() == False
+        assert "!BBB".isupper() == True
         assert "bbb".isupper() == False
         assert "BBBbbb".isupper() == False
                           



More information about the Pypy-commit mailing list