Author: Brian Kearns <[email protected]>
Branch:
Changeset: r70063:922c7ee9e9d2
Date: 2014-03-18 17:15 -0400
http://bitbucket.org/pypy/pypy/changeset/922c7ee9e9d2/
Log: more buffer cleanups
diff --git a/lib-python/2.7/test/test_memoryview.py
b/lib-python/2.7/test/test_memoryview.py
--- a/lib-python/2.7/test/test_memoryview.py
+++ b/lib-python/2.7/test/test_memoryview.py
@@ -171,7 +171,7 @@
# very inconsisten on CPython. In PyPy, memoryview supports
# the buffer interface, and thus the following comparison
# succeeds. See also the comment in
- #
pypy.modules.__builtin__.interp_memoryview.W_MemoryView.descr_buffer
+ # pypy.objspace.std.memoryview.W_MemoryView.descr_buffer
#
# Comparison with objects which don't support the buffer API
self.assertFalse(m == u"abcdef", "%s %s" % (self, tp))
diff --git a/pypy/interpreter/test/test_buffer.py
b/pypy/interpreter/test/test_buffer.py
--- a/pypy/interpreter/test/test_buffer.py
+++ b/pypy/interpreter/test/test_buffer.py
@@ -1,12 +1,10 @@
import py
-from pypy.module.__builtin__.interp_memoryview import W_Buffer
from rpython.tool.udir import udir
testdir = udir.ensure('test_buffer', dir=1)
class TestBuffer:
-
def test_buffer_w(self):
space = self.space
w_hello = space.wrap('hello world')
@@ -14,14 +12,14 @@
assert buf.getlength() == 11
assert buf.as_str() == 'hello world'
assert buf.getslice(1, 6, 1, 5) == 'ello '
- assert space.buffer_w(W_Buffer(buf)) is buf
+ assert space.buffer_w(space.newbuffer(buf)) is buf
assert space.bufferstr_w(w_hello) == 'hello world'
- assert space.bufferstr_w(W_Buffer(space.buffer_w(w_hello))) == 'hello
world'
+ assert space.bufferstr_w(space.newbuffer(space.buffer_w(w_hello))) ==
'hello world'
space.raises_w(space.w_TypeError, space.buffer_w, space.wrap(5))
def test_file_write(self):
space = self.space
- w_buffer = W_Buffer(space.buffer_w(space.wrap('hello world')))
+ w_buffer = space.newbuffer(space.buffer_w(space.wrap('hello world')))
filename = str(testdir.join('test_file_write'))
space.appexec([w_buffer, space.wrap(filename)], """(buffer, filename):
f = open(filename, 'wb')
@@ -42,4 +40,4 @@
space.bufferstr_w, space.wrap(u'\xe9'))
-# Note: some app-level tests for buffer are in module/__builtin__/test/.
+# Note: some app-level tests for buffer are in
objspace/std/test/test_memoryview.py.
diff --git a/pypy/module/__builtin__/__init__.py
b/pypy/module/__builtin__/__init__.py
--- a/pypy/module/__builtin__/__init__.py
+++ b/pypy/module/__builtin__/__init__.py
@@ -33,16 +33,11 @@
interpleveldefs = {
# constants
+ '__debug__' : '(space.w_True)', # XXX
'None' : '(space.w_None)',
'False' : '(space.w_False)',
'True' : '(space.w_True)',
- '__debug__' : '(space.w_True)', # XXX
- 'type' : '(space.w_type)',
- 'object' : '(space.w_object)',
'bytes' : '(space.w_str)',
- 'unicode' : '(space.w_unicode)',
- 'buffer' : 'interp_memoryview.W_Buffer',
- 'memoryview' : 'interp_memoryview.W_MemoryView',
'file' : 'state.get(space).w_file',
'open' : 'state.get(space).w_file',
diff --git a/pypy/module/__builtin__/test/test_builtin.py
b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -24,6 +24,17 @@
else:
cls.w_safe_runtimerror = cls.space.wrap(sys.version_info < (2, 6))
+ def test_builtin_names(self):
+ import __builtin__
+ assert __builtin__.None is None
+ assert __builtin__.False is False
+ assert __builtin__.True is True
+
+ assert __builtin__.buffer is buffer
+ assert __builtin__.bytes is str
+ assert __builtin__.dict is dict
+ assert __builtin__.memoryview is memoryview
+
def test_bytes_alias(self):
assert bytes is str
assert isinstance(eval("b'hi'"), str)
diff --git a/pypy/module/__pypy__/bytebuffer.py
b/pypy/module/__pypy__/bytebuffer.py
--- a/pypy/module/__pypy__/bytebuffer.py
+++ b/pypy/module/__pypy__/bytebuffer.py
@@ -4,11 +4,9 @@
from pypy.interpreter.buffer import RWBuffer
from pypy.interpreter.gateway import unwrap_spec
-from pypy.module.__builtin__.interp_memoryview import W_Buffer
class ByteBuffer(RWBuffer):
-
def __init__(self, len):
self.data = ['\x00'] * len
@@ -24,4 +22,4 @@
@unwrap_spec(length=int)
def bytebuffer(space, length):
- return W_Buffer(ByteBuffer(length))
+ return space.newbuffer(ByteBuffer(length))
diff --git a/pypy/module/_cffi_backend/cbuffer.py
b/pypy/module/_cffi_backend/cbuffer.py
--- a/pypy/module/_cffi_backend/cbuffer.py
+++ b/pypy/module/_cffi_backend/cbuffer.py
@@ -4,7 +4,7 @@
from pypy.interpreter.gateway import unwrap_spec, interp2app
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
from pypy.module._cffi_backend import cdataobj, ctypeptr, ctypearray
-from pypy.module.__builtin__.interp_memoryview import W_Buffer
+from pypy.objspace.std.memoryview import W_Buffer
from rpython.rtyper.annlowlevel import llstr
from rpython.rtyper.lltypesystem import rffi
diff --git a/pypy/module/_io/interp_bufferedio.py
b/pypy/module/_io/interp_bufferedio.py
--- a/pypy/module/_io/interp_bufferedio.py
+++ b/pypy/module/_io/interp_bufferedio.py
@@ -5,7 +5,6 @@
TypeDef, GetSetProperty, generic_new_descr, interp_attrproperty_w)
from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
from pypy.interpreter.buffer import RWBuffer
-from pypy.module.__builtin__.interp_memoryview import W_Buffer
from rpython.rlib.rstring import StringBuilder
from rpython.rlib.rarithmetic import r_longlong, intmask
from rpython.rlib import rposix
@@ -512,7 +511,7 @@
def _raw_read(self, space, buffer, start, length):
length = intmask(length)
- w_buf = W_Buffer(RawBuffer(buffer, start, length))
+ w_buf = space.newbuffer(RawBuffer(buffer, start, length))
while True:
try:
w_size = space.call_method(self.w_raw, "readinto", w_buf)
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -22,10 +22,10 @@
from pypy.interpreter.nestedscope import Cell
from pypy.interpreter.module import Module
from pypy.interpreter.function import StaticMethod
+from pypy.objspace.std.memoryview import W_MemoryView
from pypy.objspace.std.sliceobject import W_SliceObject
from pypy.module.__builtin__.descriptor import W_Property
from pypy.module.__builtin__.interp_classobj import W_ClassObject
-from pypy.module.__builtin__.interp_memoryview import W_MemoryView
from pypy.module.micronumpy.base import W_NDimArray
from rpython.rlib.entrypoint import entrypoint_lowlevel
from rpython.rlib.rposix import is_valid_fd, validate_fd
diff --git a/pypy/module/cpyext/bufferobject.py
b/pypy/module/cpyext/bufferobject.py
--- a/pypy/module/cpyext/bufferobject.py
+++ b/pypy/module/cpyext/bufferobject.py
@@ -1,12 +1,12 @@
from rpython.rtyper.lltypesystem import rffi, lltype
+from pypy.interpreter.buffer import StringBuffer, SubBuffer
+from pypy.interpreter.error import OperationError
from pypy.module.cpyext.api import (
cpython_api, Py_ssize_t, cpython_struct, bootstrap_function,
PyObjectFields, PyObject)
from pypy.module.cpyext.pyobject import make_typedescr, Py_DecRef, make_ref
-from pypy.interpreter.buffer import StringBuffer, SubBuffer
-from pypy.interpreter.error import OperationError
-from pypy.module.__builtin__.interp_memoryview import W_Buffer
from pypy.module.array.interp_array import ArrayBuffer
+from pypy.objspace.std.memoryview import W_Buffer
PyBufferObjectStruct = lltype.ForwardReference()
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -14,7 +14,6 @@
from pypy.module.cpyext.pyobject import from_ref
from pypy.module.cpyext.pyerrors import PyErr_Occurred
from pypy.module.cpyext.state import State
-from pypy.module.__builtin__.interp_memoryview import W_Buffer
from pypy.interpreter.error import OperationError, oefmt
from pypy.interpreter.buffer import Buffer
from pypy.interpreter.argument import Arguments
@@ -250,7 +249,7 @@
size = generic_cpy_call(space, func_target, w_self, index, ptr)
if size < 0:
space.fromcache(State).check_and_raise_exception(always=True)
- return W_Buffer(CPyBuffer(ptr[0], size, w_self))
+ return space.newbuffer(CPyBuffer(ptr[0], size, w_self))
def get_richcmp_func(OP_CONST):
def inner(space, w_self, w_args, func):
diff --git a/pypy/module/micronumpy/ndarray.py
b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -7,7 +7,6 @@
from rpython.rlib.rawstorage import RAW_STORAGE_PTR
from rpython.rtyper.lltypesystem import rffi
from rpython.tool.sourcetools import func_with_new_name
-from pypy.module.__builtin__.interp_memoryview import W_Buffer
from pypy.module.micronumpy import descriptor, ufuncs, boxes, arrayops, loop, \
support, constants as NPY
from pypy.module.micronumpy.appbridge import get_appbridge_cache
@@ -607,7 +606,7 @@
return self.implementation.get_buffer(space)
def descr_get_data(self, space):
- return W_Buffer(self.buffer_w(space))
+ return space.newbuffer(self.buffer_w(space))
@unwrap_spec(offset=int, axis1=int, axis2=int)
def descr_diagonal(self, space, offset=0, axis1=0, axis2=1):
diff --git a/pypy/module/__builtin__/interp_memoryview.py
b/pypy/objspace/std/memoryview.py
rename from pypy/module/__builtin__/interp_memoryview.py
rename to pypy/objspace/std/memoryview.py
--- a/pypy/module/__builtin__/interp_memoryview.py
+++ b/pypy/objspace/std/memoryview.py
@@ -37,6 +37,7 @@
"""
def __init__(self, buf):
+ assert isinstance(buf, buffer.Buffer)
self.buf = buf
def buffer_w(self, space):
@@ -171,6 +172,7 @@
"""
def __init__(self, buf):
+ assert isinstance(buf, buffer.Buffer)
self.buf = buf
def buffer_w(self, space):
diff --git a/pypy/objspace/std/model.py b/pypy/objspace/std/model.py
--- a/pypy/objspace/std/model.py
+++ b/pypy/objspace/std/model.py
@@ -63,7 +63,7 @@
from pypy.objspace.std import unicodeobject
from pypy.objspace.std import dictproxyobject
from pypy.objspace.std import proxyobject
- from pypy.module.__builtin__.interp_memoryview import W_Buffer
+ from pypy.objspace.std.memoryview import W_Buffer, W_MemoryView
import pypy.objspace.std.default # register a few catch-all
multimethods
import pypy.objspace.std.marshal_impl # install marshal multimethods
@@ -84,6 +84,7 @@
self.pythontypes.append(boolobject.W_BoolObject.typedef)
self.pythontypes.append(longobject.W_LongObject.typedef)
self.pythontypes.append(W_Buffer.typedef)
+ self.pythontypes.append(W_MemoryView.typedef)
# the set of implementation types
self.typeorder = {
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
@@ -24,6 +24,7 @@
from pypy.objspace.std.iterobject import W_AbstractSeqIterObject
from pypy.objspace.std.listobject import W_ListObject
from pypy.objspace.std.longobject import W_LongObject, newlong
+from pypy.objspace.std.memoryview import W_Buffer
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.objectobject import W_ObjectObject
from pypy.objspace.std.iterobject import W_SeqIterObject
@@ -314,6 +315,9 @@
def newseqiter(self, w_obj):
return W_SeqIterObject(w_obj)
+ def newbuffer(self, w_obj):
+ return W_Buffer(w_obj)
+
def type(self, w_obj):
jit.promote(w_obj.__class__)
return w_obj.getclass(self)
diff --git a/pypy/module/__builtin__/test/test_buffer.py
b/pypy/objspace/std/test/test_memoryview.py
rename from pypy/module/__builtin__/test/test_buffer.py
rename to pypy/objspace/std/test/test_memoryview.py
--- a/pypy/module/__builtin__/test/test_buffer.py
+++ b/pypy/objspace/std/test/test_memoryview.py
@@ -1,6 +1,3 @@
-"""Tests some behaviour of the buffer type that is not tested in
-lib-python/2.5.2/test/test_types.py where the stdlib buffer tests live."""
-
class AppTestBuffer:
spaceconfig = dict(usemodules=['array'])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit