[Zope-CVS] CVS: Products/Event - EventRegistry.py:1.3
Martijn Pieters
mj@zope.com
Fri, 20 Sep 2002 11:08:05 -0400
Update of /cvs-repository/Products/Event
In directory cvs.zope.org:/tmp/cvs-serv13184
Modified Files:
EventRegistry.py
Log Message:
New reindentDoc method to clean up docstrings pulled from Event Interfaces.
=== Products/Event/EventRegistry.py 1.2 => 1.3 ===
--- Products/Event/EventRegistry.py:1.2 Fri Sep 20 10:35:42 2002
+++ Products/Event/EventRegistry.py Fri Sep 20 11:08:04 2002
@@ -80,9 +80,36 @@
return
if description is None:
- description = interface.__doc__
+ description = reindentDocstring(interface.__doc__)
_registry[key] = {'interface': interface, 'title': title,
'description': description}
+
eventRegistry = EventRegistry()
+
+
+def reindentDocstring(doc):
+ """Remove indentation from docstring.
+
+ It is assumed that the first line is not indented, and that the first
+ non-blank line after that can be used to determine indentation for the whole
+ docstring, as is the case with this docstring. This will help preserve
+ indentation within the docstring itself.
+
+ """
+
+ lines = doc.splitlines()
+
+ if len(lines) == 1:
+ return doc
+
+ indent = None
+ for i in range(1, len(lines)):
+ if indent is None and lines[i].strip():
+ indent = len(lines[i]) - len(lines[i].lstrip())
+ lines[i] = lines[i][indent:]
+ elif indent:
+ lines[i] = lines[i][indent:]
+
+ return "\n".join(lines)