[svn r41655] Added list of possible exceptions for callables.

--HG--
branch : trunk
This commit is contained in:
guido 2007-03-29 22:57:16 +02:00
parent cd6471e71f
commit 1e7bb8ca99
2 changed files with 25 additions and 10 deletions

View File

@ -56,8 +56,8 @@ class H(html):
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 @@ class H(html):
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 H(html):
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 @@ class H(html):
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

View File

@ -412,6 +412,7 @@ class ApiPageBuilder(AbstractPageBuilder):
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 @@ class ApiPageBuilder(AbstractPageBuilder):
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 @@ class ApiPageBuilder(AbstractPageBuilder):
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 @@ class ApiPageBuilder(AbstractPageBuilder):
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)