Skip to content

Commit 8bc4cbb

Browse files
committed
fixed tests on all python versions
1 parent 2f1506b commit 8bc4cbb

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

progressbar/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@ def len_color(value):
2222
'''
2323
Return the length of `value` without ANSI escape codes
2424
25-
>>> len_color(u'\u001b[1234]abc')
26-
3
2725
>>> len_color(b'\u001b[1234]abc')
2826
3
27+
>>> len_color(u'\u001b[1234]abc')
28+
3
2929
>>> len_color('\u001b[1234]abc')
3030
3
3131
'''
32-
pattern = u'\u001b\\[.*?[@-~]'
3332
if isinstance(value, bytes):
33+
pattern = '\\\u001b\\[.*?[@-~]'
3434
pattern = pattern.encode()
3535
replace = b''
3636
assert isinstance(pattern, bytes)
3737
else:
38+
pattern = u'\x1b\\[.*?[@-~]'
3839
replace = ''
3940

4041
value = re.sub(pattern, replace, value)

progressbar/widgets.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,17 @@ def __call__(self, progress, data, width=None):
531531
else:
532532
fill = ''
533533

534-
return '%s%s' % (
535-
fill,
536-
self.markers[data['updates'] % len(self.markers)],
537-
)
534+
marker = self.markers[data['updates'] % len(self.markers)]
535+
536+
# Python 3 returns an int when indexing bytes
537+
if isinstance(marker, int): # pragma: no cover
538+
marker = bytes(marker)
539+
fill = fill.encode()
540+
else:
541+
# cast fill to the same type as marker
542+
fill = type(marker)(fill)
543+
544+
return fill + marker
538545

539546

540547
# Alias for backwards compatibility

0 commit comments

Comments
 (0)