[py-svn] r41655 - py/trunk/py/apigen

guido at codespeak.net guido at codespeak.net
Thu Mar 29 22:57:17 CEST 2007


Author: guido
Date: Thu Mar 29 22:57:16 2007
New Revision: 41655

Modified:
   py/trunk/py/apigen/html.py
   py/trunk/py/apigen/htmlgen.py
Log:
Added list of possible exceptions for callables.


Modified: py/trunk/py/apigen/html.py
==============================================================================
--- py/trunk/py/apigen/html.py	(original)
+++ py/trunk/py/apigen/html.py	Thu Mar 29 22:57:16 2007
@@ -56,8 +56,8 @@
         pass
 
     class FunctionDescription(Description):
-        def __init__(self, localname, argdesc, docstring, valuedesc, csource,
-                     callstack):
+        def __init__(self, localname, argdesc, docstring, valuedesc, excdesc,
+                     csource, callstack):
             infoid = 'info_%s' % (localname.replace('.', '_dot_'),)
             docstringid = 'docstring_%s' % (localname.replace('.', '_dot_'),)
             fd = H.FunctionDef(localname, argdesc,
@@ -68,7 +68,7 @@
             infodiv = H.div(
                 H.Docstring(docstring or '*no docstring available*',
                             id=docstringid),
-                H.FunctionInfo(valuedesc, csource, callstack,
+                H.FunctionInfo(valuedesc, excdesc, csource, callstack,
                                id=infoid, style="display: none"),
                 class_='funcdocinfo')
             super(H.FunctionDescription, self).__init__(fd, infodiv)
@@ -81,8 +81,9 @@
                                                 class_=class_, **kwargs)
 
     class FunctionInfo(html.div):
-        def __init__(self, valuedesc, csource, callstack, **kwargs):
-            super(H.FunctionInfo, self).__init__(valuedesc, H.br(), csource,
+        def __init__(self, valuedesc, excdesc, csource, callstack, **kwargs):
+            super(H.FunctionInfo, self).__init__(valuedesc, H.br(), excdesc,
+                                                 H.br(), csource,
                                                  callstack, class_='funcinfo',
                                                  **kwargs)
     
@@ -183,6 +184,13 @@
         def __init__(self, *args, **kwargs):
             super(H.ValueDescList, self).__init__(*args, **kwargs)
 
+    class ExceptionDescList(html.ul):
+        def __init__(self, *args, **kwargs):
+            super(H.ExceptionDescList, self).__init__(*args, **kwargs)
+
+        def append(self, t):
+            super(H.ExceptionDescList, self).append(html.li(t))
+
     class ValueDescItem(html.li):
         pass
 

Modified: py/trunk/py/apigen/htmlgen.py
==============================================================================
--- py/trunk/py/apigen/htmlgen.py	(original)
+++ py/trunk/py/apigen/htmlgen.py	Thu Mar 29 22:57:16 2007
@@ -412,6 +412,7 @@
             docstring = deindent(docstring)
         localname = func.__name__
         argdesc = get_param_htmldesc(self.linker, func)
+        excdesc = self.build_exception_description(dotted_name)
         valuedesc = self.build_callable_signature_description(dotted_name)
 
         sourcefile = inspect.getsourcefile(func)
@@ -423,11 +424,9 @@
         colored = []
         if sourcefile and callable_source:
             enc = source_html.get_module_encoding(sourcefile)
-            tokenizer = source_color.Tokenizer(source_color.PythonSchema)
-            firstlineno = func.func_code.co_firstlineno
             sep = get_linesep(callable_source)
-            org = callable_source.split(sep)
-            colored = [enumerate_and_color(org, firstlineno, enc)]
+            colored = [enumerate_and_color(callable_source.split(sep),
+                                           func.func_code.co_firstlineno, enc)]
             relpath = get_rel_sourcepath(self.projroot, sourcefile, sourcefile)
             text = 'source: %s' % (relpath,)
             if is_in_pkg:
@@ -436,7 +435,7 @@
         csource = H.SourceSnippet(text, href, colored)
         cslinks = self.build_callsites(dotted_name)
         snippet = H.FunctionDescription(localname, argdesc, docstring,
-                                        valuedesc, csource, cslinks)
+                                        valuedesc, excdesc, csource, cslinks)
         return snippet
 
     def build_class_view(self, dotted_name):
@@ -697,6 +696,14 @@
             lst.append(name)
         return lst
 
+    def build_exception_description(self, dotted_name):
+        excs = self.dsa.get_function_exceptions(dotted_name)
+        excdesc = H.ExceptionDescList()
+        for exc in excs:
+            excdesc.append(exc)
+        ret = H.div(H.div('possible exceptions:'), excdesc)
+        return ret
+
     def is_in_pkg(self, sourcefile):
         return py.path.local(sourcefile).relto(self.projpath)
 


More information about the py-svn mailing list