[Python-checkins] r54820 - sandbox/trunk/pep0/pep0.py sandbox/trunk/pep0/test_pep0.py (original) (raw)
brett.cannon python-checkins at python.org
Sat Apr 14 02:33:00 CEST 2007
- Previous message: [Python-checkins] r54819 - peps/trunk/pep-3118.txt
- Next message: [Python-checkins] r54821 - sandbox/trunk/pep0/TODO
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: brett.cannon Date: Sat Apr 14 02:32:58 2007 New Revision: 54820
Modified: sandbox/trunk/pep0/pep0.py sandbox/trunk/pep0/test_pep0.py Log: Add support for author nicknames.
Modified: sandbox/trunk/pep0/pep0.py
--- sandbox/trunk/pep0/pep0.py (original) +++ sandbox/trunk/pep0/pep0.py Sat Apr 14 02:32:58 2007 @@ -1,5 +1,6 @@ """Auto-generate PEP 0 (PEP index). """ from future import with_statement +import authors import os import re
@@ -65,7 +66,7 @@ angled = r'(?P.+?) <.+?>' paren = r'.+? ((?P.+?))' simple = r'(?P[^,]+)'
- authors = []
- author_list = [] for regex in (angled, paren, simple): # Watch out for commas separating multiple names. regex += '(,\s+)?'
@@ -76,14 +77,15 @@ # separated by commas. author = match.group('author') if not author.partition(' ')[1] and author.endswith('.'):
prev_author = authors.pop()
prev_author = author_list.pop() author = ', '.join([prev_author, author])
authors.append(author)
author_list.append(author) else:
# If authors were found then stop searching.
if authors:
# If authors were found then stop searching as only expect one
# style of author citation.
if author_list: break
- return authors
- return author_list
def handle_csv(data): """Handle the Post-History.""" @@ -94,8 +96,8 @@ 'Post-History': handle_csv, }
-def last_name(full_name):
- """Find the last name of a full name.
+def last_name(full_name, nicknames={}):
"""Find the last name (or nickname) of a full name.
If no last name (e.g, 'Aahz') then return the full name. If there is a leading, lowercase portion to the last name (e.g., 'van' or 'von') then
@@ -103,6 +105,9 @@ comma, then drop the suffix.
"""
- nickname = nicknames.get(full_name)
- if nickname:
no_suffix = full_name.partition(',')[0] name_parts = no_suffix.split() part_count = len(name_parts) @@ -154,9 +159,11 @@ number = str(pep['PEP']).rjust(4) title = pep['Title'] authors_list = []return nickname
- authors = ', '.join(last_name(author) for author in pep['Author'])
- author_string = ', '.join(last_name(author, authors.nicknames)
output.write(" %s%s %s %s %s\n" %for author in pep['Author'])
(type_abbr, status_abbr, number, title.ljust(44), authors))
(type_abbr, status_abbr, number, title.ljust(44),
author_string))
if name == 'main':
Modified: sandbox/trunk/pep0/test_pep0.py
--- sandbox/trunk/pep0/test_pep0.py (original) +++ sandbox/trunk/pep0/test_pep0.py Sat Apr 14 02:32:58 2007 @@ -157,6 +157,17 @@ got = pep0.last_name(full_name) self.failUnlessEqual(got, expect)
- def test_author_nickname(self):
# Make sure nicknames are returned instead of last names when a
# nickname is available.
full_name = 'Guido van Rossum'
nickname = 'GvR'
last_name = 'van Rossum'
got = pep0.last_name(full_name, {full_name:nickname})
self.failUnlessEqual(got, nickname)
got = pep0.last_name(full_name, {'asdf':nickname})
self.failUnlessEqual(got, last_name)
def test_main(): test_support.run_unittest(
- Previous message: [Python-checkins] r54819 - peps/trunk/pep-3118.txt
- Next message: [Python-checkins] r54821 - sandbox/trunk/pep0/TODO
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]