summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2011-03-03 18:21:02 (GMT)
committerEli Bendersky <eliben@gmail.com>2011-03-03 18:21:02 (GMT)
commit4db28d3343da7e48946a62036058fc6f0ee7cd71 (patch)
treef70ae2f75439eaf594b3877f5fd77a365e040caf /Objects/bytearrayobject.c
parent91221f2857961cfed3411e5c49cfa256d9c6a3f8 (diff)
downloadcpython-4db28d3343da7e48946a62036058fc6f0ee7cd71.zip
cpython-4db28d3343da7e48946a62036058fc6f0ee7cd71.tar.gz
cpython-4db28d3343da7e48946a62036058fc6f0ee7cd71.tar.bz2
Issue #10516: added copy() and clear() methods to bytearrays as well
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 9290d00..b419482 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1148,6 +1148,30 @@ bytearray_count(PyByteArrayObject *self, PyObject *args)
return count_obj;
}
+PyDoc_STRVAR(clear__doc__,
+"B.clear() -> None\n\
+\n\
+Remove all items from B.");
+
+static PyObject *
+bytearray_clear(PyByteArrayObject *self)
+{
+ if (PyByteArray_Resize((PyObject *)self, 0) < 0)
+ return NULL;
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(copy__doc__,
+"B.copy() -> bytearray\n\
+\n\
+Return a copy of B.");
+
+static PyObject *
+bytearray_copy(PyByteArrayObject *self)
+{
+ return PyByteArray_FromStringAndSize(PyByteArray_AS_STRING((PyObject *)self),
+ PyByteArray_GET_SIZE(self));
+}
PyDoc_STRVAR(index__doc__,
"B.index(sub[, start[, end]]) -> int\n\
@@ -2730,6 +2754,8 @@ bytearray_methods[] = {
{"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS,
_Py_capitalize__doc__},
{"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__},
+ {"clear", (PyCFunction)bytearray_clear, METH_NOARGS, clear__doc__},
+ {"copy", (PyCFunction)bytearray_copy, METH_NOARGS, copy__doc__},
{"count", (PyCFunction)bytearray_count, METH_VARARGS, count__doc__},
{"decode", (PyCFunction)bytearray_decode, METH_VARARGS | METH_KEYWORDS, decode_doc},
{"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS, endswith__doc__},