Merged revisions 81860 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r81860 | antoine.pitrou | 2010-06-09 18:24:00 +0200 (mer., 09 juin 2010) | 3 lines Issue #8930: fix some C code indentation ........
This commit is contained in:
parent
0ca4624e8a
commit
d118856049
|
@ -162,62 +162,62 @@ static PyObject *
|
||||||
escape_encode(PyObject *self,
|
escape_encode(PyObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
static const char *hexdigits = "0123456789abcdef";
|
static const char *hexdigits = "0123456789abcdef";
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
Py_ssize_t newsize;
|
Py_ssize_t newsize;
|
||||||
const char *errors = NULL;
|
const char *errors = NULL;
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
|
if (!PyArg_ParseTuple(args, "O!|z:escape_encode",
|
||||||
&PyBytes_Type, &str, &errors))
|
&PyBytes_Type, &str, &errors))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
size = PyBytes_GET_SIZE(str);
|
size = PyBytes_GET_SIZE(str);
|
||||||
newsize = 4*size;
|
newsize = 4*size;
|
||||||
if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
|
if (newsize > PY_SSIZE_T_MAX || newsize / 4 != size) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"string is too large to encode");
|
"string is too large to encode");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
v = PyBytes_FromStringAndSize(NULL, newsize);
|
||||||
|
|
||||||
|
if (v == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
register Py_ssize_t i;
|
||||||
|
register char c;
|
||||||
|
register char *p = PyBytes_AS_STRING(v);
|
||||||
|
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
/* There's at least enough room for a hex escape */
|
||||||
|
assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4);
|
||||||
|
c = PyBytes_AS_STRING(str)[i];
|
||||||
|
if (c == '\'' || c == '\\')
|
||||||
|
*p++ = '\\', *p++ = c;
|
||||||
|
else if (c == '\t')
|
||||||
|
*p++ = '\\', *p++ = 't';
|
||||||
|
else if (c == '\n')
|
||||||
|
*p++ = '\\', *p++ = 'n';
|
||||||
|
else if (c == '\r')
|
||||||
|
*p++ = '\\', *p++ = 'r';
|
||||||
|
else if (c < ' ' || c >= 0x7f) {
|
||||||
|
*p++ = '\\';
|
||||||
|
*p++ = 'x';
|
||||||
|
*p++ = hexdigits[(c & 0xf0) >> 4];
|
||||||
|
*p++ = hexdigits[c & 0xf];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*p++ = c;
|
||||||
}
|
}
|
||||||
v = PyBytes_FromStringAndSize(NULL, newsize);
|
*p = '\0';
|
||||||
|
if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) {
|
||||||
if (v == NULL) {
|
return NULL;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
register Py_ssize_t i;
|
|
||||||
register char c;
|
|
||||||
register char *p = PyBytes_AS_STRING(v);
|
|
||||||
|
|
||||||
for (i = 0; i < size; i++) {
|
return codec_tuple(v, size);
|
||||||
/* There's at least enough room for a hex escape */
|
|
||||||
assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4);
|
|
||||||
c = PyBytes_AS_STRING(str)[i];
|
|
||||||
if (c == '\'' || c == '\\')
|
|
||||||
*p++ = '\\', *p++ = c;
|
|
||||||
else if (c == '\t')
|
|
||||||
*p++ = '\\', *p++ = 't';
|
|
||||||
else if (c == '\n')
|
|
||||||
*p++ = '\\', *p++ = 'n';
|
|
||||||
else if (c == '\r')
|
|
||||||
*p++ = '\\', *p++ = 'r';
|
|
||||||
else if (c < ' ' || c >= 0x7f) {
|
|
||||||
*p++ = '\\';
|
|
||||||
*p++ = 'x';
|
|
||||||
*p++ = hexdigits[(c & 0xf0) >> 4];
|
|
||||||
*p++ = hexdigits[c & 0xf];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*p++ = c;
|
|
||||||
}
|
|
||||||
*p = '\0';
|
|
||||||
if (_PyBytes_Resize(&v, (p - PyBytes_AS_STRING(v)))) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return codec_tuple(v, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- Decoder ------------------------------------------------------------ */
|
/* --- Decoder ------------------------------------------------------------ */
|
||||||
|
@ -252,7 +252,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;
|
||||||
|
@ -265,7 +265,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);
|
||||||
|
@ -275,7 +275,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;
|
||||||
|
@ -288,7 +288,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);
|
||||||
|
@ -298,7 +298,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;
|
||||||
|
@ -311,7 +311,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);
|
||||||
|
@ -321,7 +321,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;
|
||||||
|
@ -335,7 +335,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);
|
||||||
|
@ -345,7 +345,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;
|
||||||
|
@ -359,7 +359,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);
|
||||||
|
@ -377,7 +377,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;
|
||||||
|
@ -390,7 +390,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);
|
||||||
|
@ -402,7 +402,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;
|
||||||
|
@ -415,7 +415,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);
|
||||||
|
@ -425,7 +425,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;
|
||||||
|
@ -438,7 +438,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);
|
||||||
|
@ -448,7 +448,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;
|
||||||
|
@ -461,7 +461,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);
|
||||||
|
@ -479,7 +479,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;
|
||||||
|
@ -492,7 +492,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);
|
||||||
|
@ -504,7 +504,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;
|
||||||
|
|
||||||
|
@ -512,68 +512,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, "y*|z:latin_1_decode",
|
if (!PyArg_ParseTuple(args, "y*|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, "y*|z:ascii_decode",
|
if (!PyArg_ParseTuple(args, "y*|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;
|
||||||
|
|
||||||
|
@ -583,9 +583,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)
|
||||||
|
@ -594,7 +594,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;
|
||||||
|
@ -607,7 +607,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);
|
||||||
|
|
|
@ -1650,43 +1650,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 */
|
||||||
|
|
|
@ -14,10 +14,10 @@ _getbuffer(PyObject *obj, Py_buffer *view)
|
||||||
|
|
||||||
if (buffer == NULL || buffer->bf_getbuffer == NULL)
|
if (buffer == NULL || buffer->bf_getbuffer == NULL)
|
||||||
{
|
{
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"Type %.100s doesn't support the buffer API",
|
"Type %.100s doesn't support the buffer API",
|
||||||
Py_TYPE(obj)->tp_name);
|
Py_TYPE(obj)->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0)
|
if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0)
|
||||||
|
@ -776,19 +776,19 @@ bytes_contains(PyObject *self, PyObject *arg)
|
||||||
{
|
{
|
||||||
Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_ValueError);
|
Py_ssize_t ival = PyNumber_AsSsize_t(arg, PyExc_ValueError);
|
||||||
if (ival == -1 && PyErr_Occurred()) {
|
if (ival == -1 && PyErr_Occurred()) {
|
||||||
Py_buffer varg;
|
Py_buffer varg;
|
||||||
int pos;
|
int pos;
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
if (_getbuffer(arg, &varg) < 0)
|
if (_getbuffer(arg, &varg) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
pos = stringlib_find(PyBytes_AS_STRING(self), Py_SIZE(self),
|
pos = stringlib_find(PyBytes_AS_STRING(self), Py_SIZE(self),
|
||||||
varg.buf, varg.len, 0);
|
varg.buf, varg.len, 0);
|
||||||
PyBuffer_Release(&varg);
|
PyBuffer_Release(&varg);
|
||||||
return pos >= 0;
|
return pos >= 0;
|
||||||
}
|
}
|
||||||
if (ival < 0 || ival >= 256) {
|
if (ival < 0 || ival >= 256) {
|
||||||
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
|
PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return memchr(PyBytes_AS_STRING(self), ival, Py_SIZE(self)) != NULL;
|
return memchr(PyBytes_AS_STRING(self), ival, Py_SIZE(self)) != NULL;
|
||||||
|
@ -2345,12 +2345,12 @@ bytes_splitlines(PyObject *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, PyBytes_AS_STRING(self),
|
(PyObject*) self, PyBytes_AS_STRING(self),
|
||||||
PyBytes_GET_SIZE(self), keepends
|
PyBytes_GET_SIZE(self), keepends
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue