Skip to content

Commit 101fe5f

Browse files
committed
When extracting meta-information from drafts, it is required that some data reside on the first page. Split unpaginated drafts into chunks so we can adhere better to this.
- Legacy-Id: 3083
1 parent fb1ee77 commit 101fe5f

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

ietf/utils/draft.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,16 @@ def __init__(self, text):
126126

127127
self.rawlines = self.text.split("\n")
128128
self.lines, self.pages = self._stripheaders()
129-
if not self.pages:
130-
self.pages = [ self.text ]
129+
130+
# Some things (such as the filename) has to be on the first page. If
131+
# we didn't get back a set of pages, only one single page with the
132+
# whole document, then we need to do an enforced page split in order
133+
# to limit later searches to the first page.
134+
if len(self.pages) <= 1:
135+
self.pages = []
136+
for pagestart in range(0, len(self.lines), 58):
137+
self.pages += [ "\n".join(self.lines[pagestart:pagestart+54]) ]
138+
131139
self.filename, self.revision = self._parse_draftname()
132140

133141
self._authors = None
@@ -723,18 +731,18 @@ def get_refs(self):
723731

724732

725733
# ----------------------------------------------------------------------
726-
def _output(fields):
734+
def _output(docname, fields):
727735
if opt_timestamp:
728736
sys.stdout.write("%s " % (fields["eventdate"]))
729-
sys.stdout.write("%s" % (fields["doctag"].strip()))
737+
sys.stdout.write("%s" % (docname.strip()))
730738

731739
def outputkey(key, fields):
732740
sys.stdout.write(" %s='%s'" % ( key.lower(), fields[key].strip().replace("\\", "\\\\" ).replace("'", "\\x27" ).replace("\n", "\\n")))
733741

734742
keys = fields.keys()
735743
keys.sort()
736744
for key in keys:
737-
if fields[key] and not key in ["doctag", "eventdate"]:
745+
if fields[key] and not key in ["eventdate", ]:
738746
outputkey(key, fields)
739747
sys.stdout.write("\n")
740748

@@ -768,7 +776,8 @@ def _printmeta(timestamp, fn):
768776
#_debug("\n".join(draft.lines))
769777

770778
fields["eventdate"] = timestamp
771-
fields["doctag"] = draft.filename or fn[:-7]
779+
if draft.filename:
780+
fields["doctag"] = draft.filename
772781
fields["docrev"] = draft.revision
773782

774783
fields["doctitle"] = draft.get_title()
@@ -785,7 +794,7 @@ def _printmeta(timestamp, fn):
785794
if abstract:
786795
fields["docabstract"] = abstract
787796

788-
_output(fields)
797+
_output(fields.get("doctag", fn[:-7]), fields)
789798

790799
if opt_trace:
791800
sys.stderr.write("%5.1f\n" % ((time.time() - t)))

0 commit comments

Comments
 (0)