mirror of https://github.com/python/cpython
Merged revisions 80123-80124,80126 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80123 | benjamin.peterson | 2010-04-16 17:24:16 -0500 (Fri, 16 Apr 2010) | 1 line bytearray -> type2test ........ r80124 | benjamin.peterson | 2010-04-16 17:25:57 -0500 (Fri, 16 Apr 2010) | 1 line fix typo ........ r80126 | benjamin.peterson | 2010-04-16 17:35:38 -0500 (Fri, 16 Apr 2010) | 1 line have a clear error when passing something > sys.maxsize to bytearray ........
This commit is contained in:
parent
58a7f75d05
commit
c218ce86c4
|
@ -62,17 +62,18 @@ class BaseBytesTest(unittest.TestCase):
|
||||||
b = self.type2test([Indexable(), Indexable(1), Indexable(254),
|
b = self.type2test([Indexable(), Indexable(1), Indexable(254),
|
||||||
Indexable(255)])
|
Indexable(255)])
|
||||||
self.assertEqual(list(b), [0, 1, 254, 255])
|
self.assertEqual(list(b), [0, 1, 254, 255])
|
||||||
self.assertRaises(ValueError, bytearray, [Indexable(-1)])
|
self.assertRaises(ValueError, self.type2test, [Indexable(-1)])
|
||||||
self.assertRaises(ValueError, bytearray, [Indexable(256)])
|
self.assertRaises(ValueError, self.type2test, [Indexable(256)])
|
||||||
|
|
||||||
def test_from_ssize(self):
|
def test_from_ssize(self):
|
||||||
self.assertEqual(bytearray(0), b'')
|
self.assertEqual(self.type2test(0), b'')
|
||||||
self.assertEqual(bytearray(1), b'\x00')
|
self.assertEqual(self.type2test(1), b'\x00')
|
||||||
self.assertEqual(bytearray(5), b'\x00\x00\x00\x00\x00')
|
self.assertEqual(self.type2test(5), b'\x00\x00\x00\x00\x00')
|
||||||
self.assertRaises(ValueError, bytearray, -1)
|
self.assertRaises(ValueError, self.type2test, -1)
|
||||||
|
|
||||||
self.assertEqual(bytearray('0', 'ascii'), b'0')
|
self.assertEqual(self.type2test('0', 'ascii'), b'0')
|
||||||
self.assertEqual(bytearray(b'0'), b'0')
|
self.assertEqual(self.type2test(b'0'), b'0')
|
||||||
|
self.assertRaises(OverflowError, self.type2test, sys.maxsize + 1)
|
||||||
|
|
||||||
def test_constructor_type_errors(self):
|
def test_constructor_type_errors(self):
|
||||||
self.assertRaises(TypeError, self.type2test, 0.0)
|
self.assertRaises(TypeError, self.type2test, 0.0)
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 2.6.6 alpha 1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #8417: Raise an OverflowError when an integer larger than sys.maxsize is
|
||||||
|
passed to bytearray.
|
||||||
|
|
||||||
- Issue #8329: Don't return the same lists from select.select when no fds are
|
- Issue #8329: Don't return the same lists from select.select when no fds are
|
||||||
changed.
|
changed.
|
||||||
|
|
||||||
|
|
|
@ -830,14 +830,18 @@ bytes_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Is it an int? */
|
/* Is it an int? */
|
||||||
count = PyNumber_AsSsize_t(arg, PyExc_ValueError);
|
count = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
|
||||||
if (count == -1 && PyErr_Occurred())
|
if (count == -1 && PyErr_Occurred()) {
|
||||||
|
if (PyErr_ExceptionMatches(PyExc_OverflowError))
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
else {
|
}
|
||||||
if (count < 0) {
|
else if (count < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError, "negative count");
|
PyErr_SetString(PyExc_ValueError, "negative count");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if (PyByteArray_Resize((PyObject *)self, count))
|
if (PyByteArray_Resize((PyObject *)self, count))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue