2
2
"""Mad Libs"""
3
3
4
4
import argparse
5
- import re
6
5
import sys
7
6
8
7
@@ -16,7 +15,7 @@ def get_args():
16
15
17
16
parser .add_argument ('file' ,
18
17
metavar = 'FILE' ,
19
- type = argparse .FileType ('r ' ),
18
+ type = argparse .FileType ('rt ' ),
20
19
help = 'Input file' )
21
20
22
21
parser .add_argument ('-i' ,
@@ -55,8 +54,7 @@ def main():
55
54
if had_placeholders :
56
55
print (text )
57
56
else :
58
- print (f'"{ args .file .name } " has no placeholders.' , file = sys .stderr )
59
- sys .exit (1 )
57
+ sys .exit (f'"{ args .file .name } " has no placeholders.' )
60
58
61
59
62
60
# --------------------------------------------------
@@ -65,15 +63,15 @@ def find_brackets(text):
65
63
66
64
start = text .index ('<' ) if '<' in text else - 1
67
65
stop = text .index ('>' ) if start >= 0 and '>' in text [start + 2 :] else - 1
68
- return (start , stop ) if start >= 0 and stop >= 0 else and balanced None
66
+ return (start , stop ) if start >= 0 and stop >= 0 else None
69
67
70
68
71
69
# --------------------------------------------------
72
70
def test_find_brackets ():
73
71
"""Test for finding angle brackets"""
74
72
75
- assert find_brackets ('' ) == None
76
- assert find_brackets ('<>' ) == None
73
+ assert find_brackets ('' ) is None
74
+ assert find_brackets ('<>' ) is None
77
75
assert find_brackets ('<x>' ) == (0 , 2 )
78
76
assert find_brackets ('foo <bar> baz' ) == (4 , 8 )
79
77
0 commit comments