[pypy-commit] pypy unicode-strategies: start to implement space.listview_unicode; it works only for lists for now

antocuni noreply at buildbot.pypy.org
Fri Oct 26 21:45:27 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: unicode-strategies
Changeset: r58470:87cc5b05aa76
Date: 2012-10-26 19:16 +0200
http://bitbucket.org/pypy/pypy/changeset/87cc5b05aa76/

Log:	start to implement space.listview_unicode; it works only for lists
	for now

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -953,6 +953,13 @@
         """
         return None
 
+    def listview_unicode(self, w_list):
+        """ Return a list of unwrapped unicode out of a list of unicode. If the
+        argument is not a list or does not contain only unicode, return None.
+        May return None anyway.
+        """
+        return None
+
     def view_as_kwargs(self, w_dict):
         """ if w_dict is a kwargs-dict, return two lists, one of unwrapped
         strings and one of wrapped values. otherwise return (None, None)
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -223,6 +223,11 @@
         not use the list strategy, return None. """
         return self.strategy.getitems_str(self)
 
+    def getitems_unicode(self):
+        """ Return the items in the list as unwrapped unicodes. If the list does
+        not use the list strategy, return None. """
+        return self.strategy.getitems_unicode(self)
+
     def getitems_int(self):
         """ Return the items in the list as unwrapped ints. If the list does
         not use the list strategy, return None. """
@@ -327,6 +332,9 @@
     def getitems_str(self, w_list):
         return None
 
+    def getitems_unicode(self, w_list):
+        return None
+
     def getitems_int(self, w_list):
         return None
 
@@ -1078,6 +1086,8 @@
         if reverse:
             l.reverse()
 
+    def getitems_unicode(self, w_list):
+        return self.unerase(w_list.lstorage)
 
 # _______________________________________________________
 
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -464,6 +464,21 @@
             return w_obj.getitems_str()
         return None
 
+    def listview_unicode(self, w_obj):
+        # note: uses exact type checking for objects with strategies,
+        # and isinstance() for others.  See test_listobject.test_uses_custom...
+        if type(w_obj) is W_ListObject:
+            return w_obj.getitems_unicode()
+        ## if type(w_obj) is W_DictMultiObject:
+        ##     return w_obj.listview_unicode()
+        ## if type(w_obj) is W_SetObject or type(w_obj) is W_FrozensetObject:
+        ##     return w_obj.listview_unicode()
+        ## if isinstance(w_obj, W_UnicodeObject):
+        ##     return w_obj.listview_unicode()
+        ## if isinstance(w_obj, W_ListObject) and self._uses_list_iter(w_obj):
+        ##     return w_obj.getitems_unicode()
+        return None
+
     def listview_int(self, w_obj):
         if type(w_obj) is W_ListObject:
             return w_obj.getitems_int()
diff --git a/pypy/objspace/std/test/test_liststrategies.py b/pypy/objspace/std/test/test_liststrategies.py
--- a/pypy/objspace/std/test/test_liststrategies.py
+++ b/pypy/objspace/std/test/test_liststrategies.py
@@ -515,6 +515,12 @@
         w_l = self.space.newlist([self.space.wrap('a'), self.space.wrap('b')])
         assert space.listview_str(w_l) == ["a", "b"]
 
+    def test_listview_unicode(self):
+        space = self.space
+        assert space.listview_unicode(space.wrap(1)) == None
+        w_l = self.space.newlist([self.space.wrap(u'a'), self.space.wrap(u'b')])
+        assert space.listview_unicode(w_l) == [u"a", u"b"]
+
     def test_string_join_uses_listview_str(self):
         space = self.space
         w_l = self.space.newlist([self.space.wrap('a'), self.space.wrap('b')])


More information about the pypy-commit mailing list