[Python-checkins] r56008 - sandbox/trunk/pep0/pep0/constants.py sandbox/trunk/pep0/pep0/pep.py

brett.cannon python-checkins at python.org
Sun Jun 17 19:44:17 CEST 2007


Author: brett.cannon
Date: Sun Jun 17 19:44:13 2007
New Revision: 56008

Modified:
   sandbox/trunk/pep0/pep0/constants.py
   sandbox/trunk/pep0/pep0/pep.py
Log:
Update output so that title that go beyond the max title length (currently 44),
use textwrap.wrap to truncate to a shorter length and have an ellipsis tacked
on.


Modified: sandbox/trunk/pep0/pep0/constants.py
==============================================================================
--- sandbox/trunk/pep0/pep0/constants.py	(original)
+++ sandbox/trunk/pep0/pep0/constants.py	Sun Jun 17 19:44:13 2007
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
-column_format = ' %(type)1s%(status)1s %(number)4s  %(title)-44s %(authors)-s'
+title_length = 44
+column_format = (' %(type)1s%(status)1s %(number)4s  %(title)-' +
+                    str(title_length) + 's %(authors)-s')
 
 header = """PEP: 0
 Title: Index of Python Enhancement Proposals (PEPs)

Modified: sandbox/trunk/pep0/pep0/pep.py
==============================================================================
--- sandbox/trunk/pep0/pep0/pep.py	(original)
+++ sandbox/trunk/pep0/pep0/pep.py	Sun Jun 17 19:44:13 2007
@@ -2,6 +2,7 @@
 from . import constants
 
 import re
+import textwrap
 
 
 class PEP(object):
@@ -90,6 +91,8 @@
 
     def _parse_author(self, data):
         """Return a list of author names."""
+        # XXX Consider using email.utils.parseaddr (doesn't work with names
+        # lacking an email address.
         angled = r'(?P<author>.+?) <.+?>'
         paren = r'.+? \((?P<author>.+?)\)'
         simple = r'(?P<author>[^,]+)'
@@ -115,18 +118,40 @@
         return author_list
 
 
-    def __str__(self):
-        """Return the line entry for the PEP."""
-        pep_info = {'type': self.type_[0].upper(), 'number': str(self.number),
-                    'title': self.title}
+    @property
+    def type_abbr(self):
+        """Return the how the type is to be represented in the index."""
+        return self.type_[0].upper()
+
+
+    @property
+    def status_abbr(self):
+        """Return how the status should be represented in the index."""
         if self.status in ('Draft', 'Active'):
-            status_abbr = ' '
+            return ' '
         else:
-            status_abbr = self.status[0].upper()
-        pep_info['status'] = status_abbr
-        author_string = ', '.join(last_name(author, constants.nicknames)
-                                    for author in self.authors)
-        pep_info['authors'] = author_string
+            return self.status[0].upper()
+
+    @property
+    def author_abbr(self):
+        """Return the author list as a comma-separated with only last names."""
+        return ', '.join(last_name(author, constants.nicknames)
+                            for author in self.authors)
+
+    @property
+    def title_abbr(self):
+        """Shorten the title to be no longer than the max title length."""
+        if len(self.title) <= constants.title_length:
+            return self.title
+        wrapped_title = textwrap.wrap(self.title, constants.title_length - 4)
+        return wrapped_title[0] + ' ...'
+
+
+    def __str__(self):
+        """Return the line entry for the PEP."""
+        pep_info = {'type': self.type_abbr, 'number': str(self.number),
+                'title': self.title_abbr, 'status': self.status_abbr,
+                'authors': self.author_abbr}
         return constants.column_format % pep_info
 
 


More information about the Python-checkins mailing list