fix circular imports

This commit is contained in:
Maximilian Hils 2015-09-02 20:56:19 +02:00
parent b4e0be9052
commit cc2a6a3919
2 changed files with 19 additions and 10 deletions

View File

@ -185,7 +185,8 @@ class FlowView(tabs.Tabs):
tuple(tuple(i) for i in conn.headers.lst), tuple(tuple(i) for i in conn.headers.lst),
conn.content, conn.content,
limit, limit,
isinstance(conn, HTTPRequest) isinstance(conn, HTTPRequest),
signals.add_event
) )
return (description, text_objects) return (description, text_objects)

View File

@ -14,7 +14,6 @@ import html2text
import netlib.utils import netlib.utils
from netlib import odict, encoding from netlib import odict, encoding
from .console import common, signals
from . import utils from . import utils
from .contrib import jsbeautifier from .contrib import jsbeautifier
from .contrib.wbxml.ASCommandResponse import ASCommandResponse from .contrib.wbxml.ASCommandResponse import ASCommandResponse
@ -40,6 +39,10 @@ else:
VIEW_CUTOFF = 1024 * 50 VIEW_CUTOFF = 1024 * 50
def format_keyvals(lst, key="key", val="text", indent=0):
raise NotImplementedError()
def _view_text(content, total, limit): def _view_text(content, total, limit):
""" """
Generates a body for a chunk of text. Generates a body for a chunk of text.
@ -227,7 +230,7 @@ class ViewURLEncoded:
def __call__(self, hdrs, content, limit): def __call__(self, hdrs, content, limit):
lines = netlib.utils.urldecode(content) lines = netlib.utils.urldecode(content)
if lines: if lines:
body = common.format_keyvals( body = format_keyvals(
[(k + ":", v) for (k, v) in lines], [(k + ":", v) for (k, v) in lines],
key = "header", key = "header",
val = "text" val = "text"
@ -246,7 +249,7 @@ class ViewMultipart:
r = [ r = [
urwid.Text(("highlight", "Form data:\n")), urwid.Text(("highlight", "Form data:\n")),
] ]
r.extend(common.format_keyvals( r.extend(format_keyvals(
v, v,
key = "header", key = "header",
val = "text" val = "text"
@ -396,7 +399,7 @@ class ViewImage:
clean.append( clean.append(
[netlib.utils.cleanBin(i[0]), netlib.utils.cleanBin(i[1])] [netlib.utils.cleanBin(i[0]), netlib.utils.cleanBin(i[1])]
) )
fmt = common.format_keyvals( fmt = format_keyvals(
clean, clean,
key = "header", key = "header",
val = "text" val = "text"
@ -508,9 +511,13 @@ def get(name):
return i return i
def get_content_view(viewmode, hdrItems, content, limit, is_request): def get_content_view(viewmode, hdrItems, content, limit, is_request, log=None):
""" """
Returns a (msg, body) tuple. Returns:
A (msg, body) tuple.
Raises:
ContentViewException, if the content view threw an error.
""" """
if not content: if not content:
if is_request: if is_request:
@ -531,9 +538,10 @@ def get_content_view(viewmode, hdrItems, content, limit, is_request):
ret = viewmode(hdrs, content, limit) ret = viewmode(hdrs, content, limit)
# Third-party viewers can fail in unexpected ways... # Third-party viewers can fail in unexpected ways...
except Exception: except Exception:
if log:
s = traceback.format_exc() s = traceback.format_exc()
s = "Content viewer failed: \n" + s s = "Content viewer failed: \n" + s
signals.add_event(s, "error") log(s, "error")
ret = None ret = None
if not ret: if not ret:
ret = get("Raw")(hdrs, content, limit) ret = get("Raw")(hdrs, content, limit)