@@ -80,30 +80,46 @@ def _json_formatter(cls, x):
80
80
return json .dumps (x , separators = (',\n ' , ': ' ), sort_keys = True )
81
81
82
82
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
84
85
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
+ """
86
92
begin_char , end_char = self ._message_end_chars (header )
87
93
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
89
96
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.
95
100
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 )
98
104
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 )
101
107
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
103
110
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.
106
116
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
107
123
108
124
def _error_msg (self , path , type , body ):
109
125
HEADER = self ._message_line (path , type , header = True )
0 commit comments