From 39d90125b07e67109dfe3ce0030c43daf8f20dcd Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 29 Oct 2024 11:16:47 -0300 Subject: [PATCH 1/2] chore: remove get_draft_meta() - unused --- ietf/submit/utils.py | 64 -------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/ietf/submit/utils.py b/ietf/submit/utils.py index e6cbcb12f79..ee58fd388ff 100644 --- a/ietf/submit/utils.py +++ b/ietf/submit/utils.py @@ -770,70 +770,6 @@ def save_files(form): log.log("saved file %s" % name) return file_name -def get_draft_meta(form, saved_files): - authors = [] - file_name = saved_files - - if form.cleaned_data['xml']: - # Some meta-information, such as the page-count, can only - # be retrieved from the generated text file. Provide a - # parsed draft object to get at that kind of information. - file_name['txt'] = os.path.join(settings.IDSUBMIT_STAGING_PATH, '%s-%s.txt' % (form.filename, form.revision)) - file_size = os.stat(file_name['txt']).st_size - with io.open(file_name['txt']) as txt_file: - form.parsed_draft = PlaintextDraft(txt_file.read(), txt_file.name) - else: - file_size = form.cleaned_data['txt'].size - - if form.authors: - authors = form.authors - else: - # If we don't have an xml file, try to extract the - # relevant information from the text file - for author in form.parsed_draft.get_author_list(): - full_name, first_name, middle_initial, last_name, name_suffix, email, country, company = author - - name = full_name.replace("\n", "").replace("\r", "").replace("<", "").replace(">", "").strip() - - if email: - try: - validate_email(email) - except ValidationError: - email = "" - - def turn_into_unicode(s): - if s is None: - return "" - - if isinstance(s, str): - return s - else: - try: - return s.decode("utf-8") - except UnicodeDecodeError: - try: - return s.decode("latin-1") - except UnicodeDecodeError: - return "" - - name = turn_into_unicode(name) - email = turn_into_unicode(email) - company = turn_into_unicode(company) - - authors.append({ - "name": name, - "email": email, - "affiliation": company, - "country": country - }) - - if form.abstract: - abstract = form.abstract - else: - abstract = form.parsed_draft.get_abstract() - - return authors, abstract, file_name, file_size - def get_submission(form): # See if there is a Submission in state waiting-for-draft From 306b78f31d462ad36d1a3cedb87b9b998d0d71aa Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 29 Oct 2024 12:02:24 -0300 Subject: [PATCH 2/2] feat: limit line width for PlaintextDraft --- ietf/utils/draft.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ietf/utils/draft.py b/ietf/utils/draft.py index a1e79760ea5..5f8a5688fcf 100755 --- a/ietf/utils/draft.py +++ b/ietf/utils/draft.py @@ -194,18 +194,20 @@ def get_wordcount(self): class PlaintextDraft(Draft): - def __init__(self, text, source, name_from_source=False): + def __init__(self, text, source, name_from_source=False, max_line_width=100): """Initialize a Draft instance :param text: plaintext draft contents :param source: name of file containing the contents :param name_from_source: if True, fall back to source to determine draft name not found from text + :param max_line_width: (default 100) ignore contents of lines beyond this width """ super().__init__() assert isinstance(text, str) self.source = str(source) self.rawtext = text self.name_from_source = name_from_source + self.max_line_width = max_line_width text = re.sub(".\x08", "", text) # Get rid of inkribbon backspace-emphasis text = text.replace("\r\n", "\n") # Convert DOS to unix @@ -320,7 +322,7 @@ def begpage(pages, page, newpage, line=None): return pages, page, newpage for line in self.rawlines: linecount += 1 - line = line.rstrip() + line = line.rstrip()[:self.max_line_width] # source of lines used elsewhere in the class! if re.search(r"\[?page [0-9ivx]+\]?[ \t\f]*$", line, re.I): pages, page, newpage = endpage(pages, page, newpage, line) continue