Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 50 additions & 48 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,7 @@ bytearray_take_bytes_impl(PyByteArrayObject *self, PyObject *n)


/*[clinic input]
@permit_long_summary
@critical_section
bytearray.translate

Expand All @@ -1630,14 +1631,15 @@ bytearray.translate

Return a copy with each character mapped by the given translation table.

All characters occurring in the optional argument delete are removed.
The remaining characters are mapped through the given translation table.
All characters occurring in the optional argument delete are
removed. The remaining characters are mapped through the given
translation table.
[clinic start generated code]*/

static PyObject *
bytearray_translate_impl(PyByteArrayObject *self, PyObject *table,
PyObject *deletechars)
/*[clinic end generated code: output=b6a8f01c2a74e446 input=cd6fa93ca04e05bc]*/
/*[clinic end generated code: output=b6a8f01c2a74e446 input=e30d2ae004365ed9]*/
{
char *input, *output;
const char *table_chars;
Expand Down Expand Up @@ -1727,7 +1729,6 @@ bytearray_translate_impl(PyByteArrayObject *self, PyObject *table,
/*[clinic input]

@permit_long_summary
@permit_long_docstring_body
@staticmethod
bytearray.maketrans

Expand All @@ -1737,15 +1738,15 @@ bytearray.maketrans

Return a translation table usable for the bytes or bytearray translate method.

The returned table will be one where each byte in frm is mapped to the byte at
the same position in to.
The returned table will be one where each byte in frm is mapped to
the byte at the same position in to.

The bytes objects frm and to must be of the same length.
[clinic start generated code]*/

static PyObject *
bytearray_maketrans_impl(Py_buffer *frm, Py_buffer *to)
/*[clinic end generated code: output=1df267d99f56b15e input=1146b43a592eca13]*/
/*[clinic end generated code: output=1df267d99f56b15e input=c2f5f6e7e6b0221d]*/
{
return _Py_bytes_maketrans(frm, to);
}
Expand Down Expand Up @@ -1785,8 +1786,8 @@ bytearray.split

sep: object = None
The delimiter according which to split the bytearray.
None (the default value) means split on ASCII whitespace characters
(space, tab, return, newline, formfeed, vertical tab).
None (the default value) means split on ASCII whitespace
characters (space, tab, return, newline, formfeed, vertical tab).
maxsplit: Py_ssize_t = -1
Maximum number of splits to do.
-1 (the default value) means no limit.
Expand All @@ -1797,7 +1798,7 @@ Return a list of the sections in the bytearray, using sep as the delimiter.
static PyObject *
bytearray_split_impl(PyByteArrayObject *self, PyObject *sep,
Py_ssize_t maxsplit)
/*[clinic end generated code: output=833e2cf385d9a04d input=dd9f6e2910cc3a34]*/
/*[clinic end generated code: output=833e2cf385d9a04d input=45605178023b52ac]*/
{
PyObject *list = NULL;

Expand Down Expand Up @@ -1829,7 +1830,6 @@ bytearray_split_impl(PyByteArrayObject *self, PyObject *sep,
}

/*[clinic input]
@permit_long_docstring_body
@critical_section
bytearray.partition

Expand All @@ -1838,17 +1838,18 @@ bytearray.partition

Partition the bytearray into three parts using the given separator.

This will search for the separator sep in the bytearray. If the separator is
found, returns a 3-tuple containing the part before the separator, the
separator itself, and the part after it as new bytearray objects.
This will search for the separator sep in the bytearray. If the
separator is found, returns a 3-tuple containing the part before the
separator, the separator itself, and the part after it as new
bytearray objects.

If the separator is not found, returns a 3-tuple containing the copy of the
original bytearray object and two empty bytearray objects.
If the separator is not found, returns a 3-tuple containing the copy
of the original bytearray object and two empty bytearray objects.
[clinic start generated code]*/

static PyObject *
bytearray_partition_impl(PyByteArrayObject *self, PyObject *sep)
/*[clinic end generated code: output=b5fa1e03f10cfccb input=b87276af883f39d9]*/
/*[clinic end generated code: output=b5fa1e03f10cfccb input=d76673ed03acf5dd]*/
{
PyObject *bytesep, *result;

Expand All @@ -1868,7 +1869,6 @@ bytearray_partition_impl(PyByteArrayObject *self, PyObject *sep)
}

/*[clinic input]
@permit_long_docstring_body
@critical_section
bytearray.rpartition

Expand All @@ -1877,18 +1877,19 @@ bytearray.rpartition

Partition the bytearray into three parts using the given separator.

This will search for the separator sep in the bytearray, starting at the end.
If the separator is found, returns a 3-tuple containing the part before the
separator, the separator itself, and the part after it as new bytearray
objects.
This will search for the separator sep in the bytearray, starting at
the end. If the separator is found, returns a 3-tuple containing
the part before the separator, the separator itself, and the part
after it as new bytearray objects.

If the separator is not found, returns a 3-tuple containing two empty bytearray
objects and the copy of the original bytearray object.
If the separator is not found, returns a 3-tuple containing two
empty bytearray objects and the copy of the original bytearray
object.
[clinic start generated code]*/

static PyObject *
bytearray_rpartition_impl(PyByteArrayObject *self, PyObject *sep)
/*[clinic end generated code: output=0186ce7b1ef61289 input=5bdcfc4c333bcfab]*/
/*[clinic end generated code: output=0186ce7b1ef61289 input=b9216a2074174a36]*/
{
PyObject *bytesep, *result;

Expand All @@ -1909,19 +1910,19 @@ bytearray_rpartition_impl(PyByteArrayObject *self, PyObject *sep)

/*[clinic input]
@permit_long_summary
@permit_long_docstring_body
@critical_section
bytearray.rsplit = bytearray.split

Return a list of the sections in the bytearray, using sep as the delimiter.

Splitting is done starting at the end of the bytearray and working to the front.
Splitting is done starting at the end of the bytearray and working
to the front.
[clinic start generated code]*/

static PyObject *
bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep,
Py_ssize_t maxsplit)
/*[clinic end generated code: output=a55e0b5a03cb6190 input=60e9abf305128ff4]*/
/*[clinic end generated code: output=a55e0b5a03cb6190 input=e201671c9a0c19ee]*/
{
PyObject *list = NULL;

Expand Down Expand Up @@ -2392,7 +2393,6 @@ bytearray_strip_impl_helper(PyByteArrayObject* self, PyObject* bytes, int stript
}

/*[clinic input]
@permit_long_docstring_body
@critical_section
bytearray.strip

Expand All @@ -2401,12 +2401,13 @@ bytearray.strip

Strip leading and trailing bytes contained in the argument.

If the argument is omitted or None, strip leading and trailing ASCII whitespace.
If the argument is omitted or None, strip leading and trailing ASCII
whitespace.
[clinic start generated code]*/

static PyObject *
bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes)
/*[clinic end generated code: output=760412661a34ad5a input=6acaf88b2ec9daa7]*/
/*[clinic end generated code: output=760412661a34ad5a input=f4ec5fa609df7d14]*/
{
return bytearray_strip_impl_helper(self, bytes, BOTHSTRIP);
}
Expand Down Expand Up @@ -2506,19 +2507,19 @@ bytearray.decode
encoding: str(c_default="NULL") = 'utf-8'
The encoding with which to decode the bytearray.
errors: str(c_default="NULL") = 'strict'
The error handling scheme to use for the handling of decoding errors.
The default is 'strict' meaning that decoding errors raise a
UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
as well as any other name registered with codecs.register_error that
can handle UnicodeDecodeErrors.
The error handling scheme to use for the handling of decoding
errors. The default is 'strict' meaning that decoding errors
raise a UnicodeDecodeError. Other possible values are 'ignore'
and 'replace' as well as any other name registered with
codecs.register_error that can handle UnicodeDecodeErrors.

Decode the bytearray using the codec registered for encoding.
[clinic start generated code]*/

static PyObject *
bytearray_decode_impl(PyByteArrayObject *self, const char *encoding,
const char *errors)
/*[clinic end generated code: output=f57d43f4a00b42c5 input=86c303ee376b8453]*/
/*[clinic end generated code: output=f57d43f4a00b42c5 input=e51ce9b82b51e2ca]*/
{
if (encoding == NULL)
encoding = PyUnicode_GetDefaultEncoding();
Expand Down Expand Up @@ -2550,14 +2551,15 @@ bytearray.join

Concatenate any number of bytes/bytearray objects.

The bytearray whose method is called is inserted in between each pair.
The bytearray whose method is called is inserted in between each
pair.

The result is returned as a new bytearray object.
[clinic start generated code]*/

static PyObject *
bytearray_join_impl(PyByteArrayObject *self, PyObject *iterable_of_bytes)
/*[clinic end generated code: output=0ced382b5846a7ee input=49627e07ca31ca26]*/
/*[clinic end generated code: output=0ced382b5846a7ee input=0a31db349efcd7fa]*/
{
PyObject *ret;
self->ob_exports++; // this protects `self` from being cleared/resized if `iterable_of_bytes` is a custom iterator
Expand Down Expand Up @@ -2588,21 +2590,20 @@ bytearray_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)

/*[clinic input]
@permit_long_summary
@permit_long_docstring_body
@critical_section
bytearray.splitlines

keepends: bool = False

Return a list of the lines in the bytearray, breaking at line boundaries.

Line breaks are not included in the resulting list unless keepends is given and
true.
Line breaks are not included in the resulting list unless keepends
is given and true.
[clinic start generated code]*/

static PyObject *
bytearray_splitlines_impl(PyByteArrayObject *self, int keepends)
/*[clinic end generated code: output=4223c94b895f6ad9 input=21bc3f02bf1be832]*/
/*[clinic end generated code: output=4223c94b895f6ad9 input=cc2bb740eed19f27]*/
{
return stringlib_splitlines(
(PyObject*) self, PyByteArray_AS_STRING(self),
Expand All @@ -2620,12 +2621,13 @@ bytearray.fromhex
Create a bytearray object from a string of hexadecimal numbers.

Spaces between two numbers are accepted.
Example: bytearray.fromhex('B9 01EF') -> bytearray(b'\\xb9\\x01\\xef')
Example:
bytearray.fromhex('B9 01EF') -> bytearray(b'\\xb9\\x01\\xef')
[clinic start generated code]*/

static PyObject *
bytearray_fromhex_impl(PyTypeObject *type, PyObject *string)
/*[clinic end generated code: output=8f0f0b6d30fb3ba0 input=7e314e5b2d7ab484]*/
/*[clinic end generated code: output=8f0f0b6d30fb3ba0 input=2243a8b0b9e66cd5]*/
{
PyObject *result = _PyBytes_FromHex(string, type == &PyByteArray_Type);
if (type != &PyByteArray_Type && result != NULL) {
Expand All @@ -2641,8 +2643,8 @@ bytearray.hex
sep: object = NULL
An optional single character or byte to separate hex bytes.
bytes_per_sep: Py_ssize_t = 1
How many bytes between separators. Positive values count from the
right, negative values count from the left.
How many bytes between separators. Positive values count from
the right, negative values count from the left.

Create a string of hexadecimal numbers from a bytearray object.

Expand All @@ -2661,7 +2663,7 @@ Create a string of hexadecimal numbers from a bytearray object.
static PyObject *
bytearray_hex_impl(PyByteArrayObject *self, PyObject *sep,
Py_ssize_t bytes_per_sep)
/*[clinic end generated code: output=c9563921aff1262b input=d2b23ef057cfcad5]*/
/*[clinic end generated code: output=c9563921aff1262b input=9ed746203691e894]*/
{
char* argbuf = PyByteArray_AS_STRING(self);
Py_ssize_t arglen = PyByteArray_GET_SIZE(self);
Expand Down
4 changes: 2 additions & 2 deletions Objects/bytes_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ _Py_bytes_upper(char *result, const char *cptr, Py_ssize_t len)
PyDoc_STRVAR_shared(_Py_title__doc__,
"B.title() -> copy of B\n\
\n\
Return a titlecased version of B, i.e. ASCII words start with uppercase\n\
characters, all remaining cased characters have lowercase.");
Return a titlecased version of B, i.e. ASCII words start with\n\
uppercase characters, all remaining cased characters have lowercase.");

void
_Py_bytes_title(char *result, const char *s, Py_ssize_t len)
Expand Down
Loading
Loading