Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/oscrypto/_errors.py: 92%
13 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:25 +0000
1# coding: utf-8
3"""
4Helper for formatting exception messages. Exports the following items:
6 - pretty_message()
7"""
9from __future__ import unicode_literals, division, absolute_import, print_function
11import re
12import textwrap
15__all__ = [
16 'pretty_message',
17]
20def pretty_message(string, *params):
21 """
22 Takes a multi-line string and does the following:
24 - dedents
25 - converts newlines with text before and after into a single line
26 - strips leading and trailing whitespace
28 :param string:
29 The string to format
31 :param *params:
32 Params to interpolate into the string
34 :return:
35 The formatted string
36 """
38 output = textwrap.dedent(string)
40 # Unwrap lines, taking into account bulleted lists, ordered lists and
41 # underlines consisting of = signs
42 if output.find('\n') != -1:
43 output = re.sub('(?<=\\S)\n(?=[^ \n\t\\d\\*\\-=])', ' ', output)
45 if params:
46 output = output % params
48 output = output.strip()
50 return output