PEP 7 style for if/else in C

Add also a newline for readability in normalize_encoding().
This commit is contained in:
Victor Stinner 2016-09-02 12:12:23 +02:00
parent 65a5a47d79
commit 1a05d6c04d
3 changed files with 35 additions and 17 deletions

View file

@ -54,6 +54,7 @@ def normalize_encoding(encoding):
""" """
if isinstance(encoding, bytes): if isinstance(encoding, bytes):
encoding = str(encoding, "ascii") encoding = str(encoding, "ascii")
chars = [] chars = []
punct = False punct = False
for c in encoding: for c in encoding:

View file

@ -314,8 +314,9 @@ STRINGLIB(utf8_encoder)(PyObject *unicode,
else if (Py_UNICODE_IS_SURROGATE(ch)) { else if (Py_UNICODE_IS_SURROGATE(ch)) {
Py_ssize_t startpos, endpos, newpos; Py_ssize_t startpos, endpos, newpos;
Py_ssize_t k; Py_ssize_t k;
if (error_handler == _Py_ERROR_UNKNOWN) if (error_handler == _Py_ERROR_UNKNOWN) {
error_handler = get_error_handler(errors); error_handler = get_error_handler(errors);
}
startpos = i-1; startpos = i-1;
endpos = startpos+1; endpos = startpos+1;

View file

@ -316,20 +316,27 @@ typedef enum {
static _Py_error_handler static _Py_error_handler
get_error_handler(const char *errors) get_error_handler(const char *errors)
{ {
if (errors == NULL || strcmp(errors, "strict") == 0) if (errors == NULL || strcmp(errors, "strict") == 0) {
return _Py_ERROR_STRICT; return _Py_ERROR_STRICT;
if (strcmp(errors, "surrogateescape") == 0) }
if (strcmp(errors, "surrogateescape") == 0) {
return _Py_ERROR_SURROGATEESCAPE; return _Py_ERROR_SURROGATEESCAPE;
if (strcmp(errors, "replace") == 0) }
if (strcmp(errors, "replace") == 0) {
return _Py_ERROR_REPLACE; return _Py_ERROR_REPLACE;
if (strcmp(errors, "ignore") == 0) }
if (strcmp(errors, "ignore") == 0) {
return _Py_ERROR_IGNORE; return _Py_ERROR_IGNORE;
if (strcmp(errors, "backslashreplace") == 0) }
if (strcmp(errors, "backslashreplace") == 0) {
return _Py_ERROR_BACKSLASHREPLACE; return _Py_ERROR_BACKSLASHREPLACE;
if (strcmp(errors, "surrogatepass") == 0) }
if (strcmp(errors, "surrogatepass") == 0) {
return _Py_ERROR_SURROGATEPASS; return _Py_ERROR_SURROGATEPASS;
if (strcmp(errors, "xmlcharrefreplace") == 0) }
if (strcmp(errors, "xmlcharrefreplace") == 0) {
return _Py_ERROR_XMLCHARREFREPLACE; return _Py_ERROR_XMLCHARREFREPLACE;
}
return _Py_ERROR_OTHER; return _Py_ERROR_OTHER;
} }
@ -5636,36 +5643,45 @@ _PyUnicode_EncodeUTF16(PyObject *str,
if (kind == PyUnicode_4BYTE_KIND) { if (kind == PyUnicode_4BYTE_KIND) {
const Py_UCS4 *in = (const Py_UCS4 *)data; const Py_UCS4 *in = (const Py_UCS4 *)data;
const Py_UCS4 *end = in + len; const Py_UCS4 *end = in + len;
while (in < end) while (in < end) {
if (*in++ >= 0x10000) if (*in++ >= 0x10000) {
pairs++; pairs++;
}
}
} }
if (len > PY_SSIZE_T_MAX / 2 - pairs - (byteorder == 0)) if (len > PY_SSIZE_T_MAX / 2 - pairs - (byteorder == 0)) {
return PyErr_NoMemory(); return PyErr_NoMemory();
}
nsize = len + pairs + (byteorder == 0); nsize = len + pairs + (byteorder == 0);
v = PyBytes_FromStringAndSize(NULL, nsize * 2); v = PyBytes_FromStringAndSize(NULL, nsize * 2);
if (v == NULL) if (v == NULL) {
return NULL; return NULL;
}
/* output buffer is 2-bytes aligned */ /* output buffer is 2-bytes aligned */
assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(v), 2)); assert(_Py_IS_ALIGNED(PyBytes_AS_STRING(v), 2));
out = (unsigned short *)PyBytes_AS_STRING(v); out = (unsigned short *)PyBytes_AS_STRING(v);
if (byteorder == 0) if (byteorder == 0) {
*out++ = 0xFEFF; *out++ = 0xFEFF;
if (len == 0) }
if (len == 0) {
goto done; goto done;
}
if (kind == PyUnicode_1BYTE_KIND) { if (kind == PyUnicode_1BYTE_KIND) {
ucs1lib_utf16_encode((const Py_UCS1 *)data, len, &out, native_ordering); ucs1lib_utf16_encode((const Py_UCS1 *)data, len, &out, native_ordering);
goto done; goto done;
} }
if (byteorder < 0) if (byteorder < 0) {
encoding = "utf-16-le"; encoding = "utf-16-le";
else if (byteorder > 0) }
else if (byteorder > 0) {
encoding = "utf-16-be"; encoding = "utf-16-be";
else }
else {
encoding = "utf-16"; encoding = "utf-16";
}
pos = 0; pos = 0;
while (pos < len) { while (pos < len) {