[pypy-svn] r8675 - pypy/dist/pypy/tool
tismer at codespeak.net
tismer at codespeak.net
Fri Jan 28 18:48:02 CET 2005
Author: tismer
Date: Fri Jan 28 18:48:02 2005
New Revision: 8675
Added:
pypy/dist/pypy/tool/sourcetools.py
Log:
extracting a few helpers which I need in multiple
source generating applications
Added: pypy/dist/pypy/tool/sourcetools.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/tool/sourcetools.py Fri Jan 28 18:48:02 2005
@@ -0,0 +1,23 @@
+# a couple of support functions which
+# help with generating Python source.
+
+# this script is used for extracting
+# the information available for exceptions
+# via introspection.
+# The idea is to use it once to create
+# a template for a re-birth of exceptions.py
+
+def render_docstr(func, indent_str, q='"""', redo=True):
+ """render a docstring as a sequenceof lines """
+ doc = func.__doc__
+ if doc is None:
+ return []
+ doc = indent_str + q + doc.replace(q, "\\"+q) + q
+ doc2 = doc
+ if q in doc and redo:
+ doc2 = render_docstr(func, indent_str, "'''", False)
+ if not redo:
+ return doc # recursion case
+ doc = (doc, doc2)[len(doc2) < len(doc)]
+ return [line for line in doc.split('\n')]
+
More information about the Pypy-commit
mailing list