1717 from typing import Collection
1818except ImportError :
1919 from typing import Container , Generic , Sized , TypeVar
20+
2021 # Python 3.5
2122 # noinspection PyAbstractClass
2223 class Collection (Generic [TypeVar ('T_co' , covariant = True )], Container , Sized , Iterable ):
@@ -174,12 +175,12 @@ def _wrap_chunks(self, chunks):
174175 del chunks [- 1 ]
175176
176177 while chunks :
177- l = _wcswidth (chunks [- 1 ])
178+ length = _wcswidth (chunks [- 1 ])
178179
179180 # Can at least squeeze this chunk onto the current line.
180- if cur_len + l <= width :
181+ if cur_len + length <= width :
181182 cur_line .append (chunks .pop ())
182- cur_len += l
183+ cur_len += length
183184
184185 # Nope, this line is full.
185186 else :
@@ -197,19 +198,15 @@ def _wrap_chunks(self, chunks):
197198 del cur_line [- 1 ]
198199
199200 if cur_line :
200- if (self .max_lines is None or
201- len (lines ) + 1 < self .max_lines or
202- (not chunks or
203- self .drop_whitespace and
204- len (chunks ) == 1 and
205- not chunks [0 ].strip ()) and cur_len <= width ):
201+ if (self .max_lines is None or len (lines ) + 1 < self .max_lines
202+ or (not chunks or self .drop_whitespace and len (chunks ) == 1 and not chunks [0 ].strip ())
203+ and cur_len <= width ):
206204 # Convert current line back to a string and store it in
207205 # list of all lines (return value).
208206 lines .append (indent + '' .join (cur_line ))
209207 else :
210208 while cur_line :
211- if (cur_line [- 1 ].strip () and
212- cur_len + _wcswidth (self .placeholder ) <= width ):
209+ if cur_line [- 1 ].strip () and cur_len + _wcswidth (self .placeholder ) <= width :
213210 cur_line .append (self .placeholder )
214211 lines .append (indent + '' .join (cur_line ))
215212 break
@@ -218,8 +215,7 @@ def _wrap_chunks(self, chunks):
218215 else :
219216 if lines :
220217 prev_line = lines [- 1 ].rstrip ()
221- if (_wcswidth (prev_line ) + _wcswidth (self .placeholder ) <=
222- self .width ):
218+ if _wcswidth (prev_line ) + _wcswidth (self .placeholder ) <= self .width :
223219 lines [- 1 ] = prev_line + self .placeholder
224220 break
225221 lines .append (indent + self .placeholder .lstrip ())
@@ -233,7 +229,7 @@ def _translate_tabs(text: str) -> str:
233229 tabpos = text .find ('\t ' )
234230 while tabpos >= 0 :
235231 before_text = text [:tabpos ]
236- after_text = text [tabpos + 1 :]
232+ after_text = text [tabpos + 1 :]
237233 before_width = _wcswidth (before_text )
238234 tab_pad = TAB_WIDTH - (before_width % TAB_WIDTH )
239235 text = before_text + '{: <{width}}' .format ('' , width = tab_pad ) + after_text
@@ -351,25 +347,26 @@ def _pad_columns(text: str, pad_char: str, align: Union[ColumnAlignment, str], w
351347 """Returns a string padded out to the specified width"""
352348 text = _translate_tabs (text )
353349 display_width = _printable_width (text )
350+ diff = width - display_width
354351 if display_width >= width :
355352 return text
356353
357354 if align in (ColumnAlignment .AlignLeft , ColumnAlignment .AlignLeft .format_string ()):
358355 out_text = text
359- out_text += '{:{pad}<{width}}' .format ('' , pad = pad_char , width = width - display_width )
356+ out_text += '{:{pad}<{width}}' .format ('' , pad = pad_char , width = diff )
360357 elif align in (ColumnAlignment .AlignRight , ColumnAlignment .AlignRight .format_string ()):
361- out_text = '{:{pad}<{width}}' .format ('' , pad = pad_char , width = width - display_width )
358+ out_text = '{:{pad}<{width}}' .format ('' , pad = pad_char , width = diff )
362359 out_text += text
363360 elif align in (ColumnAlignment .AlignCenter , ColumnAlignment .AlignCenter .format_string ()):
364- lead_pad = int (( width - display_width ) / 2 )
365- tail_pad = width - display_width - lead_pad
361+ lead_pad = diff // 2
362+ tail_pad = diff - lead_pad
366363
367364 out_text = '{:{pad}<{width}}' .format ('' , pad = pad_char , width = lead_pad )
368365 out_text += text
369366 out_text += '{:{pad}<{width}}' .format ('' , pad = pad_char , width = tail_pad )
370367 else :
371368 out_text = text
372- out_text += '{:{pad}<{width}}' .format ('' , pad = pad_char , width = width - display_width )
369+ out_text += '{:{pad}<{width}}' .format ('' , pad = pad_char , width = diff )
373370
374371 return out_text
375372
@@ -565,7 +562,7 @@ def border_right_span(self, row_index: Union[int, None]) -> str:
565562 bg_reset = self .bg_reset if self .bg_reset is not None else TableColors .BG_RESET
566563 return bg_reset + '║'
567564
568- def col_divider_span (self , row_index : Union [int , None ]) -> str :
565+ def col_divider_span (self , row_index : Union [int , None ]) -> str :
569566 bg_reset = self .bg_reset if self .bg_reset is not None else TableColors .BG_RESET
570567 bg_primary = self .bg_primary if self .bg_primary is not None else TableColors .BG_RESET
571568 bg_alt = self .bg_alt if self .bg_alt is not None else TableColors .BG_COLOR_ROW
0 commit comments