[pypy-svn] r12752 - pypy/dist/pypy/objspace/std
pedronis at codespeak.net
pedronis at codespeak.net
Mon May 23 20:03:43 CEST 2005
Author: pedronis
Date: Mon May 23 20:03:42 2005
New Revision: 12752
Modified:
pypy/dist/pypy/objspace/std/objspace.py
pypy/dist/pypy/objspace/std/unicodeobject.py
pypy/dist/pypy/objspace/std/unicodetype.py
Log:
- assert unicode results (or arguments) as W_UnicodeObjects beyond the inferred W_Root
- made unicode_join__Unicode_ANY type-proper
- hackish fix for types of W_UnicodeObject.__init__ in space.wrap(unicode)
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Mon May 23 20:03:42 2005
@@ -200,7 +200,7 @@
if isinstance(x, str):
return W_StringObject(self, x)
if isinstance(x, unicode):
- return W_UnicodeObject(self, [u for u in x])
+ return W_UnicodeObject(self, [unichr(ord(u)) for u in x]) # xxx
if isinstance(x, dict):
items_w = [(self.wrap(k), self.wrap(v)) for (k, v) in x.iteritems()]
return W_DictObject(self, items_w)
Modified: pypy/dist/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/unicodeobject.py (original)
+++ pypy/dist/pypy/objspace/std/unicodeobject.py Mon May 23 20:03:42 2005
@@ -31,6 +31,9 @@
# Helper for converting int/long
def unicode_to_decimal_w(space, w_unistr):
+ if not isinstance(w_unistr, W_UnicodeObject):
+ raise OperationError(space.w_TypeError,
+ space.wrap("expected unicode"))
unistr = w_unistr._value
result = ['\0'] * len(unistr)
digits = [ '0', '1', '2', '3', '4',
@@ -52,7 +55,9 @@
# string-to-unicode delegation
def delegate_String2Unicode(w_str):
space = w_str.space
- return space.call_function(space.w_unicode, w_str)
+ w_uni = space.call_function(space.w_unicode, w_str)
+ assert isinstance(w_uni, W_UnicodeObject) # help the annotator!
+ return w_uni
def str_w__Unicode(space, w_uni):
return space.str_w(space.str(w_uni))
@@ -150,33 +155,38 @@
totlen = 0
if len(list) == 0:
return W_UnicodeObject(space, [])
+ values_list = [None] * len(list)
+ values_list[0] = [u'\0']
for i in range(len(list)):
item = list[i]
if space.is_true(space.isinstance(item, space.w_unicode)):
- list[i] = item._value
+ pass
elif space.is_true(space.isinstance(item, space.w_str)):
- list[i] = space.call_function(space.w_unicode, item)._value
+ item = space.call_function(space.w_unicode, item)
else:
w_msg = space.mod(space.wrap('sequence item %d: expected string or Unicode'),
space.wrap(i))
raise OperationError(space.w_TypeError, w_msg)
- totlen += len(list[i])
- totlen += len(delim) * (len(list) - 1)
- if len(list) == 1:
- return W_UnicodeObject(space, list[0])
+ assert isinstance(item, W_UnicodeObject)
+ item = item._value
+ totlen += len(item)
+ values_list[i] = item
+ totlen += len(delim) * (len(values_list) - 1)
+ if len(values_list) == 1:
+ return W_UnicodeObject(space, values_list[0])
# Allocate result
result = [u'\0'] * totlen
- first = list[0]
+ first = values_list[0]
for i in range(len(first)):
result[i] = first[i]
offset = len(first)
- for i in range(1, len(list)):
- item = list[i]
+ for i in range(1, len(values_list)):
+ item = values_list[i]
# Add delimiter
for j in range(len(delim)):
result[offset + j] = delim[j]
offset += len(delim)
- # Add item from list
+ # Add item from values_list
for j in range(len(item)):
result[offset + j] = item[j]
offset += len(item)
Modified: pypy/dist/pypy/objspace/std/unicodetype.py
==============================================================================
--- pypy/dist/pypy/objspace/std/unicodetype.py (original)
+++ pypy/dist/pypy/objspace/std/unicodetype.py Mon May 23 20:03:42 2005
@@ -102,6 +102,8 @@
w_value = unicode_from_object(space, w_obj)
else:
w_value = unicode_from_encoded_object(space, w_obj, w_encoding, w_errors)
+ # help the annotator! also the ._value depends on W_UnicodeObject layout
+ assert isinstance(w_value, W_UnicodeObject)
w_newobj = space.allocate_instance(W_UnicodeObject, w_unicodetype)
w_newobj.__init__(space, w_value._value)
return w_newobj
More information about the Pypy-commit
mailing list