Kaydet (Commit) 0cb431c0 authored tarafından Eric Smith's avatar Eric Smith

Code layout changes for PEP 7 compliance.

üst 7b4beea0
...@@ -122,7 +122,8 @@ parse_internal_render_format_spec(PyObject *format_spec, ...@@ -122,7 +122,8 @@ parse_internal_render_format_spec(PyObject *format_spec,
format->align = ptr[1]; format->align = ptr[1];
format->fill_char = ptr[0]; format->fill_char = ptr[0];
ptr += 2; ptr += 2;
} else if (end-ptr >= 1 && is_alignment_token(ptr[0])) { }
else if (end-ptr >= 1 && is_alignment_token(ptr[0])) {
format->align = ptr[0]; format->align = ptr[0];
ptr++; ptr++;
} }
...@@ -245,17 +246,20 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign, ...@@ -245,17 +246,20 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign,
/* always put a + or - */ /* always put a + or - */
r->n_lsign = 1; r->n_lsign = 1;
r->lsign = (actual_sign == '-' ? '-' : '+'); r->lsign = (actual_sign == '-' ? '-' : '+');
} else if (format->sign == '(') { }
else if (format->sign == '(') {
if (actual_sign == '-') { if (actual_sign == '-') {
r->n_lsign = 1; r->n_lsign = 1;
r->lsign = '('; r->lsign = '(';
r->n_rsign = 1; r->n_rsign = 1;
r->rsign = ')'; r->rsign = ')';
} }
} else if (format->sign == ' ') { }
else if (format->sign == ' ') {
r->n_lsign = 1; r->n_lsign = 1;
r->lsign = (actual_sign == '-' ? '-' : ' '); r->lsign = (actual_sign == '-' ? '-' : ' ');
} else { }
else {
/* non specified, or the default (-) */ /* non specified, or the default (-) */
if (actual_sign == '-') { if (actual_sign == '-') {
r->n_lsign = 1; r->n_lsign = 1;
...@@ -266,12 +270,14 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign, ...@@ -266,12 +270,14 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign,
/* now the number of padding characters */ /* now the number of padding characters */
if (format->width == -1) { if (format->width == -1) {
/* no padding at all, nothing to do */ /* no padding at all, nothing to do */
} else { }
else {
/* see if any padding is needed */ /* see if any padding is needed */
if (r->n_lsign + n_digits + r->n_rsign >= format->width) { if (r->n_lsign + n_digits + r->n_rsign >= format->width) {
/* no padding needed, we're already bigger than the /* no padding needed, we're already bigger than the
requested width */ requested width */
} else { }
else {
/* determine which of left, space, or right padding is /* determine which of left, space, or right padding is
needed */ needed */
Py_ssize_t padding = format->width - (r->n_lsign + n_digits + r->n_rsign); Py_ssize_t padding = format->width - (r->n_lsign + n_digits + r->n_rsign);
...@@ -282,7 +288,8 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign, ...@@ -282,7 +288,8 @@ calc_number_widths(NumberFieldWidths *r, STRINGLIB_CHAR actual_sign,
else if (format->align == '^') { else if (format->align == '^') {
r->n_lpadding = padding / 2; r->n_lpadding = padding / 2;
r->n_rpadding = padding - r->n_lpadding; r->n_rpadding = padding - r->n_lpadding;
} else }
else
/* must be '=' */ /* must be '=' */
r->n_spadding = padding; r->n_spadding = padding;
} }
...@@ -365,7 +372,8 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format) ...@@ -365,7 +372,8 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format)
if (len > width) { if (len > width) {
width = len; width = len;
} }
} else { }
else {
/* not specified, use all of the chars and no more */ /* not specified, use all of the chars and no more */
width = len; width = len;
} }
...@@ -476,7 +484,8 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format) ...@@ -476,7 +484,8 @@ format_long_internal(PyObject *value, const InternalFormatSpec *format)
p = STRINGLIB_STR(result); p = STRINGLIB_STR(result);
p[0] = (Py_UNICODE) x; p[0] = (Py_UNICODE) x;
n_digits = len = 1; n_digits = len = 1;
} else { }
else {
int base; int base;
int format_leading_chars_to_skip; /* characters added by int format_leading_chars_to_skip; /* characters added by
PyNumber_ToBase that we PyNumber_ToBase that we
......
...@@ -400,7 +400,8 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs) ...@@ -400,7 +400,8 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs)
} }
Py_DECREF(key); Py_DECREF(key);
Py_INCREF(obj); Py_INCREF(obj);
} else { }
else {
/* look up in args */ /* look up in args */
obj = PySequence_GetItem(args, index); obj = PySequence_GetItem(args, index);
if (obj == NULL) { if (obj == NULL) {
...@@ -589,7 +590,8 @@ parse_field(SubString *str, SubString *field_name, SubString *format_spec, ...@@ -589,7 +590,8 @@ parse_field(SubString *str, SubString *field_name, SubString *format_spec,
return 1; return 1;
} else { }
else {
/* end of string, there's no format_spec or conversion */ /* end of string, there's no format_spec or conversion */
field_name->end = str->ptr; field_name->end = str->ptr;
return 1; return 1;
...@@ -682,7 +684,8 @@ MarkupIterator_next(MarkupIterator *self, int *is_markup, SubString *literal, ...@@ -682,7 +684,8 @@ MarkupIterator_next(MarkupIterator *self, int *is_markup, SubString *literal,
PyErr_SetString(PyExc_ValueError, "unmatched '{' in format"); PyErr_SetString(PyExc_ValueError, "unmatched '{' in format");
return 0; return 0;
} else { }
else {
/* literal text, read until the end of string, an escaped { or }, /* literal text, read until the end of string, an escaped { or },
or an unescaped { */ or an unescaped { */
while (self->str.ptr < self->str.end) { while (self->str.ptr < self->str.end) {
...@@ -715,7 +718,8 @@ MarkupIterator_next(MarkupIterator *self, int *is_markup, SubString *literal, ...@@ -715,7 +718,8 @@ MarkupIterator_next(MarkupIterator *self, int *is_markup, SubString *literal,
/* escaped } or {, skip it in the input */ /* escaped } or {, skip it in the input */
self->str.ptr++; self->str.ptr++;
self->in_markup = 0; self->in_markup = 0;
} else }
else
len--; len--;
} }
...@@ -795,7 +799,8 @@ output_markup(SubString *field_name, SubString *format_spec, ...@@ -795,7 +799,8 @@ output_markup(SubString *field_name, SubString *format_spec,
SubString_init(&expanded_format_spec, SubString_init(&expanded_format_spec,
STRINGLIB_STR(tmp), STRINGLIB_LEN(tmp)); STRINGLIB_STR(tmp), STRINGLIB_LEN(tmp));
actual_format_spec = &expanded_format_spec; actual_format_spec = &expanded_format_spec;
} else }
else
actual_format_spec = format_spec; actual_format_spec = format_spec;
if (render_field(fieldobj, actual_format_spec, output) == 0) if (render_field(fieldobj, actual_format_spec, output) == 0)
...@@ -838,10 +843,10 @@ do_markup(SubString *input, PyObject *args, PyObject *kwargs, ...@@ -838,10 +843,10 @@ do_markup(SubString *input, PyObject *args, PyObject *kwargs,
format_spec_needs_expanding, conversion, output, format_spec_needs_expanding, conversion, output,
args, kwargs, recursion_level)) args, kwargs, recursion_level))
return 0; return 0;
} else { }
else
if (!output_data(output, str.ptr, str.end-str.ptr)) if (!output_data(output, str.ptr, str.end-str.ptr))
return 0; return 0;
}
} }
return result; return result;
} }
...@@ -970,10 +975,10 @@ formatteriter_next(formatteriterobject *it) ...@@ -970,10 +975,10 @@ formatteriter_next(formatteriterobject *it)
/* all of the SubString objects point into it->str, so no /* all of the SubString objects point into it->str, so no
memory management needs to be done on them */ memory management needs to be done on them */
assert(0 <= result && result <= 2); assert(0 <= result && result <= 2);
if (result == 0 || result == 1) { if (result == 0 || result == 1)
/* if 0, error has already been set, if 1, iterator is empty */ /* if 0, error has already been set, if 1, iterator is empty */
return NULL; return NULL;
} else { else {
PyObject *is_markup_bool = NULL; PyObject *is_markup_bool = NULL;
PyObject *literal_str = NULL; PyObject *literal_str = NULL;
PyObject *field_name_str = NULL; PyObject *field_name_str = NULL;
...@@ -1004,12 +1009,14 @@ formatteriter_next(formatteriterobject *it) ...@@ -1004,12 +1009,14 @@ formatteriter_next(formatteriterobject *it)
if (conversion == '\0') { if (conversion == '\0') {
conversion_str = Py_None; conversion_str = Py_None;
Py_INCREF(conversion_str); Py_INCREF(conversion_str);
} else }
else
conversion_str = PyUnicode_FromUnicode(&conversion, conversion_str = PyUnicode_FromUnicode(&conversion,
1); 1);
if (conversion_str == NULL) if (conversion_str == NULL)
goto error; goto error;
} else { }
else {
/* only literal is returned */ /* only literal is returned */
literal_str = SubString_new_object(&literal); literal_str = SubString_new_object(&literal);
if (literal_str == NULL) if (literal_str == NULL)
...@@ -1139,10 +1146,10 @@ fieldnameiter_next(fieldnameiterobject *it) ...@@ -1139,10 +1146,10 @@ fieldnameiter_next(fieldnameiterobject *it)
result = FieldNameIterator_next(&it->it_field, &is_attr, result = FieldNameIterator_next(&it->it_field, &is_attr,
&idx, &name); &idx, &name);
if (result == 0 || result == 1) { if (result == 0 || result == 1)
/* if 0, error has already been set, if 1, iterator is empty */ /* if 0, error has already been set, if 1, iterator is empty */
return NULL; return NULL;
} else { else {
PyObject* result = NULL; PyObject* result = NULL;
PyObject* is_attr_obj = NULL; PyObject* is_attr_obj = NULL;
PyObject* obj = NULL; PyObject* obj = NULL;
...@@ -1242,7 +1249,7 @@ formatter_field_name_split(PyUnicodeObject *self) ...@@ -1242,7 +1249,7 @@ formatter_field_name_split(PyUnicodeObject *self)
&first, &first_idx, &it->it_field)) &first, &first_idx, &it->it_field))
goto error; goto error;
/* first becomes an integer, if possible, else a string */ /* first becomes an integer, if possible; else a string */
if (first_idx != -1) if (first_idx != -1)
first_obj = PyInt_FromSsize_t(first_idx); first_obj = PyInt_FromSsize_t(first_idx);
else else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment