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 build_class_view(self, dotted_name): """ build the html for a class """ cls = get_obj(self.dsa, self.pkg, dotted_name) # XXX is this a safe check? try: sourcefile = inspect.getsourcefile(cls) except TypeError: sourcefile = None docstring = cls.__doc__ if docstring: docstring = deindent(docstring) if not hasattr(cls, '__name__'): clsname = 'instance of %s' % (cls.__class__.__name__,) else: clsname = cls.__name__ bases = self.build_bases(dotted_name) properties = self.build_properties(cls) methods = self.build_methods(dotted_name) if sourcefile is None: sourcelink = H.div('no source available') else: if sourcefile[-1] in ['o', 'c']: sourcefile = sourcefile[:-1] sourcelink = H.div(H.a('view source', href=self.linker.get_lazyhref(sourcefile))) snippet = H.ClassDescription( # XXX bases HTML H.ClassDef(clsname, bases, docstring, sourcelink, properties, methods), ) return snippet
def build_callable_signature_description(self, dotted_name): args, retval = self.dsa.get_function_signature(dotted_name) valuedesc = H.ValueDescList() for name, _type in args: valuedesc.append(self.build_sig_value_description(name, _type)) if retval: retval = self.process_type_link(retval) ret = H.div(H.div('arguments:'), valuedesc, H.div('return value:'), retval or 'None') return ret
def gen_traceback(self, dotted_name, call_site): tbtag = H.CallStackDescription() obj = self.dsa.get_obj(dotted_name) for frame in call_site: lineno = frame.lineno - frame.firstlineno source = frame.source sourcefile = frame.filename tokenizer = source_color.Tokenizer(source_color.PythonSchema) mangled = [] source = str(source) sep = get_linesep(source) for i, sline in enumerate(source.split(sep)): if i == lineno: l = '-> %s' % (sline,) else: l = ' %s' % (sline,) mangled.append(l) if sourcefile: relpath = get_rel_sourcepath(self.projpath, sourcefile, sourcefile) linktext = '%s - line %s' % (relpath, frame.lineno + 1) # skip py.code.Source objects and source files outside of the # package is_code_source = self._reg_source.match(sourcefile) if (not is_code_source and self.is_in_pkg(sourcefile) and py.path.local(sourcefile).check()): enc = source_html.get_module_encoding(sourcefile) href = self.linker.get_lazyhref(sourcefile) sourcelink = H.a(linktext, href=href) else: enc = 'latin-1' sourcelink = H.div(linktext) colored = [enumerate_and_color(mangled, frame.firstlineno, enc)] else: sourcelink = H.div('source unknown (%s)' % (sourcefile,)) colored = mangled[:] tbtag.append(sourcelink) tbtag.append(H.div(*colored)) return tbtag