16 from itertools
import takewhile
21 from .charwidth
import get_char_width
22 from .misc
import seq2str2
23 from .robottypes
import is_string
24 from .unic
import safe_str
28 MAX_ASSIGN_LENGTH = 200
32 _MAX_ERROR_LINE_LENGTH = 78
36 _ERROR_CUT_EXPLN =
' [ Message content over the limit has been removed. ]'
40 _TAGS_RE = re.compile(
r'\s*tags:(.*)', re.IGNORECASE)
44 if MAX_ERROR_LINES
is None:
46 lines = msg.splitlines()
48 if sum(lengths) <= MAX_ERROR_LINES:
52 return '\n'.join(start + [_ERROR_CUT_EXPLN] + end)
60 limit = MAX_ERROR_LINES // 2
61 for line, length
in zip(lines[:limit], lengths[:limit]):
62 if total + length >= limit:
72 available_lines = MAX_ERROR_LINES // 2 - used
73 available_chars = available_lines * _MAX_ERROR_LINE_LENGTH - 3
74 if len(line) > available_chars:
76 line = line[:available_chars] +
'...'
78 line =
'...' + line[-available_chars:]
87 lines, remainder = divmod(len(line), _MAX_ERROR_LINE_LENGTH)
88 return lines
if not remainder
else lines + 1
92 formatter = {
'$': safe_str,
'@': seq2str2,
'&': _dict_to_str}[variable[0]]
93 value = formatter(value)
96 return '%s = %s' % (variable, value)
101 return '{ %s }' %
' | '.join(
'%s=%s' % (
safe_str(k),
safe_str(d[k]))
for k
in d)
107 if len(value) > MAX_ASSIGN_LENGTH:
108 value = value[:MAX_ASSIGN_LENGTH] +
'...'
126 return text +
' ' * more
142 if os.path.exists(name):
143 return os.path.abspath(name), []
147 args = name[index+1:].split(name[index])
149 if os.path.exists(name):
150 name = os.path.abspath(name)
155 colon_index = name.find(
':')
157 if colon_index == 1
and name[2:3]
in (
'/',
'\\'):
158 colon_index = name.find(
':', colon_index+1)
159 semicolon_index = name.find(
';')
160 if colon_index == -1:
161 return semicolon_index
162 if semicolon_index == -1:
164 return min(colon_index, semicolon_index)
172 lines = doc.splitlines()
173 match = _TAGS_RE.match(lines[-1])
175 doc =
'\n'.join(lines[:-1]).rstrip()
176 tags = [tag.strip()
for tag
in match.group(1).split(
',')]
181 return inspect.getdoc(item)
or ''
188 lines = takewhile(
lambda line: line.strip(), doc.splitlines())
189 return linesep.join(lines)
def get_char_width(char)
A module to handle different character widths on the console.
def _cut_long_line(line, used, from_end)
def cut_long_message(msg)
def _count_virtual_line_length(line)
def _pad_width(text, width)
def split_args_from_name_or_path(name)
Split arguments embedded to name or path like Example:arg1:arg2.
def getshortdoc(doc_or_item, linesep='\n')
def _prune_excess_lines(lines, lengths, from_end=False)
def get_console_length(text)
def cut_assign_value(value)
def split_tags_from_doc(doc)
def format_assign_message(variable, value, cut_long=True)
def _lose_width(text, diff)
def _get_arg_separator_index_from_name_or_path(name)
def pad_console_length(text, width)
def _count_line_lengths(lines)