Author: Brian Kearns <bdkea...@gmail.com>
Branch: 
Changeset: r70072:66fcaf1343c6
Date: 2014-03-18 20:41 -0400
http://bitbucket.org/pypy/pypy/changeset/66fcaf1343c6/

Log:    fix buffer_w on objects defining pypy's app-level buffer interface

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -195,6 +195,11 @@
         return None
 
     def buffer_w(self, space):
+        w_impl = space.lookup(self, '__buffer__')
+        if w_impl is not None:
+            w_result = space.get_and_call_function(w_impl, self)
+            if space.isinstance_w(w_result, space.w_buffer):
+                return w_result.buffer_w(space)
         self._typed_unwrap_error(space, "buffer")
 
     def str_w(self, space):
diff --git a/pypy/objspace/std/test/test_memoryview.py 
b/pypy/objspace/std/test/test_memoryview.py
--- a/pypy/objspace/std/test/test_memoryview.py
+++ b/pypy/objspace/std/test/test_memoryview.py
@@ -2,10 +2,14 @@
     spaceconfig = dict(usemodules=['array'])
 
     def test_init(self):
+        import sys
         class A(object):
             def __buffer__(self):
                 return buffer('123')
-        raises(TypeError, buffer, A())
+        if '__pypy__' not in sys.builtin_module_names:
+            raises(TypeError, buffer, A())
+        else:
+            assert buffer(A()) == buffer('123')
 
     def test_unicode_buffer(self):
         import sys
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to