text
stringlengths
0
828
break_long = astyle['break_long']
body = _clean_newlines(body)
tmp_rows = [_wrap_row(row, max_col, break_long)
for row in body.split('\n')]
body_rows = []
for rows in tmp_rows:
if rows:
body_rows += rows
else:
body_rows.append('')
if not ''.join(body_rows).strip():
# Concrete empty body
body_rows = []
title = _clean_newlines(title)
tmp_rows = [_wrap_row(row, max_col, break_long)
for row in title.split('\n')]
title_rows = []
for rows in tmp_rows:
if rows:
title_rows += rows
else:
title_rows.append('')
if not ''.join(title_rows).strip():
# Concrete empty title
title_rows = []
max_col = max([len(row) for row in body_rows + title_rows] + [min_col])
mid_top_border_len = max_col + \
len(border[3]) + len(border[4]) - len(border[0]) - len(border[2])
mid_bottom_border_len = max_col + \
len(border[3]) + len(border[4]) - len(border[5]) - len(border[7])
top_border = border[0] + \
(border[1] * mid_top_border_len)[:mid_top_border_len] + border[2]
bottom_border = border[5] + \
(border[6] * mid_bottom_border_len)[:mid_bottom_border_len] + \
border[7]
if isinstance(horiz_sep, tuple) and len(horiz_sep) == 3:
horiz_line = horiz_sep[0] + \
(horiz_sep[1] * (max_col + 2))[:(max_col + 2)] + horiz_sep[2]
else:
horiz_line = border[3] + (horiz_sep * max_col)[:max_col] + border[4]
title_rows = [tab_str + border[3] + row +
' ' * (max_col - len(row)) +
border[4] for row in title_rows]
body_rows = [tab_str + border[3] + row +
' ' * (max_col - len(row)) + border[4] for row in body_rows]
ret = []
if top_border:
ret += [tab_str + top_border]
ret += title_rows
if title_rows or force_horiz:
ret += [tab_str + horiz_line]
ret += body_rows
if bottom_border:
ret += [tab_str + bottom_border]
return (prefix + '\n'.join(ret) + suffix).encode('utf-8')"
4199,"def wait_for_user(msg=""""):
""""""
Print MSG and a confirmation prompt.
Waiting for user's confirmation, unless silent '--yes-i-know'
command line option was used, in which case the function
returns immediately without printing anything.
""""""
if '--yes-i-know' in sys.argv:
return
print(msg)
try:
answer = raw_input(""Please confirm by typing 'Yes, I know!': "")
except KeyboardInterrupt:
print()
answer = ''
if answer != 'Yes, I know!':
sys.stderr.write(""ERROR: Aborted.\n"")
sys.exit(1)
return"
4200,"def guess_minimum_encoding(text, charsets=('ascii', 'latin1', 'utf8')):
""""""Try to guess the minimum charset that is able to represent.
Try to guess the minimum charset that is able to represent the given
text using the provided charsets. text is supposed to be encoded in utf8.
Returns (encoded_text, charset) where charset is the first charset
in the sequence being able to encode text.
Returns (text_in_utf8, 'utf8') in case no charset is able to encode text.
@note: If the input text is not in strict UTF-8, then replace any
non-UTF-8 chars inside it.
""""""
text_in_unicode = text.decode('utf8', 'replace')
for charset in charsets:
try:
return (text_in_unicode.encode(charset), charset)
except (UnicodeEncodeError, UnicodeDecodeError):
pass
return (text_in_unicode.encode('utf8'), 'utf8')"