Skip to content

Commit 494b3c7

Browse files
committed
Fix a problem with author extraction when a given name is the same as the surname.
- Legacy-Id: 3135
1 parent 3ece259 commit 494b3c7

1 file changed

Lines changed: 37 additions & 31 deletions

File tree

ietf/utils/draft.py

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import sys
4141
import time
4242

43-
version = "0.16"
43+
version = "0.19"
4444
program = os.path.basename(sys.argv[0])
4545
progdir = os.path.dirname(sys.argv[0])
4646

@@ -561,10 +561,7 @@ def extract_authors(self):
561561
else:
562562
fullname = author_match
563563
fullname = re.sub(" +", " ", fullname)
564-
if fullname.endswith(surname):
565-
given_names = fullname.replace(surname, "").strip()
566-
else:
567-
given_names, surname = fullname.rsplit(None, 1)
564+
given_names, surname = fullname.rsplit(None, 1)
568565
if " " in given_names:
569566
first, middle = given_names.split(None, 1)
570567
else:
@@ -574,7 +571,7 @@ def extract_authors(self):
574571
if suffix:
575572
fullname = fullname+" "+suffix
576573
if not " ".join([ n for n in names if n ]) == fullname:
577-
_err("Author tuple doesn't match text in draft: %s, %s" % (authors[i], fullname))
574+
_err("Author tuple doesn't match text in draft: %s: %s %s" % (authors[i], names, fullname))
578575
authors[i] = (fullname, first, middle, surname, suffix)
579576
#_debug( "Author: %s: %s" % (author_match, authors[author_match]))
580577
break
@@ -731,26 +728,10 @@ def get_refs(self):
731728

732729

733730
# ----------------------------------------------------------------------
734-
def _output(docname, fields):
735-
if opt_timestamp:
736-
sys.stdout.write("%s " % (fields["eventdate"]))
737-
sys.stdout.write("%s" % (docname.strip()))
738-
739-
def outputkey(key, fields):
740-
sys.stdout.write(" %s='%s'" % ( key.lower(), fields[key].strip().replace("\\", "\\\\" ).replace("'", "\\x27" ).replace("\n", "\\n")))
741-
742-
keys = fields.keys()
743-
keys.sort()
744-
for key in keys:
745-
if fields[key] and not key in ["eventdate", ]:
746-
outputkey(key, fields)
747-
sys.stdout.write("\n")
748731

749-
# ----------------------------------------------------------------------
750-
def _printmeta(timestamp, fn):
732+
def getmeta(fn):
751733
# Initial values
752734
fields = {}
753-
fields["eventdate"] = timestamp
754735
fields["eventsource"] = "draft"
755736

756737
if " " in fn or not fn.endswith(".txt"):
@@ -760,16 +741,14 @@ def _printmeta(timestamp, fn):
760741
if os.path.exists(fn):
761742
filename = fn
762743
fn = os.path.basename(fn)
744+
elif fn.lower().startswith('rfc'):
745+
filename = os.path.join("/www/tools.ietf.org/rfc", fn)
763746
else:
764747
filename = os.path.join("/www/tools.ietf.org/id", fn)
765748
if not os.path.exists(filename):
766749
_warn("Could not find file: '%s'" % (filename))
767750
return
768751

769-
if opt_trace:
770-
t = time.time()
771-
sys.stderr.write("%-58s" % fn[:-4])
772-
773752
timestamp = time.strftime("%Y-%m-%dT%H:%M:%S+00:00", time.gmtime(os.stat(filename)[stat.ST_MTIME]))
774753
text = _gettext(filename)
775754
draft = Draft(text)
@@ -794,16 +773,43 @@ def _printmeta(timestamp, fn):
794773
if abstract:
795774
fields["docabstract"] = abstract
796775

797-
_output(fields.get("doctag", fn[:-7]), fields)
776+
return fields
777+
778+
779+
# ----------------------------------------------------------------------
780+
def _output(docname, fields, outfile=sys.stdout):
781+
if opt_timestamp:
782+
outfile.write("%s " % (fields["eventdate"]))
783+
outfile.write("%s" % (os.path.basename(docname.strip())))
784+
785+
def outputkey(key, fields):
786+
outfile.write(" %s='%s'" % ( key.lower(), fields[key].strip().replace("\\", "\\\\" ).replace("'", "\\x27" ).replace("\n", "\\n")))
787+
788+
keys = fields.keys()
789+
keys.sort()
790+
for key in keys:
791+
if fields[key] and not key in ["eventdate", ]:
792+
outputkey(key, fields)
793+
outfile.write("\n")
794+
795+
# ----------------------------------------------------------------------
796+
def _printmeta(timestamp, fn, outfile=sys.stdout):
797+
if opt_trace:
798+
t = time.time()
799+
sys.stderr.write("%-58s" % fn[:-4])
800+
801+
fields = getmeta(fn)
802+
_output(fields.get("doctag", fn[:-7]), fields, outfile)
798803

799804
if opt_trace:
800805
sys.stderr.write("%5.1f\n" % ((time.time() - t)))
801806

807+
802808
# ----------------------------------------------------------------------
803809
# Main
804810
# ----------------------------------------------------------------------
805811

806-
def _main():
812+
def _main(outfile=sys.stdout):
807813
global opt_debug, opt_timestamp, opt_trace, files
808814
# set default values, if any
809815
# ----------------------------------------------------------------------
@@ -867,15 +873,15 @@ def _main():
867873
if basename.startswith("draft-"):
868874
draft = basename
869875
_debug( "** Processing '%s'" % draft)
870-
_printmeta(timestamp, draft)
876+
_printmeta(timestamp, file.name, outfile)
871877
else:
872878
for line in file:
873879
draft = line.strip()
874880
if draft.startswith("#"):
875881
continue
876882
if draft:
877883
_debug( "** Processing '%s'" % draft)
878-
_printmeta(timestamp, draft)
884+
_printmeta(timestamp, draft, outfile)
879885

880886
if __name__ == "__main__":
881887
try:

0 commit comments

Comments
 (0)