Skip to content

Commit 3745891

Browse files
committed
Make critical parsing explicit. See ietf-tools#584
- Legacy-Id: 2828
1 parent 5dd4ef6 commit 3745891

6 files changed

Lines changed: 53 additions & 364 deletions

File tree

ietf/submit/forms.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,30 @@ def get_fieldsets(self):
7272
yield fieldset_dict
7373

7474
def clean_txt(self):
75-
parsed_info = PlainParser(self.cleaned_data['txt']).parse()
75+
if not self.cleaned_data['txt']:
76+
return None
77+
parsed_info = PlainParser(self.cleaned_data['txt']).critical_parse()
7678
if parsed_info.errors:
7779
raise forms.ValidationError(parsed_info.errors)
7880

7981
def clean_pdf(self):
80-
parsed_info = PDFParser(self.cleaned_data['pdf']).parse()
82+
if not self.cleaned_data['pdf']:
83+
return None
84+
parsed_info = PDFParser(self.cleaned_data['pdf']).critical_parse()
8185
if parsed_info.errors:
8286
raise forms.ValidationError(parsed_info.errors)
8387

8488
def clean_ps(self):
85-
parsed_info = PSParser(self.cleaned_data['ps']).parse()
89+
if not self.cleaned_data['ps']:
90+
return None
91+
parsed_info = PSParser(self.cleaned_data['ps']).critical_parse()
8692
if parsed_info.errors:
8793
raise forms.ValidationError(parsed_info.errors)
8894

8995
def clean_xml(self):
90-
parsed_info = XMLParser(self.cleaned_data['xml']).parse()
96+
if not self.cleaned_data['xml']:
97+
return None
98+
parsed_info = XMLParser(self.cleaned_data['xml']).critical_parse()
9199
if parsed_info.errors:
92100
raise forms.ValidationError(parsed_info.errors)
93101

ietf/submit/parsers/base.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,13 @@ def __init__(self, fd):
3636
self.fd = fd
3737
self.parsed_info = ParseInfo()
3838

39-
def parse(self):
40-
if not self.fd:
41-
return self.parsed_info
42-
for attr in dir(self):
43-
if attr.startswith('parse_critical_'):
44-
method = getattr(self, attr, None)
45-
if callable(method):
46-
method()
47-
# If some critical parsing has returned an error do not continue
48-
if self.parsed_info.errors:
49-
return self.parsed_info
50-
# Continue with non critical parsing, note that they also can return errors
51-
for attr in dir(self):
52-
if attr.startswith('parse_normal_'):
53-
method = getattr(self, attr, None)
54-
if callable(method):
55-
method()
39+
# If some error is found after this method invocation
40+
# no other file parsing is recommended
41+
def critical_parse(self):
42+
self.parse_invalid_chars_in_filename()
5643
return self.parsed_info
5744

58-
def parse_critical_000_invalid_chars_in_filename(self):
45+
def parse_invalid_chars_in_filename(self):
5946
name = self.fd.name
6047
regexp = re.compile(r'&|\|\/|;|\*|\s|\$')
6148
chars = regexp.findall(name)

ietf/submit/parsers/pdf_parser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33

44
class PDFParser(FileParser):
55

6-
def parse_critical_filename_extension(self):
6+
# If some error is found after this method invocation
7+
# no other file parsing is recommended
8+
def critical_parse(self):
9+
super(PDFParser, self).critical_parse()
10+
self.parse_filename_extension()
11+
return self.parsed_info
12+
13+
def parse_filename_extension(self):
714
if not self.fd.name.endswith('.pdf'):
815
self.parsed_info.add_error('Format of this document must be PDF')

0 commit comments

Comments
 (0)