# Path: wiremaps/web/json.py
# class JsonPage(rend.Page):
# 
#     flattenFactory = lambda self, *args: flat.flattenFactory(*args)
#     addSlash = True
# 
#     def renderHTTP(self, ctx):
#         request = inevow.IRequest(ctx)
#         if inevow.ICurrentSegments(ctx)[-1] != '':
#             request.redirect(request.URLPath().child(''))
#             return ''
#         request.setHeader("Content-Type",
#                           "application/json; charset=UTF-8")
#         d = defer.maybeDeferred(self.data_json, ctx, None)
#         d.addCallback(lambda x: self.render_json(ctx, x))
#         return d
# 
#     def render_json(self, ctx, data):
#         """Render the given data in a proper JSON string"""
# 
#         def sanitize(data, d=None):
#             """Nevow JSON serializer is not able to handle some types.
# 
#             We convert those types in proper types:
#              - string to unicode string
#              - PgSQL result set into list
#              - handling of deferreds
#             """
#             if type(data) in [list, tuple] or \
#                     (PgSQL and isinstance(data, PgSQL.PgResultSet)):
#                 return [sanitize(x, d) for x in data]
#             if PgSQL and isinstance(data, PgSQL.PgBooleanType):
#                 if data:
#                     return u"true"
#                 return u"false"
#             if type(data) == str:
#                 return unicode(data, errors='ignore')
#             if isinstance(data, rend.Fragment):
#                 io = StringIO()
#                 writer = io.write
#                 finisher = lambda result: io.getvalue()
#                 newctx = context.PageContext(parent=ctx, tag=data)
#                 data.rememberStuff(newctx)
#                 doc = data.docFactory.load()
#                 newctx = context.WovenContext(newctx, T.invisible[doc])
#                 fl = self.flattenFactory(doc, newctx, writer, finisher)
#                 fl.addCallback(sanitize, None)
#                 d.append(fl)
#                 return fl
#             if isinstance(data, defer.Deferred):
#                 if data.called:
#                     return sanitize(data.result)
#                 return data
#             if isinstance(data, failure.Failure):
#                 return unicode(
#                     "<span class='error'>An error occured (%s)</span>" % data.getErrorMessage(),
#                     errors='ignore')
#             return data
# 
#         def serialize(data):
#             return json.serialize(sanitize(data))
# 
#         d = []
#         data = sanitize(data, d)
#         d = defer.DeferredList(d)
#         d.addCallback(lambda x: serialize(data))
#         return d
# 
# Path: wiremaps/web/common.py
# class FragmentMixIn(rend.Fragment, RenderMixIn):
#     def __init__(self, dbpool, *args, **kwargs):
#         self.dbpool = dbpool
#         rend.Fragment.__init__(self, *args, **kwargs)


from twisted.internet import defer
from nevow import loaders, rend
from nevow import tags as T
from wiremaps.web.json import JsonPage
from wiremaps.web.common import FragmentMixIn
            detail = c(ctx, self.ip, self.index, self.dbpool)
            l.append(detail.collectDetails())
        d = defer.DeferredList(l, consumeErrors=True)
        d.addCallback(self.flattenList)
        return d

class PortRelatedDetails:
    """Return a list of port related details.

    This list is built from one SQL query. The result of this query is
    passed to C{render} method which should output a list of triple
    C{column, value, sort} where C{value} will be turned into a
    C{rend.Fragment}.
    """

    def __init__(self, ctx, ip, index, dbpool):
        self.ctx = ctx
        self.dbpool = dbpool
        self.ip = ip
        self.index = index

    def render(self, data):
        raise NotImplementedError

    def convertFragments(self, data):
        result = []
        if not data:
            return []
        for column, value, sort in data:
            result.append((column,

# Path: wiremaps/web/json.py
# class JsonPage(rend.Page):
# 
#     flattenFactory = lambda self, *args: flat.flattenFactory(*args)
#     addSlash = True
# 
#     def renderHTTP(self, ctx):
#         request = inevow.IRequest(ctx)
#         if inevow.ICurrentSegments(ctx)[-1] != '':
#             request.redirect(request.URLPath().child(''))
#             return ''
#         request.setHeader("Content-Type",
#                           "application/json; charset=UTF-8")
#         d = defer.maybeDeferred(self.data_json, ctx, None)
#         d.addCallback(lambda x: self.render_json(ctx, x))
#         return d
# 
#     def render_json(self, ctx, data):
#         """Render the given data in a proper JSON string"""
# 
#         def sanitize(data, d=None):
#             """Nevow JSON serializer is not able to handle some types.
# 
#             We convert those types in proper types:
#              - string to unicode string
#              - PgSQL result set into list
#              - handling of deferreds
#             """
#             if type(data) in [list, tuple] or \
#                     (PgSQL and isinstance(data, PgSQL.PgResultSet)):
#                 return [sanitize(x, d) for x in data]
#             if PgSQL and isinstance(data, PgSQL.PgBooleanType):
#                 if data:
#                     return u"true"
#                 return u"false"
#             if type(data) == str:
#                 return unicode(data, errors='ignore')
#             if isinstance(data, rend.Fragment):
#                 io = StringIO()
#                 writer = io.write
#                 finisher = lambda result: io.getvalue()
#                 newctx = context.PageContext(parent=ctx, tag=data)
#                 data.rememberStuff(newctx)
#                 doc = data.docFactory.load()
#                 newctx = context.WovenContext(newctx, T.invisible[doc])
#                 fl = self.flattenFactory(doc, newctx, writer, finisher)
#                 fl.addCallback(sanitize, None)
#                 d.append(fl)
#                 return fl
#             if isinstance(data, defer.Deferred):
#                 if data.called:
#                     return sanitize(data.result)
#                 return data
#             if isinstance(data, failure.Failure):
#                 return unicode(
#                     "<span class='error'>An error occured (%s)</span>" % data.getErrorMessage(),
#                     errors='ignore')
#             return data
# 
#         def serialize(data):
#             return json.serialize(sanitize(data))
# 
#         d = []
#         data = sanitize(data, d)
#         d = defer.DeferredList(d)
#         d.addCallback(lambda x: serialize(data))
#         return d
# 
# Path: wiremaps/web/common.py
# class FragmentMixIn(rend.Fragment, RenderMixIn):
#     def __init__(self, dbpool, *args, **kwargs):
#         self.dbpool = dbpool
#         rend.Fragment.__init__(self, *args, **kwargs)


# Path: wiremaps/web/ports.py
from twisted.internet import defer
from nevow import loaders, rend
from nevow import tags as T
from wiremaps.web.json import JsonPage
from wiremaps.web.common import FragmentMixIn

            detail = c(ctx, self.ip, self.index, self.dbpool)
            l.append(detail.collectDetails())
        d = defer.DeferredList(l, consumeErrors=True)
        d.addCallback(self.flattenList)
        return d

class PortRelatedDetails:
    """Return a list of port related details.

    This list is built from one SQL query. The result of this query is
    passed to C{render} method which should output a list of triple
    C{column, value, sort} where C{value} will be turned into a
    C{rend.Fragment}.
    """

    def __init__(self, ctx, ip, index, dbpool):
        self.ctx = ctx
        self.dbpool = dbpool
        self.ip = ip
        self.index = index

    def render(self, data):
        raise NotImplementedError

    def convertFragments(self, data):
        result = []
        if not data:
            return []
        for column, value, sort in data:
            result.append((column,

                           FragmentMixIn(self.dbpool,