summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin Blais <blais@furius.ca>2006-06-04 13:49:49 (GMT)
committerMartin Blais <blais@furius.ca>2006-06-04 13:49:49 (GMT)
commitaf2ae72cb20e853091faad0dd11d51e97539881d (patch)
tree218d426ffb6408a97dcf7ff2055cc4b28476b1b5 /Lib
parent63f0db682e00d051466e5d739ba85f2a30279eef (diff)
downloadcpython-af2ae72cb20e853091faad0dd11d51e97539881d.zip
cpython-af2ae72cb20e853091faad0dd11d51e97539881d.tar.gz
cpython-af2ae72cb20e853091faad0dd11d51e97539881d.tar.bz2
Fixes in struct and socket from merge reviews.
- Following Guido's comments, renamed * pack_to -> pack_into * recv_buf -> recv_into * recvfrom_buf -> recvfrom_into - Made fixes to _struct.c according to Neal Norwitz comments on the checkins list. - Converted some ints into the appropriate -- I hope -- ssize_t and size_t.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/socket.py6
-rw-r--r--Lib/struct.py4
-rw-r--r--Lib/test/test_socket.py12
-rw-r--r--Lib/test/test_struct.py26
4 files changed, 24 insertions, 24 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index cc5e65e..fa0e663 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -141,7 +141,7 @@ class _socketobject(object):
__doc__ = _realsocket.__doc__
__slots__ = ["_sock",
- "recv", "recv_buf", "recvfrom_buf",
+ "recv", "recv_into", "recvfrom_into",
"send", "sendto", "recvfrom",
"__weakref__"]
@@ -151,10 +151,10 @@ class _socketobject(object):
self._sock = _sock
self.send = self._sock.send
self.recv = self._sock.recv
- self.recv_buf = self._sock.recv_buf
+ self.recv_into = self._sock.recv_into
self.sendto = self._sock.sendto
self.recvfrom = self._sock.recvfrom
- self.recvfrom_buf = self._sock.recvfrom_buf
+ self.recvfrom_into = self._sock.recvfrom_into
def close(self):
self._sock = _closedsocket()
diff --git a/Lib/struct.py b/Lib/struct.py
index 51ee29a..9113e71 100644
--- a/Lib/struct.py
+++ b/Lib/struct.py
@@ -62,7 +62,7 @@ def pack(fmt, *args):
o = _compile(fmt)
return o.pack(*args)
-def pack_to(fmt, buf, offset, *args):
+def pack_into(fmt, buf, offset, *args):
"""
Pack the values v2, v2, ... according to fmt, write
the packed bytes into the writable buffer buf starting at offset.
@@ -72,7 +72,7 @@ def pack_to(fmt, buf, offset, *args):
o = _cache[fmt]
except KeyError:
o = _compile(fmt)
- return o.pack_to(buf, offset, *args)
+ return o.pack_into(buf, offset, *args)
def unpack(fmt, s):
"""
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 2246fb6..01b9b5b 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -860,25 +860,25 @@ class BufferIOTest(SocketConnectedTest):
def __init__(self, methodName='runTest'):
SocketConnectedTest.__init__(self, methodName=methodName)
- def testRecvBuf(self):
+ def testRecvInto(self):
buf = array.array('c', ' '*1024)
- nbytes = self.cli_conn.recv_buf(buf)
+ nbytes = self.cli_conn.recv_into(buf)
self.assertEqual(nbytes, len(MSG))
msg = buf.tostring()[:len(MSG)]
self.assertEqual(msg, MSG)
- def _testRecvBuf(self):
+ def _testRecvInto(self):
buf = buffer(MSG)
self.serv_conn.send(buf)
- def testRecvFromBuf(self):
+ def testRecvFromInto(self):
buf = array.array('c', ' '*1024)
- nbytes, addr = self.cli_conn.recvfrom_buf(buf)
+ nbytes, addr = self.cli_conn.recvfrom_into(buf)
self.assertEqual(nbytes, len(MSG))
msg = buf.tostring()[:len(MSG)]
self.assertEqual(msg, MSG)
- def _testRecvFromBuf(self):
+ def _testRecvFromInto(self):
buf = buffer(MSG)
self.serv_conn.send(buf)
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 28759fb..33fa0b9 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -529,50 +529,50 @@ def test_unpack_from():
for i in xrange(6, len(test_string) + 1):
simple_err(struct.unpack_from, fmt, data, i)
-def test_pack_to():
+def test_pack_into():
test_string = 'Reykjavik rocks, eow!'
writable_buf = array.array('c', ' '*100)
fmt = '21s'
s = struct.Struct(fmt)
# Test without offset
- s.pack_to(writable_buf, 0, test_string)
+ s.pack_into(writable_buf, 0, test_string)
from_buf = writable_buf.tostring()[:len(test_string)]
assert from_buf == test_string
# Test with offset.
- s.pack_to(writable_buf, 10, test_string)
+ s.pack_into(writable_buf, 10, test_string)
from_buf = writable_buf.tostring()[:len(test_string)+10]
assert from_buf == (test_string[:10] + test_string)
# Go beyond boundaries.
small_buf = array.array('c', ' '*10)
- assertRaises(struct.error, s.pack_to, small_buf, 0, test_string)
- assertRaises(struct.error, s.pack_to, small_buf, 2, test_string)
+ assertRaises(struct.error, s.pack_into, small_buf, 0, test_string)
+ assertRaises(struct.error, s.pack_into, small_buf, 2, test_string)
-def test_pack_to_fn():
+def test_pack_into_fn():
test_string = 'Reykjavik rocks, eow!'
writable_buf = array.array('c', ' '*100)
fmt = '21s'
- pack_to = lambda *args: struct.pack_to(fmt, *args)
+ pack_into = lambda *args: struct.pack_into(fmt, *args)
# Test without offset
- pack_to(writable_buf, 0, test_string)
+ pack_into(writable_buf, 0, test_string)
from_buf = writable_buf.tostring()[:len(test_string)]
assert from_buf == test_string
# Test with offset.
- pack_to(writable_buf, 10, test_string)
+ pack_into(writable_buf, 10, test_string)
from_buf = writable_buf.tostring()[:len(test_string)+10]
assert from_buf == (test_string[:10] + test_string)
# Go beyond boundaries.
small_buf = array.array('c', ' '*10)
- assertRaises(struct.error, pack_to, small_buf, 0, test_string)
- assertRaises(struct.error, pack_to, small_buf, 2, test_string)
+ assertRaises(struct.error, pack_into, small_buf, 0, test_string)
+ assertRaises(struct.error, pack_into, small_buf, 2, test_string)
# Test methods to pack and unpack from buffers rather than strings.
test_unpack_from()
-test_pack_to()
-test_pack_to_fn()
+test_pack_into()
+test_pack_into_fn()