fix: Ignore failure to extract text draft title unless it is needed (#5730)

* fix: Accept a Path as source for a PlaintextDraft

* fix: Guard against failure to extract PlaintextDraft title

* fix: Ignore failure to extract text draft title unless it is needed
This commit is contained in:
Jennifer Richards 2023-06-01 11:39:59 -03:00 committed by GitHub
parent 36b847b57a
commit 8d4780d304
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View file

@ -1213,11 +1213,9 @@ def process_submission_text(filename, revision):
f"Text Internet-Draft revision ({text_draft.revision}) "
f"disagrees with submission revision ({revision})"
)
title = _normalize_title(text_draft.get_title())
if not title:
# This test doesn't work well - the text_draft parser tends to grab "Abstract" as
# the title if there's an empty title.
raise SubmissionError("Could not extract a title from the text")
title = text_draft.get_title()
if title:
title = _normalize_title(title)
# Drops \r, \n, <, >. Based on get_draft_meta() behavior
trans_table = str.maketrans("", "", "\r\n<>")
@ -1233,7 +1231,7 @@ def process_submission_text(filename, revision):
return {
"filename": text_draft.filename,
"rev": text_draft.revision,
"title": _normalize_title(text_draft.get_title()),
"title": title,
"authors": authors,
"abstract": text_draft.get_abstract(),
"document_date": text_draft.get_creation_date(),
@ -1286,6 +1284,9 @@ def process_and_validate_submission(submission):
submission.title = text_metadata["title"]
submission.authors = text_metadata["authors"]
if not submission.title:
raise SubmissionError("Could not determine the title of the draft")
# Items always to get from text, even when XML is available
submission.abstract = text_metadata["abstract"]
submission.document_date = text_metadata["document_date"]

View file

@ -203,7 +203,7 @@ class PlaintextDraft(Draft):
"""
super().__init__()
assert isinstance(text, str)
self.source = source
self.source = str(source)
self.rawtext = text
self.name_from_source = name_from_source