Skip to content

Commit 7b8c802

Browse files
committed
python-jsonschema#708 - Resolve CI style issues
With any luck, it will resolve the coverage issues, too.
1 parent f618b7f commit 7b8c802

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

jsonschema/cli.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,30 +80,46 @@ def _json_formatter(cls, x):
8080
return json.dumps(x, separators=(',\n', ': '), sort_keys=True)
8181

8282
def _message_end_chars(self, header=False):
83-
return self._MESSAGE_CORNER_CHARS if header is True else [self._MESSAGE_BAR_CHAR] * 2
83+
return self._MESSAGE_CORNER_CHARS if header is True \
84+
else [self._MESSAGE_BAR_CHAR] * 2
8485

85-
def _message_line(self, path, type, header=False):
86+
def _message_line_good_unicode(self, path, type, header=False):
87+
"""
88+
Message formatter for Python interpreters with good Unicode support.
89+
90+
TODO: Rename method when support for old Python no longer needed.
91+
"""
8692
begin_char, end_char = self._message_end_chars(header)
8793
return self._MESSAGE_FORMAT.format(begin_char, type, path) \
88-
.ljust(self._MESSAGE_MAX_LENGTH - 1, self._MESSAGE_BAR_CHAR) + end_char
94+
.ljust(self._MESSAGE_MAX_LENGTH - 1, self._MESSAGE_BAR_CHAR) + \
95+
end_char
8996

90-
if len(_MESSAGE_BAR_CHAR) != 1:
91-
# The code in this if-block is for Python interpreters that don't
92-
# treat multibyte Unicode characters as single characters.
93-
# E.g., some versions of Python 2.x. This block may be removed
94-
# when support for those interpreters is no longer needed.
97+
def _message_line_poor_unicode(self, path, type, header=False):
98+
"""
99+
Message formatter for Python interpreters with poor Unicode support.
95100
96-
_FORMAT_LENGTH = len(
97-
_MESSAGE_FORMAT.replace(_MESSAGE_BAR_CHAR, '.').format('.', '', '')) + 1
101+
TODO: Remove method when support for old Python no longer needed.
102+
"""
103+
begin_char, end_char = self._message_end_chars(header)
98104

99-
def _message_line(self, path, type, header=False):
100-
begin_char, end_char = self._message_end_chars(header)
105+
bar_length = self._MESSAGE_MAX_LENGTH - self._FORMAT_LENGTH - \
106+
len(type) - len(path)
101107

102-
bar_length = self._MESSAGE_MAX_LENGTH - len(type) - len(path) - self._FORMAT_LENGTH
108+
return self._MESSAGE_FORMAT.format(begin_char, type, path) + \
109+
self._MESSAGE_BAR_CHAR * bar_length + end_char
103110

104-
return self._MESSAGE_FORMAT.format(begin_char, type, path) + \
105-
self._MESSAGE_BAR_CHAR * bar_length + end_char
111+
if len(_MESSAGE_BAR_CHAR) != 1:
112+
# The code in this if-block is for Python interpreters that don't
113+
# treat multibyte Unicode characters as single characters.
114+
# E.g., most versions of Python 2.x.
115+
# TODO: Remove if-block when support for old Python no longer needed.
106116

117+
_message_line = _message_line_poor_unicode
118+
_FORMAT_LENGTH = len(
119+
_MESSAGE_FORMAT.replace(_MESSAGE_BAR_CHAR, '.')
120+
.format('.', '', '')) + 1
121+
else:
122+
_message_line = _message_line_good_unicode
107123

108124
def _error_msg(self, path, type, body):
109125
HEADER = self._message_line(path, type, header=True)

0 commit comments

Comments
 (0)