mirror of
https://github.com/python/cpython.git
synced 2025-09-16 13:47:31 +00:00
Issue #8930: fix some C code indentation
This commit is contained in:
parent
ae1bb9a00c
commit
619f16e194
3 changed files with 279 additions and 279 deletions
|
@ -176,28 +176,28 @@ static PyObject *
|
||||||
escape_encode(PyObject *self,
|
escape_encode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
char *buf;
|
char *buf;
|
||||||
Py_ssize_t consumed, len;
|
Py_ssize_t consumed, len;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "S|z:escape_encode",
|
if (!PyArg_ParseTuple(args, "S|z:escape_encode",
|
||||||
&str, &errors))
|
&str, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
consumed = PyString_GET_SIZE(str);
|
consumed = PyString_GET_SIZE(str);
|
||||||
str = PyString_Repr(str, 0);
|
str = PyString_Repr(str, 0);
|
||||||
if (!str)
|
if (!str)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* The string will be quoted. Unquote, similar to unicode-escape. */
|
/* The string will be quoted. Unquote, similar to unicode-escape. */
|
||||||
buf = PyString_AS_STRING (str);
|
buf = PyString_AS_STRING (str);
|
||||||
len = PyString_GET_SIZE (str);
|
len = PyString_GET_SIZE (str);
|
||||||
memmove(buf, buf+1, len-2);
|
memmove(buf, buf+1, len-2);
|
||||||
if (_PyString_Resize(&str, len-2) < 0)
|
if (_PyString_Resize(&str, len-2) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return codec_tuple(str, consumed);
|
return codec_tuple(str, consumed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
|
@ -233,7 +233,7 @@ static PyObject *
|
||||||
utf_7_decode(PyObject *self,
|
utf_7_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
Py_ssize_t consumed;
|
Py_ssize_t consumed;
|
||||||
|
@ -246,7 +246,7 @@ utf_7_decode(PyObject *self,
|
||||||
|
|
||||||
decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors,
|
decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
final ? NULL : &consumed);
|
final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (decoded == NULL)
|
if (decoded == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return codec_tuple(decoded, consumed);
|
return codec_tuple(decoded, consumed);
|
||||||
|
@ -256,7 +256,7 @@ static PyObject *
|
||||||
utf_8_decode(PyObject *self,
|
utf_8_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
Py_ssize_t consumed;
|
Py_ssize_t consumed;
|
||||||
|
@ -269,7 +269,7 @@ utf_8_decode(PyObject *self,
|
||||||
|
|
||||||
decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors,
|
decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
final ? NULL : &consumed);
|
final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (decoded == NULL)
|
if (decoded == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return codec_tuple(decoded, consumed);
|
return codec_tuple(decoded, consumed);
|
||||||
|
@ -279,7 +279,7 @@ static PyObject *
|
||||||
utf_16_decode(PyObject *self,
|
utf_16_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int byteorder = 0;
|
int byteorder = 0;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
|
@ -292,7 +292,7 @@ utf_16_decode(PyObject *self,
|
||||||
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
||||||
decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
|
decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
&byteorder, final ? NULL : &consumed);
|
&byteorder, final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (decoded == NULL)
|
if (decoded == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return codec_tuple(decoded, consumed);
|
return codec_tuple(decoded, consumed);
|
||||||
|
@ -302,7 +302,7 @@ static PyObject *
|
||||||
utf_16_le_decode(PyObject *self,
|
utf_16_le_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int byteorder = -1;
|
int byteorder = -1;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
|
@ -316,7 +316,7 @@ utf_16_le_decode(PyObject *self,
|
||||||
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
||||||
decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
|
decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
&byteorder, final ? NULL : &consumed);
|
&byteorder, final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (decoded == NULL)
|
if (decoded == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return codec_tuple(decoded, consumed);
|
return codec_tuple(decoded, consumed);
|
||||||
|
@ -326,7 +326,7 @@ static PyObject *
|
||||||
utf_16_be_decode(PyObject *self,
|
utf_16_be_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int byteorder = 1;
|
int byteorder = 1;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
|
@ -340,7 +340,7 @@ utf_16_be_decode(PyObject *self,
|
||||||
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
||||||
decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
|
decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
&byteorder, final ? NULL : &consumed);
|
&byteorder, final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (decoded == NULL)
|
if (decoded == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return codec_tuple(decoded, consumed);
|
return codec_tuple(decoded, consumed);
|
||||||
|
@ -358,7 +358,7 @@ static PyObject *
|
||||||
utf_16_ex_decode(PyObject *self,
|
utf_16_ex_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int byteorder = 0;
|
int byteorder = 0;
|
||||||
PyObject *unicode, *tuple;
|
PyObject *unicode, *tuple;
|
||||||
|
@ -371,7 +371,7 @@ utf_16_ex_decode(PyObject *self,
|
||||||
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
||||||
unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
|
unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
&byteorder, final ? NULL : &consumed);
|
&byteorder, final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (unicode == NULL)
|
if (unicode == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
|
tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
|
||||||
|
@ -383,7 +383,7 @@ static PyObject *
|
||||||
utf_32_decode(PyObject *self,
|
utf_32_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int byteorder = 0;
|
int byteorder = 0;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
|
@ -396,7 +396,7 @@ utf_32_decode(PyObject *self,
|
||||||
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
||||||
decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
|
decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
&byteorder, final ? NULL : &consumed);
|
&byteorder, final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (decoded == NULL)
|
if (decoded == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return codec_tuple(decoded, consumed);
|
return codec_tuple(decoded, consumed);
|
||||||
|
@ -406,7 +406,7 @@ static PyObject *
|
||||||
utf_32_le_decode(PyObject *self,
|
utf_32_le_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int byteorder = -1;
|
int byteorder = -1;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
|
@ -419,7 +419,7 @@ utf_32_le_decode(PyObject *self,
|
||||||
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
||||||
decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
|
decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
&byteorder, final ? NULL : &consumed);
|
&byteorder, final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (decoded == NULL)
|
if (decoded == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return codec_tuple(decoded, consumed);
|
return codec_tuple(decoded, consumed);
|
||||||
|
@ -429,7 +429,7 @@ static PyObject *
|
||||||
utf_32_be_decode(PyObject *self,
|
utf_32_be_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int byteorder = 1;
|
int byteorder = 1;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
|
@ -442,7 +442,7 @@ utf_32_be_decode(PyObject *self,
|
||||||
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
||||||
decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
|
decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
&byteorder, final ? NULL : &consumed);
|
&byteorder, final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (decoded == NULL)
|
if (decoded == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return codec_tuple(decoded, consumed);
|
return codec_tuple(decoded, consumed);
|
||||||
|
@ -460,7 +460,7 @@ static PyObject *
|
||||||
utf_32_ex_decode(PyObject *self,
|
utf_32_ex_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int byteorder = 0;
|
int byteorder = 0;
|
||||||
PyObject *unicode, *tuple;
|
PyObject *unicode, *tuple;
|
||||||
|
@ -473,7 +473,7 @@ utf_32_ex_decode(PyObject *self,
|
||||||
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
consumed = pbuf.len; /* This is overwritten unless final is true. */
|
||||||
unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
|
unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors,
|
||||||
&byteorder, final ? NULL : &consumed);
|
&byteorder, final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (unicode == NULL)
|
if (unicode == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
|
tuple = Py_BuildValue("Oni", unicode, consumed, byteorder);
|
||||||
|
@ -485,7 +485,7 @@ static PyObject *
|
||||||
unicode_escape_decode(PyObject *self,
|
unicode_escape_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
PyObject *unicode;
|
PyObject *unicode;
|
||||||
|
|
||||||
|
@ -493,68 +493,68 @@ unicode_escape_decode(PyObject *self,
|
||||||
&pbuf, &errors))
|
&pbuf, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors);
|
unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
return codec_tuple(unicode, pbuf.len);
|
return codec_tuple(unicode, pbuf.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
raw_unicode_escape_decode(PyObject *self,
|
raw_unicode_escape_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
PyObject *unicode;
|
PyObject *unicode;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode",
|
if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode",
|
||||||
&pbuf, &errors))
|
&pbuf, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors);
|
unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
return codec_tuple(unicode, pbuf.len);
|
return codec_tuple(unicode, pbuf.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
latin_1_decode(PyObject *self,
|
latin_1_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
PyObject *unicode;
|
PyObject *unicode;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s*|z:latin_1_decode",
|
if (!PyArg_ParseTuple(args, "s*|z:latin_1_decode",
|
||||||
&pbuf, &errors))
|
&pbuf, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors);
|
unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
return codec_tuple(unicode, pbuf.len);
|
return codec_tuple(unicode, pbuf.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
ascii_decode(PyObject *self,
|
ascii_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
PyObject *unicode;
|
PyObject *unicode;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s*|z:ascii_decode",
|
if (!PyArg_ParseTuple(args, "s*|z:ascii_decode",
|
||||||
&pbuf, &errors))
|
&pbuf, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors);
|
unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
return codec_tuple(unicode, pbuf.len);
|
return codec_tuple(unicode, pbuf.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
charmap_decode(PyObject *self,
|
charmap_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
PyObject *unicode;
|
PyObject *unicode;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
PyObject *mapping = NULL;
|
PyObject *mapping = NULL;
|
||||||
|
|
||||||
|
@ -564,9 +564,9 @@ charmap_decode(PyObject *self,
|
||||||
if (mapping == Py_None)
|
if (mapping == Py_None)
|
||||||
mapping = NULL;
|
mapping = NULL;
|
||||||
|
|
||||||
unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors);
|
unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
return codec_tuple(unicode, pbuf.len);
|
return codec_tuple(unicode, pbuf.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
|
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
|
||||||
|
@ -575,7 +575,7 @@ static PyObject *
|
||||||
mbcs_decode(PyObject *self,
|
mbcs_decode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
Py_buffer pbuf;
|
Py_buffer pbuf;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
int final = 0;
|
int final = 0;
|
||||||
Py_ssize_t consumed;
|
Py_ssize_t consumed;
|
||||||
|
@ -588,7 +588,7 @@ mbcs_decode(PyObject *self,
|
||||||
|
|
||||||
decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors,
|
decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors,
|
||||||
final ? NULL : &consumed);
|
final ? NULL : &consumed);
|
||||||
PyBuffer_Release(&pbuf);
|
PyBuffer_Release(&pbuf);
|
||||||
if (decoded == NULL)
|
if (decoded == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return codec_tuple(decoded, consumed);
|
return codec_tuple(decoded, consumed);
|
||||||
|
|
|
@ -106,24 +106,24 @@ bytearray_buffer_getcharbuf(PyByteArrayObject *self, Py_ssize_t index, const cha
|
||||||
static int
|
static int
|
||||||
bytearray_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags)
|
bytearray_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
if (view == NULL) {
|
if (view == NULL) {
|
||||||
obj->ob_exports++;
|
obj->ob_exports++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ptr = (void *) PyByteArray_AS_STRING(obj);
|
ptr = (void *) PyByteArray_AS_STRING(obj);
|
||||||
ret = PyBuffer_FillInfo(view, (PyObject*)obj, ptr, Py_SIZE(obj), 0, flags);
|
ret = PyBuffer_FillInfo(view, (PyObject*)obj, ptr, Py_SIZE(obj), 0, flags);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
obj->ob_exports++;
|
obj->ob_exports++;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bytearray_releasebuffer(PyByteArrayObject *obj, Py_buffer *view)
|
bytearray_releasebuffer(PyByteArrayObject *obj, Py_buffer *view)
|
||||||
{
|
{
|
||||||
obj->ob_exports--;
|
obj->ob_exports--;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Py_ssize_t
|
static Py_ssize_t
|
||||||
|
@ -1718,43 +1718,43 @@ replace_single_character_in_place(PyByteArrayObject *self,
|
||||||
char from_c, char to_c,
|
char from_c, char to_c,
|
||||||
Py_ssize_t maxcount)
|
Py_ssize_t maxcount)
|
||||||
{
|
{
|
||||||
char *self_s, *result_s, *start, *end, *next;
|
char *self_s, *result_s, *start, *end, *next;
|
||||||
Py_ssize_t self_len;
|
Py_ssize_t self_len;
|
||||||
PyByteArrayObject *result;
|
PyByteArrayObject *result;
|
||||||
|
|
||||||
/* The result string will be the same size */
|
/* The result string will be the same size */
|
||||||
self_s = PyByteArray_AS_STRING(self);
|
self_s = PyByteArray_AS_STRING(self);
|
||||||
self_len = PyByteArray_GET_SIZE(self);
|
self_len = PyByteArray_GET_SIZE(self);
|
||||||
|
|
||||||
next = findchar(self_s, self_len, from_c);
|
next = findchar(self_s, self_len, from_c);
|
||||||
|
|
||||||
if (next == NULL) {
|
if (next == NULL) {
|
||||||
/* No matches; return the original bytes */
|
/* No matches; return the original bytes */
|
||||||
return return_self(self);
|
return return_self(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Need to make a new bytes */
|
/* Need to make a new bytes */
|
||||||
result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len);
|
result = (PyByteArrayObject *) PyByteArray_FromStringAndSize(NULL, self_len);
|
||||||
if (result == NULL)
|
if (result == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
result_s = PyByteArray_AS_STRING(result);
|
result_s = PyByteArray_AS_STRING(result);
|
||||||
Py_MEMCPY(result_s, self_s, self_len);
|
Py_MEMCPY(result_s, self_s, self_len);
|
||||||
|
|
||||||
/* change everything in-place, starting with this one */
|
/* change everything in-place, starting with this one */
|
||||||
start = result_s + (next-self_s);
|
start = result_s + (next-self_s);
|
||||||
*start = to_c;
|
*start = to_c;
|
||||||
start++;
|
start++;
|
||||||
end = result_s + self_len;
|
end = result_s + self_len;
|
||||||
|
|
||||||
while (--maxcount > 0) {
|
while (--maxcount > 0) {
|
||||||
next = findchar(start, end-start, from_c);
|
next = findchar(start, end-start, from_c);
|
||||||
if (next == NULL)
|
if (next == NULL)
|
||||||
break;
|
break;
|
||||||
*next = to_c;
|
*next = to_c;
|
||||||
start = next+1;
|
start = next+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* len(self)>=1, len(from)==len(to)>=2, maxcount>=1 */
|
/* len(self)>=1, len(from)==len(to)>=2, maxcount>=1 */
|
||||||
|
|
|
@ -426,7 +426,7 @@ PyObject *PyString_Decode(const char *s,
|
||||||
|
|
||||||
str = PyString_FromStringAndSize(s, size);
|
str = PyString_FromStringAndSize(s, size);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
v = PyString_AsDecodedString(str, encoding, errors);
|
v = PyString_AsDecodedString(str, encoding, errors);
|
||||||
Py_DECREF(str);
|
Py_DECREF(str);
|
||||||
return v;
|
return v;
|
||||||
|
@ -439,23 +439,23 @@ PyObject *PyString_AsDecodedObject(PyObject *str,
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
|
|
||||||
if (!PyString_Check(str)) {
|
if (!PyString_Check(str)) {
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoding == NULL) {
|
if (encoding == NULL) {
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
encoding = PyUnicode_GetDefaultEncoding();
|
encoding = PyUnicode_GetDefaultEncoding();
|
||||||
#else
|
#else
|
||||||
PyErr_SetString(PyExc_ValueError, "no encoding specified");
|
PyErr_SetString(PyExc_ValueError, "no encoding specified");
|
||||||
goto onError;
|
goto onError;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decode via the codec registry */
|
/* Decode via the codec registry */
|
||||||
v = PyCodec_Decode(str, encoding, errors);
|
v = PyCodec_Decode(str, encoding, errors);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
goto onError;
|
goto onError;
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
|
||||||
|
@ -471,24 +471,24 @@ PyObject *PyString_AsDecodedString(PyObject *str,
|
||||||
|
|
||||||
v = PyString_AsDecodedObject(str, encoding, errors);
|
v = PyString_AsDecodedObject(str, encoding, errors);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
goto onError;
|
goto onError;
|
||||||
|
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
/* Convert Unicode to a string using the default encoding */
|
/* Convert Unicode to a string using the default encoding */
|
||||||
if (PyUnicode_Check(v)) {
|
if (PyUnicode_Check(v)) {
|
||||||
PyObject *temp = v;
|
PyObject *temp = v;
|
||||||
v = PyUnicode_AsEncodedString(v, NULL, NULL);
|
v = PyUnicode_AsEncodedString(v, NULL, NULL);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!PyString_Check(v)) {
|
if (!PyString_Check(v)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"decoder did not return a string object (type=%.400s)",
|
"decoder did not return a string object (type=%.400s)",
|
||||||
Py_TYPE(v)->tp_name);
|
Py_TYPE(v)->tp_name);
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
@ -506,7 +506,7 @@ PyObject *PyString_Encode(const char *s,
|
||||||
|
|
||||||
str = PyString_FromStringAndSize(s, size);
|
str = PyString_FromStringAndSize(s, size);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
v = PyString_AsEncodedString(str, encoding, errors);
|
v = PyString_AsEncodedString(str, encoding, errors);
|
||||||
Py_DECREF(str);
|
Py_DECREF(str);
|
||||||
return v;
|
return v;
|
||||||
|
@ -519,23 +519,23 @@ PyObject *PyString_AsEncodedObject(PyObject *str,
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
|
|
||||||
if (!PyString_Check(str)) {
|
if (!PyString_Check(str)) {
|
||||||
PyErr_BadArgument();
|
PyErr_BadArgument();
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoding == NULL) {
|
if (encoding == NULL) {
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
encoding = PyUnicode_GetDefaultEncoding();
|
encoding = PyUnicode_GetDefaultEncoding();
|
||||||
#else
|
#else
|
||||||
PyErr_SetString(PyExc_ValueError, "no encoding specified");
|
PyErr_SetString(PyExc_ValueError, "no encoding specified");
|
||||||
goto onError;
|
goto onError;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encode via the codec registry */
|
/* Encode via the codec registry */
|
||||||
v = PyCodec_Encode(str, encoding, errors);
|
v = PyCodec_Encode(str, encoding, errors);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
goto onError;
|
goto onError;
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
|
||||||
|
@ -551,24 +551,24 @@ PyObject *PyString_AsEncodedString(PyObject *str,
|
||||||
|
|
||||||
v = PyString_AsEncodedObject(str, encoding, errors);
|
v = PyString_AsEncodedObject(str, encoding, errors);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
goto onError;
|
goto onError;
|
||||||
|
|
||||||
#ifdef Py_USING_UNICODE
|
#ifdef Py_USING_UNICODE
|
||||||
/* Convert Unicode to a string using the default encoding */
|
/* Convert Unicode to a string using the default encoding */
|
||||||
if (PyUnicode_Check(v)) {
|
if (PyUnicode_Check(v)) {
|
||||||
PyObject *temp = v;
|
PyObject *temp = v;
|
||||||
v = PyUnicode_AsEncodedString(v, NULL, NULL);
|
v = PyUnicode_AsEncodedString(v, NULL, NULL);
|
||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!PyString_Check(v)) {
|
if (!PyString_Check(v)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"encoder did not return a string object (type=%.400s)",
|
"encoder did not return a string object (type=%.400s)",
|
||||||
Py_TYPE(v)->tp_name);
|
Py_TYPE(v)->tp_name);
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
goto onError;
|
goto onError;
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
|
@ -3002,17 +3002,17 @@ string_encode(PyStringObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:encode",
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:encode",
|
||||||
kwlist, &encoding, &errors))
|
kwlist, &encoding, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
v = PyString_AsEncodedObject((PyObject *)self, encoding, errors);
|
v = PyString_AsEncodedObject((PyObject *)self, encoding, errors);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
goto onError;
|
goto onError;
|
||||||
if (!PyString_Check(v) && !PyUnicode_Check(v)) {
|
if (!PyString_Check(v) && !PyUnicode_Check(v)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"encoder did not return a string/unicode object "
|
"encoder did not return a string/unicode object "
|
||||||
"(type=%.400s)",
|
"(type=%.400s)",
|
||||||
Py_TYPE(v)->tp_name);
|
Py_TYPE(v)->tp_name);
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
|
||||||
|
@ -3041,17 +3041,17 @@ string_decode(PyStringObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode",
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode",
|
||||||
kwlist, &encoding, &errors))
|
kwlist, &encoding, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
v = PyString_AsDecodedObject((PyObject *)self, encoding, errors);
|
v = PyString_AsDecodedObject((PyObject *)self, encoding, errors);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
goto onError;
|
goto onError;
|
||||||
if (!PyString_Check(v) && !PyUnicode_Check(v)) {
|
if (!PyString_Check(v) && !PyUnicode_Check(v)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"decoder did not return a string/unicode object "
|
"decoder did not return a string/unicode object "
|
||||||
"(type=%.400s)",
|
"(type=%.400s)",
|
||||||
Py_TYPE(v)->tp_name);
|
Py_TYPE(v)->tp_name);
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
|
||||||
|
@ -3076,7 +3076,7 @@ string_expandtabs(PyStringObject *self, PyObject *args)
|
||||||
int tabsize = 8;
|
int tabsize = 8;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|i:expandtabs", &tabsize))
|
if (!PyArg_ParseTuple(args, "|i:expandtabs", &tabsize))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* First pass: determine size of output string */
|
/* First pass: determine size of output string */
|
||||||
i = 0; /* chars up to and including most recent \n or \r */
|
i = 0; /* chars up to and including most recent \n or \r */
|
||||||
|
@ -3085,31 +3085,31 @@ string_expandtabs(PyStringObject *self, PyObject *args)
|
||||||
for (p = PyString_AS_STRING(self); p < e; p++)
|
for (p = PyString_AS_STRING(self); p < e; p++)
|
||||||
if (*p == '\t') {
|
if (*p == '\t') {
|
||||||
if (tabsize > 0) {
|
if (tabsize > 0) {
|
||||||
incr = tabsize - (j % tabsize);
|
incr = tabsize - (j % tabsize);
|
||||||
if (j > PY_SSIZE_T_MAX - incr)
|
if (j > PY_SSIZE_T_MAX - incr)
|
||||||
goto overflow1;
|
goto overflow1;
|
||||||
j += incr;
|
j += incr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (j > PY_SSIZE_T_MAX - 1)
|
if (j > PY_SSIZE_T_MAX - 1)
|
||||||
goto overflow1;
|
goto overflow1;
|
||||||
j++;
|
j++;
|
||||||
if (*p == '\n' || *p == '\r') {
|
if (*p == '\n' || *p == '\r') {
|
||||||
if (i > PY_SSIZE_T_MAX - j)
|
if (i > PY_SSIZE_T_MAX - j)
|
||||||
goto overflow1;
|
goto overflow1;
|
||||||
i += j;
|
i += j;
|
||||||
j = 0;
|
j = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i > PY_SSIZE_T_MAX - j)
|
if (i > PY_SSIZE_T_MAX - j)
|
||||||
goto overflow1;
|
goto overflow1;
|
||||||
|
|
||||||
/* Second pass: create output string and fill it */
|
/* Second pass: create output string and fill it */
|
||||||
u = PyString_FromStringAndSize(NULL, i + j);
|
u = PyString_FromStringAndSize(NULL, i + j);
|
||||||
if (!u)
|
if (!u)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
j = 0; /* same as in first pass */
|
j = 0; /* same as in first pass */
|
||||||
q = PyString_AS_STRING(u); /* next output char */
|
q = PyString_AS_STRING(u); /* next output char */
|
||||||
|
@ -3118,22 +3118,22 @@ string_expandtabs(PyStringObject *self, PyObject *args)
|
||||||
for (p = PyString_AS_STRING(self); p < e; p++)
|
for (p = PyString_AS_STRING(self); p < e; p++)
|
||||||
if (*p == '\t') {
|
if (*p == '\t') {
|
||||||
if (tabsize > 0) {
|
if (tabsize > 0) {
|
||||||
i = tabsize - (j % tabsize);
|
i = tabsize - (j % tabsize);
|
||||||
j += i;
|
j += i;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
if (q >= qe)
|
if (q >= qe)
|
||||||
goto overflow2;
|
goto overflow2;
|
||||||
*q++ = ' ';
|
*q++ = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (q >= qe)
|
if (q >= qe)
|
||||||
goto overflow2;
|
goto overflow2;
|
||||||
*q++ = *p;
|
*q++ = *p;
|
||||||
j++;
|
j++;
|
||||||
if (*p == '\n' || *p == '\r')
|
if (*p == '\n' || *p == '\r')
|
||||||
j = 0;
|
j = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return u;
|
return u;
|
||||||
|
@ -3151,26 +3151,26 @@ pad(PyStringObject *self, Py_ssize_t left, Py_ssize_t right, char fill)
|
||||||
PyObject *u;
|
PyObject *u;
|
||||||
|
|
||||||
if (left < 0)
|
if (left < 0)
|
||||||
left = 0;
|
left = 0;
|
||||||
if (right < 0)
|
if (right < 0)
|
||||||
right = 0;
|
right = 0;
|
||||||
|
|
||||||
if (left == 0 && right == 0 && PyString_CheckExact(self)) {
|
if (left == 0 && right == 0 && PyString_CheckExact(self)) {
|
||||||
Py_INCREF(self);
|
Py_INCREF(self);
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
u = PyString_FromStringAndSize(NULL,
|
u = PyString_FromStringAndSize(NULL,
|
||||||
left + PyString_GET_SIZE(self) + right);
|
left + PyString_GET_SIZE(self) + right);
|
||||||
if (u) {
|
if (u) {
|
||||||
if (left)
|
if (left)
|
||||||
memset(PyString_AS_STRING(u), fill, left);
|
memset(PyString_AS_STRING(u), fill, left);
|
||||||
Py_MEMCPY(PyString_AS_STRING(u) + left,
|
Py_MEMCPY(PyString_AS_STRING(u) + left,
|
||||||
PyString_AS_STRING(self),
|
PyString_AS_STRING(self),
|
||||||
PyString_GET_SIZE(self));
|
PyString_GET_SIZE(self));
|
||||||
if (right)
|
if (right)
|
||||||
memset(PyString_AS_STRING(u) + left + PyString_GET_SIZE(self),
|
memset(PyString_AS_STRING(u) + left + PyString_GET_SIZE(self),
|
||||||
fill, right);
|
fill, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
return u;
|
return u;
|
||||||
|
@ -3189,11 +3189,11 @@ string_ljust(PyStringObject *self, PyObject *args)
|
||||||
char fillchar = ' ';
|
char fillchar = ' ';
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "n|c:ljust", &width, &fillchar))
|
if (!PyArg_ParseTuple(args, "n|c:ljust", &width, &fillchar))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
|
if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
|
||||||
Py_INCREF(self);
|
Py_INCREF(self);
|
||||||
return (PyObject*) self;
|
return (PyObject*) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pad(self, 0, width - PyString_GET_SIZE(self), fillchar);
|
return pad(self, 0, width - PyString_GET_SIZE(self), fillchar);
|
||||||
|
@ -3213,11 +3213,11 @@ string_rjust(PyStringObject *self, PyObject *args)
|
||||||
char fillchar = ' ';
|
char fillchar = ' ';
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "n|c:rjust", &width, &fillchar))
|
if (!PyArg_ParseTuple(args, "n|c:rjust", &width, &fillchar))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
|
if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
|
||||||
Py_INCREF(self);
|
Py_INCREF(self);
|
||||||
return (PyObject*) self;
|
return (PyObject*) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pad(self, width - PyString_GET_SIZE(self), 0, fillchar);
|
return pad(self, width - PyString_GET_SIZE(self), 0, fillchar);
|
||||||
|
@ -3238,11 +3238,11 @@ string_center(PyStringObject *self, PyObject *args)
|
||||||
char fillchar = ' ';
|
char fillchar = ' ';
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "n|c:center", &width, &fillchar))
|
if (!PyArg_ParseTuple(args, "n|c:center", &width, &fillchar))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
|
if (PyString_GET_SIZE(self) >= width && PyString_CheckExact(self)) {
|
||||||
Py_INCREF(self);
|
Py_INCREF(self);
|
||||||
return (PyObject*) self;
|
return (PyObject*) self;
|
||||||
}
|
}
|
||||||
|
|
||||||
marg = width - PyString_GET_SIZE(self);
|
marg = width - PyString_GET_SIZE(self);
|
||||||
|
@ -3266,18 +3266,18 @@ string_zfill(PyStringObject *self, PyObject *args)
|
||||||
Py_ssize_t width;
|
Py_ssize_t width;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "n:zfill", &width))
|
if (!PyArg_ParseTuple(args, "n:zfill", &width))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (PyString_GET_SIZE(self) >= width) {
|
if (PyString_GET_SIZE(self) >= width) {
|
||||||
if (PyString_CheckExact(self)) {
|
if (PyString_CheckExact(self)) {
|
||||||
Py_INCREF(self);
|
Py_INCREF(self);
|
||||||
return (PyObject*) self;
|
return (PyObject*) self;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return PyString_FromStringAndSize(
|
return PyString_FromStringAndSize(
|
||||||
PyString_AS_STRING(self),
|
PyString_AS_STRING(self),
|
||||||
PyString_GET_SIZE(self)
|
PyString_GET_SIZE(self)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fill = width - PyString_GET_SIZE(self);
|
fill = width - PyString_GET_SIZE(self);
|
||||||
|
@ -3285,13 +3285,13 @@ string_zfill(PyStringObject *self, PyObject *args)
|
||||||
s = pad(self, fill, 0, '0');
|
s = pad(self, fill, 0, '0');
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
p = PyString_AS_STRING(s);
|
p = PyString_AS_STRING(s);
|
||||||
if (p[fill] == '+' || p[fill] == '-') {
|
if (p[fill] == '+' || p[fill] == '-') {
|
||||||
/* move sign to beginning of string */
|
/* move sign to beginning of string */
|
||||||
p[0] = p[fill];
|
p[0] = p[fill];
|
||||||
p[fill] = '0';
|
p[fill] = '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject*) s;
|
return (PyObject*) s;
|
||||||
|
@ -3307,22 +3307,22 @@ static PyObject*
|
||||||
string_isspace(PyStringObject *self)
|
string_isspace(PyStringObject *self)
|
||||||
{
|
{
|
||||||
register const unsigned char *p
|
register const unsigned char *p
|
||||||
= (unsigned char *) PyString_AS_STRING(self);
|
= (unsigned char *) PyString_AS_STRING(self);
|
||||||
register const unsigned char *e;
|
register const unsigned char *e;
|
||||||
|
|
||||||
/* Shortcut for single character strings */
|
/* Shortcut for single character strings */
|
||||||
if (PyString_GET_SIZE(self) == 1 &&
|
if (PyString_GET_SIZE(self) == 1 &&
|
||||||
isspace(*p))
|
isspace(*p))
|
||||||
return PyBool_FromLong(1);
|
return PyBool_FromLong(1);
|
||||||
|
|
||||||
/* Special case for empty strings */
|
/* Special case for empty strings */
|
||||||
if (PyString_GET_SIZE(self) == 0)
|
if (PyString_GET_SIZE(self) == 0)
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
|
|
||||||
e = p + PyString_GET_SIZE(self);
|
e = p + PyString_GET_SIZE(self);
|
||||||
for (; p < e; p++) {
|
for (; p < e; p++) {
|
||||||
if (!isspace(*p))
|
if (!isspace(*p))
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
}
|
}
|
||||||
return PyBool_FromLong(1);
|
return PyBool_FromLong(1);
|
||||||
}
|
}
|
||||||
|
@ -3338,22 +3338,22 @@ static PyObject*
|
||||||
string_isalpha(PyStringObject *self)
|
string_isalpha(PyStringObject *self)
|
||||||
{
|
{
|
||||||
register const unsigned char *p
|
register const unsigned char *p
|
||||||
= (unsigned char *) PyString_AS_STRING(self);
|
= (unsigned char *) PyString_AS_STRING(self);
|
||||||
register const unsigned char *e;
|
register const unsigned char *e;
|
||||||
|
|
||||||
/* Shortcut for single character strings */
|
/* Shortcut for single character strings */
|
||||||
if (PyString_GET_SIZE(self) == 1 &&
|
if (PyString_GET_SIZE(self) == 1 &&
|
||||||
isalpha(*p))
|
isalpha(*p))
|
||||||
return PyBool_FromLong(1);
|
return PyBool_FromLong(1);
|
||||||
|
|
||||||
/* Special case for empty strings */
|
/* Special case for empty strings */
|
||||||
if (PyString_GET_SIZE(self) == 0)
|
if (PyString_GET_SIZE(self) == 0)
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
|
|
||||||
e = p + PyString_GET_SIZE(self);
|
e = p + PyString_GET_SIZE(self);
|
||||||
for (; p < e; p++) {
|
for (; p < e; p++) {
|
||||||
if (!isalpha(*p))
|
if (!isalpha(*p))
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
}
|
}
|
||||||
return PyBool_FromLong(1);
|
return PyBool_FromLong(1);
|
||||||
}
|
}
|
||||||
|
@ -3369,22 +3369,22 @@ static PyObject*
|
||||||
string_isalnum(PyStringObject *self)
|
string_isalnum(PyStringObject *self)
|
||||||
{
|
{
|
||||||
register const unsigned char *p
|
register const unsigned char *p
|
||||||
= (unsigned char *) PyString_AS_STRING(self);
|
= (unsigned char *) PyString_AS_STRING(self);
|
||||||
register const unsigned char *e;
|
register const unsigned char *e;
|
||||||
|
|
||||||
/* Shortcut for single character strings */
|
/* Shortcut for single character strings */
|
||||||
if (PyString_GET_SIZE(self) == 1 &&
|
if (PyString_GET_SIZE(self) == 1 &&
|
||||||
isalnum(*p))
|
isalnum(*p))
|
||||||
return PyBool_FromLong(1);
|
return PyBool_FromLong(1);
|
||||||
|
|
||||||
/* Special case for empty strings */
|
/* Special case for empty strings */
|
||||||
if (PyString_GET_SIZE(self) == 0)
|
if (PyString_GET_SIZE(self) == 0)
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
|
|
||||||
e = p + PyString_GET_SIZE(self);
|
e = p + PyString_GET_SIZE(self);
|
||||||
for (; p < e; p++) {
|
for (; p < e; p++) {
|
||||||
if (!isalnum(*p))
|
if (!isalnum(*p))
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
}
|
}
|
||||||
return PyBool_FromLong(1);
|
return PyBool_FromLong(1);
|
||||||
}
|
}
|
||||||
|
@ -3400,22 +3400,22 @@ static PyObject*
|
||||||
string_isdigit(PyStringObject *self)
|
string_isdigit(PyStringObject *self)
|
||||||
{
|
{
|
||||||
register const unsigned char *p
|
register const unsigned char *p
|
||||||
= (unsigned char *) PyString_AS_STRING(self);
|
= (unsigned char *) PyString_AS_STRING(self);
|
||||||
register const unsigned char *e;
|
register const unsigned char *e;
|
||||||
|
|
||||||
/* Shortcut for single character strings */
|
/* Shortcut for single character strings */
|
||||||
if (PyString_GET_SIZE(self) == 1 &&
|
if (PyString_GET_SIZE(self) == 1 &&
|
||||||
isdigit(*p))
|
isdigit(*p))
|
||||||
return PyBool_FromLong(1);
|
return PyBool_FromLong(1);
|
||||||
|
|
||||||
/* Special case for empty strings */
|
/* Special case for empty strings */
|
||||||
if (PyString_GET_SIZE(self) == 0)
|
if (PyString_GET_SIZE(self) == 0)
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
|
|
||||||
e = p + PyString_GET_SIZE(self);
|
e = p + PyString_GET_SIZE(self);
|
||||||
for (; p < e; p++) {
|
for (; p < e; p++) {
|
||||||
if (!isdigit(*p))
|
if (!isdigit(*p))
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
}
|
}
|
||||||
return PyBool_FromLong(1);
|
return PyBool_FromLong(1);
|
||||||
}
|
}
|
||||||
|
@ -3431,25 +3431,25 @@ static PyObject*
|
||||||
string_islower(PyStringObject *self)
|
string_islower(PyStringObject *self)
|
||||||
{
|
{
|
||||||
register const unsigned char *p
|
register const unsigned char *p
|
||||||
= (unsigned char *) PyString_AS_STRING(self);
|
= (unsigned char *) PyString_AS_STRING(self);
|
||||||
register const unsigned char *e;
|
register const unsigned char *e;
|
||||||
int cased;
|
int cased;
|
||||||
|
|
||||||
/* Shortcut for single character strings */
|
/* Shortcut for single character strings */
|
||||||
if (PyString_GET_SIZE(self) == 1)
|
if (PyString_GET_SIZE(self) == 1)
|
||||||
return PyBool_FromLong(islower(*p) != 0);
|
return PyBool_FromLong(islower(*p) != 0);
|
||||||
|
|
||||||
/* Special case for empty strings */
|
/* Special case for empty strings */
|
||||||
if (PyString_GET_SIZE(self) == 0)
|
if (PyString_GET_SIZE(self) == 0)
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
|
|
||||||
e = p + PyString_GET_SIZE(self);
|
e = p + PyString_GET_SIZE(self);
|
||||||
cased = 0;
|
cased = 0;
|
||||||
for (; p < e; p++) {
|
for (; p < e; p++) {
|
||||||
if (isupper(*p))
|
if (isupper(*p))
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
else if (!cased && islower(*p))
|
else if (!cased && islower(*p))
|
||||||
cased = 1;
|
cased = 1;
|
||||||
}
|
}
|
||||||
return PyBool_FromLong(cased);
|
return PyBool_FromLong(cased);
|
||||||
}
|
}
|
||||||
|
@ -3465,25 +3465,25 @@ static PyObject*
|
||||||
string_isupper(PyStringObject *self)
|
string_isupper(PyStringObject *self)
|
||||||
{
|
{
|
||||||
register const unsigned char *p
|
register const unsigned char *p
|
||||||
= (unsigned char *) PyString_AS_STRING(self);
|
= (unsigned char *) PyString_AS_STRING(self);
|
||||||
register const unsigned char *e;
|
register const unsigned char *e;
|
||||||
int cased;
|
int cased;
|
||||||
|
|
||||||
/* Shortcut for single character strings */
|
/* Shortcut for single character strings */
|
||||||
if (PyString_GET_SIZE(self) == 1)
|
if (PyString_GET_SIZE(self) == 1)
|
||||||
return PyBool_FromLong(isupper(*p) != 0);
|
return PyBool_FromLong(isupper(*p) != 0);
|
||||||
|
|
||||||
/* Special case for empty strings */
|
/* Special case for empty strings */
|
||||||
if (PyString_GET_SIZE(self) == 0)
|
if (PyString_GET_SIZE(self) == 0)
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
|
|
||||||
e = p + PyString_GET_SIZE(self);
|
e = p + PyString_GET_SIZE(self);
|
||||||
cased = 0;
|
cased = 0;
|
||||||
for (; p < e; p++) {
|
for (; p < e; p++) {
|
||||||
if (islower(*p))
|
if (islower(*p))
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
else if (!cased && isupper(*p))
|
else if (!cased && isupper(*p))
|
||||||
cased = 1;
|
cased = 1;
|
||||||
}
|
}
|
||||||
return PyBool_FromLong(cased);
|
return PyBool_FromLong(cased);
|
||||||
}
|
}
|
||||||
|
@ -3501,38 +3501,38 @@ static PyObject*
|
||||||
string_istitle(PyStringObject *self, PyObject *uncased)
|
string_istitle(PyStringObject *self, PyObject *uncased)
|
||||||
{
|
{
|
||||||
register const unsigned char *p
|
register const unsigned char *p
|
||||||
= (unsigned char *) PyString_AS_STRING(self);
|
= (unsigned char *) PyString_AS_STRING(self);
|
||||||
register const unsigned char *e;
|
register const unsigned char *e;
|
||||||
int cased, previous_is_cased;
|
int cased, previous_is_cased;
|
||||||
|
|
||||||
/* Shortcut for single character strings */
|
/* Shortcut for single character strings */
|
||||||
if (PyString_GET_SIZE(self) == 1)
|
if (PyString_GET_SIZE(self) == 1)
|
||||||
return PyBool_FromLong(isupper(*p) != 0);
|
return PyBool_FromLong(isupper(*p) != 0);
|
||||||
|
|
||||||
/* Special case for empty strings */
|
/* Special case for empty strings */
|
||||||
if (PyString_GET_SIZE(self) == 0)
|
if (PyString_GET_SIZE(self) == 0)
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
|
|
||||||
e = p + PyString_GET_SIZE(self);
|
e = p + PyString_GET_SIZE(self);
|
||||||
cased = 0;
|
cased = 0;
|
||||||
previous_is_cased = 0;
|
previous_is_cased = 0;
|
||||||
for (; p < e; p++) {
|
for (; p < e; p++) {
|
||||||
register const unsigned char ch = *p;
|
register const unsigned char ch = *p;
|
||||||
|
|
||||||
if (isupper(ch)) {
|
if (isupper(ch)) {
|
||||||
if (previous_is_cased)
|
if (previous_is_cased)
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
previous_is_cased = 1;
|
previous_is_cased = 1;
|
||||||
cased = 1;
|
cased = 1;
|
||||||
}
|
}
|
||||||
else if (islower(ch)) {
|
else if (islower(ch)) {
|
||||||
if (!previous_is_cased)
|
if (!previous_is_cased)
|
||||||
return PyBool_FromLong(0);
|
return PyBool_FromLong(0);
|
||||||
previous_is_cased = 1;
|
previous_is_cased = 1;
|
||||||
cased = 1;
|
cased = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
previous_is_cased = 0;
|
previous_is_cased = 0;
|
||||||
}
|
}
|
||||||
return PyBool_FromLong(cased);
|
return PyBool_FromLong(cased);
|
||||||
}
|
}
|
||||||
|
@ -3551,11 +3551,11 @@ string_splitlines(PyStringObject *self, PyObject *args)
|
||||||
int keepends = 0;
|
int keepends = 0;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))
|
if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return stringlib_splitlines(
|
return stringlib_splitlines(
|
||||||
(PyObject*) self, PyString_AS_STRING(self), PyString_GET_SIZE(self),
|
(PyObject*) self, PyString_AS_STRING(self), PyString_GET_SIZE(self),
|
||||||
keepends
|
keepends
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3594,15 +3594,15 @@ string__format__(PyObject* self, PyObject* args)
|
||||||
/* If 2.x, convert format_spec to the same type as value */
|
/* If 2.x, convert format_spec to the same type as value */
|
||||||
/* This is to allow things like u''.format('') */
|
/* This is to allow things like u''.format('') */
|
||||||
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
|
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
|
||||||
goto done;
|
goto done;
|
||||||
if (!(PyString_Check(format_spec) || PyUnicode_Check(format_spec))) {
|
if (!(PyString_Check(format_spec) || PyUnicode_Check(format_spec))) {
|
||||||
PyErr_Format(PyExc_TypeError, "__format__ arg must be str "
|
PyErr_Format(PyExc_TypeError, "__format__ arg must be str "
|
||||||
"or unicode, not %s", Py_TYPE(format_spec)->tp_name);
|
"or unicode, not %s", Py_TYPE(format_spec)->tp_name);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
tmp = PyObject_Str(format_spec);
|
tmp = PyObject_Str(format_spec);
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
format_spec = tmp;
|
format_spec = tmp;
|
||||||
|
|
||||||
result = _PyBytes_FormatAdvanced(self,
|
result = _PyBytes_FormatAdvanced(self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue