[pypy-svn] r34204 - in pypy/branch/transparent-proxy/pypy: interpreter objspace/std objspace/std/test

fijal at codespeak.net fijal at codespeak.net
Sat Nov 4 18:49:51 CET 2006


Author: fijal
Date: Sat Nov  4 18:49:49 2006
New Revision: 34204

Added:
   pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_iter.py   (contents, props changed)
Modified:
   pypy/branch/transparent-proxy/pypy/interpreter/typedef.py
   pypy/branch/transparent-proxy/pypy/objspace/std/proxyobject.py
   pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_internals.py
   pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py
Log:
(pedronis, fijal) - Added GeneratorIterator support.


Modified: pypy/branch/transparent-proxy/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/transparent-proxy/pypy/interpreter/typedef.py	Sat Nov  4 18:49:49 2006
@@ -668,8 +668,10 @@
 GeneratorIterator.typedef = TypeDef("generator",
     __reduce__   = interp2app(GeneratorIterator.descr__reduce__,
                               unwrap_spec=['self', ObjSpace]),
-    next       = interp2app(GeneratorIterator.descr_next),
-    __iter__   = interp2app(GeneratorIterator.descr__iter__),
+    next       = interp2app(GeneratorIterator.descr_next,
+                            descrmismatch='next'),
+    __iter__   = interp2app(GeneratorIterator.descr__iter__,
+                            descrmismatch='__iter__'),
     gi_running = interp_attrproperty('running', cls=GeneratorIterator),
     gi_frame   = interp_attrproperty('frame', cls=GeneratorIterator),
     __weakref__ = make_weakref_descr(GeneratorIterator),

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/proxyobject.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/proxyobject.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/proxyobject.py	Sat Nov  4 18:49:49 2006
@@ -78,18 +78,20 @@
 from pypy.objspace.std.objecttype import object_typedef
 W_TransparentObject.typedef = object_typedef
 
+from pypy.interpreter.typedef import Function, GeneratorIterator, PyTraceback, PyFrame
+
 class W_TransparentFunction(W_Transparent):
-    from pypy.interpreter.function import Function
     typedef = Function.typedef
 
 class W_TransparentTraceback(W_Transparent):
-    from pypy.interpreter.pytraceback import PyTraceback
     typedef = PyTraceback.typedef
 
 class W_TransparentFrame(W_Transparent):
-    from pypy.interpreter.pyframe import PyFrame
     typedef = PyFrame.typedef
 
+class W_TransparentGenerator(W_Transparent):
+    typedef = GeneratorIterator.typedef
+
 class W_TransparentList(W_TransparentObject):
     from pypy.objspace.std.listobject import W_ListObject as original
     from pypy.objspace.std.listtype import list_typedef as typedef

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_internals.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_internals.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_internals.py	Sat Nov  4 18:49:49 2006
@@ -2,7 +2,7 @@
 """ test proxy internals like code, traceback, frame
 """
 
-class AppTestProxyInternals(object):
+class AppProxy(object):
     def setup_method(self, meth):
         self.w_get_proxy = self.space.appexec([], """():
         class Controller(object):
@@ -16,6 +16,7 @@
         return get_proxy
         """)
 
+class AppTestProxyInternals(AppProxy):
     def test_traceback_basic(self):
         try:
             1/0

Added: pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_iter.py
==============================================================================
--- (empty file)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_iter.py	Sat Nov  4 18:49:49 2006
@@ -0,0 +1,17 @@
+
+""" test of iterators
+"""
+
+from pypy.objspace.std.test.test_proxy_internals import AppProxy
+
+class AppTestProxyIter(AppProxy):
+    def test_generator(self):
+        def some(l):
+            for i in l:
+                yield i
+        
+        g = self.get_proxy(some([1,2,3]))
+        assert list(g) == [1,2,3]
+        g = self.get_proxy(some([1,2,3]))
+        assert g.next() == 1
+        assert g.next() == 2

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py	Sat Nov  4 18:49:49 2006
@@ -9,7 +9,7 @@
 from pypy.objspace.std.typeobject import W_TypeObject
 
 def proxy(space, w_type, w_controller):
-    from pypy.interpreter.typedef import Function, PyTraceback, PyFrame
+    from pypy.interpreter.typedef import Function, PyTraceback, PyFrame, GeneratorIterator
     
     if not space.is_true(space.callable(w_controller)):
         raise OperationError(space.w_TypeError, space.wrap("controller should be function"))
@@ -25,6 +25,8 @@
             return W_TransparentTraceback(space, w_type, w_controller)
         if space.is_true(space.issubtype(w_type, space.gettypeobject(PyFrame.typedef))):
             return W_TransparentFrame(space, w_type, w_controller)
+        if space.is_true(space.issubtype(w_type, space.gettypeobject(GeneratorIterator.typedef))):
+            return W_TransparentGenerator(space, w_type, w_controller)
         if w_type.instancetypedef is space.w_object.instancetypedef:
             return W_Transparent(space, w_type, w_controller)
     else:



More information about the Pypy-commit mailing list