[pypy-svn] r55910 - pypy/branch/2.5-features/pypy/objspace/std
bgola at codespeak.net
bgola at codespeak.net
Tue Jun 17 00:26:25 CEST 2008
Author: bgola
Date: Tue Jun 17 00:26:24 2008
New Revision: 55910
Modified:
pypy/branch/2.5-features/pypy/objspace/std/ropeunicodeobject.py
pypy/branch/2.5-features/pypy/objspace/std/unicodeobject.py
Log:
more refactoring...
Modified: pypy/branch/2.5-features/pypy/objspace/std/ropeunicodeobject.py
==============================================================================
--- pypy/branch/2.5-features/pypy/objspace/std/ropeunicodeobject.py (original)
+++ pypy/branch/2.5-features/pypy/objspace/std/ropeunicodeobject.py Tue Jun 17 00:26:24 2008
@@ -179,22 +179,16 @@
def eq__RopeUnicode_Rope(space, w_runi, w_rope):
from pypy.objspace.std.unicodeobject import check_unicode_from_string
- msg = "Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal"
- w_runi2 = check_unicode_from_string(space, w_rope, msg, unicode_from_string)
- if w_runi2 is None:
- return space.w_False
- return space.newbool(_eq(w_runi, w_runi2))
+ return check_unicode_from_string(space, w_runi, w_rope,
+ space.w_False, unicode_from_string)
def ne__RopeUnicode_RopeUnicode(space, w_str1, w_str2):
return space.newbool(not _eq(w_str1, w_str2))
def ne__RopeUnicode_Rope(space, w_runi, w_rope):
from pypy.objspace.std.unicodeobject import check_unicode_from_string
- msg = "Unicode unequal comparison failed to convert both arguments to Unicode - interpreting them as being unequal"
- w_runi2 = check_unicode_from_string(space, w_rope, msg, unicode_from_string)
- if w_runi2 is None:
- return space.w_True
- return space.newbool(not _eq(w_runi, w_runi2))
+ return check_unicode_from_string(space, w_runi, w_rope,
+ space.w_True, unicode_from_string)
def gt__RopeUnicode_RopeUnicode(space, w_str1, w_str2):
n1 = w_str1._node
Modified: pypy/branch/2.5-features/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/branch/2.5-features/pypy/objspace/std/unicodeobject.py (original)
+++ pypy/branch/2.5-features/pypy/objspace/std/unicodeobject.py Tue Jun 17 00:26:24 2008
@@ -71,15 +71,20 @@
return w_uni
# checks if should trigger an unicode warning
-def check_unicode_from_string(space, w_str, msg, unicode_from_string):
+def check_unicode_from_string(space, w_uni, w_str, value, uni_from_str):
try:
- w_uni2 = unicode_from_string(space, w_str)
+ w_uni2 = uni_from_str(space, w_str)
except OperationError, e:
if e.match(space, space.w_UnicodeDecodeError):
+ word = "equal" if value == space.w_False else "unequal"
+ msg = "Unicode %s comparison failed to convert both arguments\
+ to Unicode - interpreting them as being unequal" % word
space.warn(msg, space.w_UnicodeWarning)
- return None
+ return value
raise
- return w_uni2
+ if value == space.w_False:
+ return space.eq(w_uni, w_uni2)
+ return space.not_(space.eq(w_uni, w_uni2))
def str_w__Unicode(space, w_uni):
return space.str_w(str__Unicode(space, w_uni))
@@ -96,21 +101,15 @@
def eq__Unicode_String(space, w_uni, w_str):
from pypy.objspace.std.unicodetype import unicode_from_string
- msg = "Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal"
- w_uni2 = check_unicode_from_string(space, w_str, msg, unicode_from_string)
- if w_uni2 is None:
- return space.w_False
- return space.newbool(w_uni._value == w_uni2._value)
+ return check_unicode_from_string(space, w_uni, w_str,
+ space.w_False, unicode_from_string)
eq__Unicode_Rope = eq__Unicode_String
def ne__Unicode_String(space, w_uni, w_str):
from pypy.objspace.std.unicodetype import unicode_from_string
- msg = "Unicode unequal comparison failed to convert both arguments to Unicode - interpreting them as being unequal"
- w_uni2 = check_unicode_from_string(space, w_str, msg, unicode_from_string)
- if w_uni2 is None:
- return space.w_True
- return space.newbool(w_uni._value != w_uni2._value)
+ return check_unicode_from_string(space, w_uni, w_str,
+ space.w_True, unicode_from_string)
ne__Unicode_Rope = ne__Unicode_String
More information about the Pypy-commit
mailing list