Skip to content

Commit aafd629

Browse files
committed
Added an option to ietf.utils.draft.Draft to pull document name from the source file name.
- Legacy-Id: 14089
1 parent f2668cf commit aafd629

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

ietf/utils/draft.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ def acronym_match(s, l):
125125

126126
class Draft():
127127

128-
def __init__(self, text, source):
128+
def __init__(self, text, source, name_from_source=False):
129129
assert isinstance(text, six.text_type)
130130
self.source = source
131131
self.rawtext = text
132+
self.name_from_source = name_from_source
132133

133134
text = re.sub(".\x08", "", text) # Get rid of inkribbon backspace-emphasis
134135
text = text.replace("\r\n", "\n") # Convert DOS to unix
@@ -164,8 +165,12 @@ def __init__(self, text, source):
164165
def _parse_draftname(self):
165166
draftname_regex = r"(draft-[a-z0-9-]*)-(\d\d)(\w|\.txt|\n|$)"
166167
draftname_match = re.search(draftname_regex, self.pages[0])
168+
if not draftname_match and self.name_from_source:
169+
draftname_match = re.search(draftname_regex, self.source)
167170
rfcnum_regex = r"(Re[qg]uests? [Ff]or Commm?ents?:? +|Request for Comments: RFC |RFC-|RFC )((# ?)?[0-9]+)( |,|\n|$)"
168171
rfcnum_match = re.search(rfcnum_regex, self.pages[0])
172+
if not rfcnum_match and self.name_from_source:
173+
rfcnum_match = re.search(rfcnum_regex, self.source)
169174
if draftname_match:
170175
return (draftname_match.group(1), draftname_match.group(2) )
171176
elif rfcnum_match:
@@ -286,6 +291,7 @@ def begpage(pages, page, newpage, line=None):
286291
page += [ line ]
287292
stripped += [ line ]
288293
pages, page, newpage = begpage(pages, page, newpage)
294+
_debug('pages: %s' % len(pages))
289295
return stripped, pages
290296

291297
# ----------------------------------------------------------------------
@@ -1172,7 +1178,10 @@ def getmeta(fn):
11721178

11731179
timestamp = time.strftime("%Y-%m-%dT%H:%M:%S+00:00", time.gmtime(os.stat(filename)[stat.ST_MTIME]))
11741180
with open(filename, 'rb') as file:
1175-
draft = Draft(file.read().decode('utf8'), filename)
1181+
try:
1182+
draft = Draft(file.read().decode('utf8'), filename)
1183+
except UnicodeDecodeError:
1184+
draft = Draft(file.read().decode('latin1'), filename)
11761185
#_debug("\n".join(draft.lines))
11771186

11781187
fields["eventdate"] = timestamp
@@ -1363,5 +1372,8 @@ def _main(outfile=sys.stdout):
13631372
except KeyboardInterrupt:
13641373
raise
13651374
except Exception, e:
1366-
_err(e)
1375+
if opt_debug:
1376+
raise
1377+
else:
1378+
_err(e)
13671379

0 commit comments

Comments
 (0)