mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Breaking ground for PEP 3137 implementation:
Get rid of buffer(). Use memoryview() in its place where possible. In a few places, do things a bit different, because memoryview() can't slice (yet).
This commit is contained in:
parent
85c1ba5d74
commit
bae07c9baf
24 changed files with 72 additions and 199 deletions
|
@ -6,7 +6,7 @@ import re
|
|||
def dump(obj):
|
||||
# helper function to dump memory contents in hex, with a hyphen
|
||||
# between the bytes.
|
||||
h = str(hexlify(buffer(obj)))
|
||||
h = str(hexlify(memoryview(obj)))
|
||||
return re.sub(r"(..)", r"\1-", h)[:-1]
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from binascii import hexlify
|
|||
from ctypes import *
|
||||
|
||||
def bin(s):
|
||||
return str(hexlify(buffer(s))).upper()
|
||||
return str(hexlify(memoryview(s))).upper()
|
||||
|
||||
# Each *simple* type that supports different byte orders has an
|
||||
# __ctype_be__ attribute that specifies the same type in BIG ENDIAN
|
||||
|
|
|
@ -30,17 +30,17 @@ class StringArrayTestCase(unittest.TestCase):
|
|||
buf.value = "Hello, World"
|
||||
self.failUnlessEqual(buf.value, "Hello, World")
|
||||
|
||||
self.failUnlessRaises(TypeError, setattr, buf, "value", buffer("Hello, World"))
|
||||
self.assertRaises(TypeError, setattr, buf, "value", buffer("abc"))
|
||||
self.assertRaises(ValueError, setattr, buf, "raw", buffer("x" * 100))
|
||||
self.failUnlessRaises(TypeError, setattr, buf, "value", memoryview(b"Hello, World"))
|
||||
self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"abc"))
|
||||
self.assertRaises(ValueError, setattr, buf, "raw", memoryview(b"x" * 100))
|
||||
|
||||
def test_c_buffer_raw(self):
|
||||
buf = c_buffer(32)
|
||||
|
||||
buf.raw = buffer(b"Hello, World")
|
||||
buf.raw = memoryview(b"Hello, World")
|
||||
self.failUnlessEqual(buf.value, "Hello, World")
|
||||
self.assertRaises(TypeError, setattr, buf, "value", buffer("abc"))
|
||||
self.assertRaises(ValueError, setattr, buf, "raw", buffer("x" * 100))
|
||||
self.assertRaises(TypeError, setattr, buf, "value", memoryview(b"abc"))
|
||||
self.assertRaises(ValueError, setattr, buf, "raw", memoryview(b"x" * 100))
|
||||
|
||||
def test_param_1(self):
|
||||
BUF = c_char * 4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue