Coverage for mt940/utils.py: 0%
19 statements
« prev ^ index » next coverage.py v7.2.7, created at 2025-03-01 10:17 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2025-03-01 10:17 +0000
1import enum
4def coalesce(*args):
5 '''
6 Return the first non-None argument
8 >>> coalesce()
10 >>> coalesce(0, 1)
11 0
12 >>> coalesce(None, 0)
13 0
14 '''
16 for arg in args:
17 if arg is not None:
18 return arg
21class Strip(enum.IntEnum):
22 NONE = 0
23 LEFT = 1
24 RIGHT = 2
25 BOTH = 3
28def join_lines(string, strip=Strip.BOTH):
29 '''
30 Join strings together and strip whitespace in between if needed
31 '''
32 lines = []
34 for line in string.splitlines():
35 if strip & Strip.RIGHT:
36 line = line.rstrip()
38 if strip & Strip.LEFT:
39 line = line.lstrip()
41 lines.append(line)
43 return ''.join(lines)