Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _len_cell(self, cell):
"""Return the width of the cell
Special characters are taken into account to return the width of the
cell, such like newlines and tabs
"""
for attr in bcolors_public_props():
cell = cell.replace(getattr(bcolors, attr), '').replace(bcolors.ENDC,'')
cell_lines = cell.split('\n')
maxi = 0
for line in cell_lines:
length = 0
parts = line.split('\t')
for part, i in zip(parts, list(range(1, len(parts) + 1))):
for attr in bcolors_public_props():
part = part.replace(getattr(bcolors, attr), '')
length = length + len(part)
if i < len(parts):
length = (length//8 + 1) * 8
maxi = max(maxi, length)
return maxi
def _splitit(self, line, isheader):
"""Split each element of line to fit the column width
Each element is turned into a list, result of the wrapping of the
string to the desired width
"""
line_wrapped = []
for cell, width in zip(line, self._width):
array = []
original_cell = cell
lost_color = bcolors.WHITE
for attr in bcolors_public_props():
cell = cell.replace(
getattr(bcolors, attr), '').replace(bcolors.ENDC,'')
if cell.replace(bcolors.ENDC,'') != original_cell.replace(
bcolors.ENDC,'') and attr != 'ENDC':
if not lost_color:
lost_color = attr
for c in cell.split('\n'):
if type(c) is not str:
try:
c = str(c, 'utf')
except UnicodeDecodeError as strerror:
sys.stderr.write("UnicodeDecodeError exception for string '%s': %s\n" % (c, strerror))
c = str(c, 'utf', 'replace')
try:
array.extend(
[get_color_string(
getattr(bcolors, lost_color),x
) for x in textwrap.wrap(c, width)
def get_color_string(type, string):
end = bcolors.ENDC
if type == bcolors.WHITE:
end = ''
return '%s%s%s' % (type, string, end)
def get_color_string(type, string):
end = bcolors.ENDC
if type == bcolors.WHITE:
end = ''
return '%s%s%s' % (type, string, end)