[svn r41655] Added list of possible exceptions for callables.
--HG-- branch : trunk
This commit is contained in:
parent
cd6471e71f
commit
1e7bb8ca99
|
@ -56,8 +56,8 @@ class H(html):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class FunctionDescription(Description):
|
class FunctionDescription(Description):
|
||||||
def __init__(self, localname, argdesc, docstring, valuedesc, csource,
|
def __init__(self, localname, argdesc, docstring, valuedesc, excdesc,
|
||||||
callstack):
|
csource, callstack):
|
||||||
infoid = 'info_%s' % (localname.replace('.', '_dot_'),)
|
infoid = 'info_%s' % (localname.replace('.', '_dot_'),)
|
||||||
docstringid = 'docstring_%s' % (localname.replace('.', '_dot_'),)
|
docstringid = 'docstring_%s' % (localname.replace('.', '_dot_'),)
|
||||||
fd = H.FunctionDef(localname, argdesc,
|
fd = H.FunctionDef(localname, argdesc,
|
||||||
|
@ -68,7 +68,7 @@ class H(html):
|
||||||
infodiv = H.div(
|
infodiv = H.div(
|
||||||
H.Docstring(docstring or '*no docstring available*',
|
H.Docstring(docstring or '*no docstring available*',
|
||||||
id=docstringid),
|
id=docstringid),
|
||||||
H.FunctionInfo(valuedesc, csource, callstack,
|
H.FunctionInfo(valuedesc, excdesc, csource, callstack,
|
||||||
id=infoid, style="display: none"),
|
id=infoid, style="display: none"),
|
||||||
class_='funcdocinfo')
|
class_='funcdocinfo')
|
||||||
super(H.FunctionDescription, self).__init__(fd, infodiv)
|
super(H.FunctionDescription, self).__init__(fd, infodiv)
|
||||||
|
@ -81,8 +81,9 @@ class H(html):
|
||||||
class_=class_, **kwargs)
|
class_=class_, **kwargs)
|
||||||
|
|
||||||
class FunctionInfo(html.div):
|
class FunctionInfo(html.div):
|
||||||
def __init__(self, valuedesc, csource, callstack, **kwargs):
|
def __init__(self, valuedesc, excdesc, csource, callstack, **kwargs):
|
||||||
super(H.FunctionInfo, self).__init__(valuedesc, H.br(), csource,
|
super(H.FunctionInfo, self).__init__(valuedesc, H.br(), excdesc,
|
||||||
|
H.br(), csource,
|
||||||
callstack, class_='funcinfo',
|
callstack, class_='funcinfo',
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
@ -183,6 +184,13 @@ class H(html):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(H.ValueDescList, self).__init__(*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):
|
class ValueDescItem(html.li):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -412,6 +412,7 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
docstring = deindent(docstring)
|
docstring = deindent(docstring)
|
||||||
localname = func.__name__
|
localname = func.__name__
|
||||||
argdesc = get_param_htmldesc(self.linker, func)
|
argdesc = get_param_htmldesc(self.linker, func)
|
||||||
|
excdesc = self.build_exception_description(dotted_name)
|
||||||
valuedesc = self.build_callable_signature_description(dotted_name)
|
valuedesc = self.build_callable_signature_description(dotted_name)
|
||||||
|
|
||||||
sourcefile = inspect.getsourcefile(func)
|
sourcefile = inspect.getsourcefile(func)
|
||||||
|
@ -423,11 +424,9 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
colored = []
|
colored = []
|
||||||
if sourcefile and callable_source:
|
if sourcefile and callable_source:
|
||||||
enc = source_html.get_module_encoding(sourcefile)
|
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)
|
sep = get_linesep(callable_source)
|
||||||
org = callable_source.split(sep)
|
colored = [enumerate_and_color(callable_source.split(sep),
|
||||||
colored = [enumerate_and_color(org, firstlineno, enc)]
|
func.func_code.co_firstlineno, enc)]
|
||||||
relpath = get_rel_sourcepath(self.projroot, sourcefile, sourcefile)
|
relpath = get_rel_sourcepath(self.projroot, sourcefile, sourcefile)
|
||||||
text = 'source: %s' % (relpath,)
|
text = 'source: %s' % (relpath,)
|
||||||
if is_in_pkg:
|
if is_in_pkg:
|
||||||
|
@ -436,7 +435,7 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
csource = H.SourceSnippet(text, href, colored)
|
csource = H.SourceSnippet(text, href, colored)
|
||||||
cslinks = self.build_callsites(dotted_name)
|
cslinks = self.build_callsites(dotted_name)
|
||||||
snippet = H.FunctionDescription(localname, argdesc, docstring,
|
snippet = H.FunctionDescription(localname, argdesc, docstring,
|
||||||
valuedesc, csource, cslinks)
|
valuedesc, excdesc, csource, cslinks)
|
||||||
return snippet
|
return snippet
|
||||||
|
|
||||||
def build_class_view(self, dotted_name):
|
def build_class_view(self, dotted_name):
|
||||||
|
@ -697,6 +696,14 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
lst.append(name)
|
lst.append(name)
|
||||||
return lst
|
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):
|
def is_in_pkg(self, sourcefile):
|
||||||
return py.path.local(sourcefile).relto(self.projpath)
|
return py.path.local(sourcefile).relto(self.projpath)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue