def as_html(self, path=""):
        """
        Return a rendering of the current state in HTML.

        """
        if path not in self.top_level_links:
            raise StateError("Unknown path")

        header = """
        <html>
            <head>
                <title>VPC-router state</title>
            </head>
            <body>
                <h3>VPC-router state</h3>
                <hr>
                <font face="courier">
        """

        footer = """
                </font>
            </body>
        </html>
        """

        rep = self.get_state_repr(path)

        def make_links(rep):
            # Recursively create clickable links for _href elements
            for e, v in rep.items():
                if e == "_href":
                    v = '<a href=%s>%s</a>' % (v, v)
                    rep[e] = v
                else:
                    if type(v) == dict:
                        make_links(v)

        make_links(rep)

        rep_str_lines = json.dumps(rep, indent=4).split("\n")
        buf = []
        for l in rep_str_lines:
            # Replace leading spaces with '&nbsp;'
            num_spaces = len(l) - len(l.lstrip())
            l = "&nbsp;" * num_spaces + l[num_spaces:]
            buf.append(l)

        return "%s%s%s" % (header, "<br>\n".join(buf), footer)
def as_html ( self , path = "" ) : if path not in self . top_level_links : raise StateError ( "Unknown path" ) header = """
        <html>
            <head>
                <title>VPC-router state</title>
            </head>
            <body>
                <h3>VPC-router state</h3>
                <hr>
                <font face="courier">
        """ footer = """
                </font>
            </body>
        </html>
        """ rep = self . get_state_repr ( path ) def make_links ( rep ) : for e , v in rep . items ( ) : if e == "_href" : v = '<a href=%s>%s</a>' % ( v , v ) rep [ e ] = v else : if type ( v ) == dict : make_links ( v ) make_links ( rep ) rep_str_lines = json . dumps ( rep , indent = 4 ) . split ( "\n" ) buf = [ ] for l in rep_str_lines : num_spaces = len ( l ) - len ( l . lstrip ( ) ) l = "&nbsp;" * num_spaces + l [ num_spaces : ] buf . append ( l ) return "%s%s%s" % ( header , "<br>\n" . join ( buf ) , footer )
Return a rendering of the current state in HTML.