Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/asn1crypto/_errors.py: 50%
14 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:28 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:28 +0000
1# coding: utf-8
3"""
4Exports the following items:
6 - unwrap()
7 - APIException()
8"""
10from __future__ import unicode_literals, division, absolute_import, print_function
12import re
13import textwrap
16class APIException(Exception):
17 """
18 An exception indicating an API has been removed from asn1crypto
19 """
21 pass
24def unwrap(string, *params):
25 """
26 Takes a multi-line string and does the following:
28 - dedents
29 - converts newlines with text before and after into a single line
30 - strips leading and trailing whitespace
32 :param string:
33 The string to format
35 :param *params:
36 Params to interpolate into the string
38 :return:
39 The formatted string
40 """
42 output = textwrap.dedent(string)
44 # Unwrap lines, taking into account bulleted lists, ordered lists and
45 # underlines consisting of = signs
46 if output.find('\n') != -1:
47 output = re.sub('(?<=\\S)\n(?=[^ \n\t\\d\\*\\-=])', ' ', output)
49 if params:
50 output = output % params
52 output = output.strip()
54 return output