cpython: 536fccc75f5a (original) (raw)

Mercurial > cpython

changeset 71543:536fccc75f5a

Issue #12380: PyArg_ParseTuple now accepts a bytearray for the 'c' format. As a side effect, this now allows the rjust, ljust and center methods of bytes and bytearray to accept a bytearray argument. Patch by Petri Lehtinen [#12380]

Eli Bendersky eliben@gmail.com
date Fri, 29 Jul 2011 07:05:08 +0300
parents ccce01988603
children 80a3bf889cf6
files Doc/c-api/arg.rst Lib/test/test_bytes.py Lib/test/test_getargs2.py Misc/NEWS Modules/_testcapimodule.c Python/getargs.c
diffstat 6 files changed, 53 insertions(+), 4 deletions(-)[+] [-] Doc/c-api/arg.rst 8 Lib/test/test_bytes.py 21 Lib/test/test_getargs2.py 9 Misc/NEWS 7 Modules/_testcapimodule.c 10 Python/getargs.c 2

line wrap: on

line diff

--- a/Doc/c-api/arg.rst +++ b/Doc/c-api/arg.rst @@ -260,9 +260,11 @@ Numbers n (:class:int) [Py_ssize_t] Convert a Python integer to a C :c:type:Py_ssize_t. -c (:class:bytes of length 1) [char]

C (:class:str of length 1) [int] Convert a Python character, represented as a :class:str object of

--- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -475,6 +475,27 @@ class BaseBytesTest(unittest.TestCase): self.assertRaises(TypeError, self.type2test(b'abc').lstrip, 'b') self.assertRaises(TypeError, self.type2test(b'abc').rstrip, 'b')

+

+

+ def test_ord(self): b = self.type2test(b'\0A\x7f\x80\xff') self.assertEqual([ord(b[i:i+1]) for i in range(len(b))],

--- a/Lib/test/test_getargs2.py +++ b/Lib/test/test_getargs2.py @@ -294,6 +294,15 @@ class Keywords_TestCase(unittest.TestCas self.fail('TypeError should have been raised') class Bytes_TestCase(unittest.TestCase):

+ def test_s(self): from _testcapi import getargs_s self.assertEqual(getargs_s('abc\xe9'), b'abc\xc3\xa9')

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -238,6 +238,9 @@ Core and Builtins

--- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -1003,6 +1003,15 @@ test_k_code(PyObject *self) } static PyObject * +getargs_c(PyObject *self, PyObject *args) +{

+} + +static PyObject * getargs_s(PyObject *self, PyObject *args) { char *str; @@ -2289,6 +2298,7 @@ static PyMethodDef TestMethods[] = { (PyCFunction)test_long_long_and_overflow, METH_NOARGS}, {"test_L_code", (PyCFunction)test_L_code, METH_NOARGS}, #endif

--- a/Python/getargs.c +++ b/Python/getargs.c @@ -828,6 +828,8 @@ convertsimple(PyObject *arg, const char char *p = va_arg(*p_va, char *); if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1) *p = PyBytes_AS_STRING(arg)[0];