Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
 def process_type_link(self, _type):
     # now we do simple type dispatching and provide a link in this case
     lst = []
     data = self.dsa.get_type_desc(_type)
     if not data:
         for i in _type.striter():
             if isinstance(i, str):
                 lst.append(i)
             else:
                 lst += self.process_type_link(i)
         return lst
     name, _desc_type, is_degenerated = data
     if not is_degenerated:
         linktarget = self.linker.get_lazyhref(name)
         lst.append(H.a(str(_type), href=linktarget))
     else:
         raise IOError('do not think we ever get here?')
         # we should provide here some way of linking to sourcegen directly
         lst.append(name)
     return lst
Пример #4
0
 def build_namespace_view(self, namespace_dotted_name, item_dotted_names):
     """ build the html for a namespace (module) """
     obj = get_obj(self.dsa, self.pkg, namespace_dotted_name)
     docstring = obj.__doc__
     snippet = H.NamespaceDescription(
         H.NamespaceDef(namespace_dotted_name),
         H.Docstring(docstring or '*no docstring available*')
     )
     for dotted_name in sorted(item_dotted_names):
         itemname = dotted_name.split('.')[-1]
         if (not is_navigateable(itemname) or
                 self.is_hidden_from_nav(dotted_name)):
             continue
         snippet.append(
             H.NamespaceItem(
                 H.a(itemname,
                     href=self.linker.get_lazyhref(dotted_name)
                 )
             )
         )
     return snippet