Author: Antonio Cuni <[email protected]>
Branch: refactor-str-types
Changeset: r68701:6b507443d1e4
Date: 2014-01-16 18:08 +0100
http://bitbucket.org/pypy/pypy/changeset/6b507443d1e4/
Log: give up with the idea of sharing idlower and isupper between bytes
and unicode, they are slightly different
diff --git a/pypy/objspace/std/stringmethods.py
b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -246,6 +246,7 @@
def descr_isdigit(self, space):
return self._is_generic(space, '_isdigit')
+ # this is only for bytes and bytesarray: unicodeobject overrides it
def descr_islower(self, space):
v = self._val(space)
if len(v) == 1:
@@ -283,6 +284,7 @@
return space.newbool(cased)
+ # this is only for bytes and bytesarray: unicodeobject overrides it
def descr_isupper(self, space):
v = self._val(space)
if len(v) == 1:
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
@@ -218,6 +218,12 @@
assert u'\u1FFc'.istitle()
assert u'Greek \u1FFcitlecases ...'.istitle()
+ def test_islower_isupper_with_titlecase(self):
+ # \u01c5 is a char which is neither lowercase nor uppercase, but
+ # titlecase
+ assert not u'\u01c5abc'.islower()
+ assert not u'\u01c5ABC'.isupper()
+
def test_capitalize(self):
assert u"brown fox".capitalize() == u"Brown fox"
assert u' hello '.capitalize() == u' hello '
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
@@ -327,6 +327,26 @@
def descr_isnumeric(self, space):
return self._is_generic(space, '_isnumeric')
+ def descr_islower(self, space):
+ cased = False
+ for uchar in self._value:
+ if (unicodedb.isupper(ord(uchar)) or
+ unicodedb.istitle(ord(uchar))):
+ return space.w_False
+ if not cased and unicodedb.islower(ord(uchar)):
+ cased = True
+ return space.newbool(cased)
+
+ def descr_isupper(self, space):
+ cased = False
+ for uchar in self._value:
+ if (unicodedb.islower(ord(uchar)) or
+ unicodedb.istitle(ord(uchar))):
+ return space.w_False
+ if not cased and unicodedb.isupper(ord(uchar)):
+ cased = True
+ return space.newbool(cased)
+
def wrapunicode(space, uni):
return W_UnicodeObject(uni)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit