From 53e453f72ede3b99fc36aca998ec78f8c186de1c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 18 Aug 2012 18:14:30 +1200 Subject: Use the new ODict get_first convenience function in a bunch of places. --- libmproxy/console/contentview.py | 18 ++++++++---------- libmproxy/console/flowview.py | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'libmproxy/console') diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index 4b934ed5..e5881b6b 100644 --- a/libmproxy/console/contentview.py +++ b/libmproxy/console/contentview.py @@ -50,11 +50,9 @@ class ViewAuto: prompt = ("auto", "a") content_types = [] def __call__(self, hdrs, content, limit): - ctype = hdrs.get("content-type") + ctype = hdrs.get_first("content-type") if ctype: - ctype = ctype[0] - ct = utils.parse_content_type(ctype) if ctype else None - if ct: + ct = utils.parse_content_type(ctype) if ctype else None ct = "%s/%s"%(ct[0], ct[1]) if ct in content_types_map: return content_types_map[ct][0](hdrs, content, limit) @@ -199,9 +197,9 @@ class ViewMultipart: prompt = ("multipart", "m") content_types = ["multipart/form-data"] def __call__(self, hdrs, content, limit): - v = hdrs.get("content-type") + v = hdrs.get_first("content-type") if v: - v = utils.parse_content_type(v[0]) + v = utils.parse_content_type(v) if not v: return boundary = v[2].get("boundary") @@ -363,12 +361,12 @@ def get_content_view(viewmode, hdrItems, content, limit, logfunc): hdrs = flow.ODictCaseless([list(i) for i in hdrItems]) - enc = hdrs.get("content-encoding") - if enc and enc[0] != "identity": - decoded = encoding.decode(enc[0], content) + enc = hdrs.get_first("content-encoding") + if enc and enc != "identity": + decoded = encoding.decode(enc, content) if decoded: content = decoded - msg.append("[decoded %s]"%enc[0]) + msg.append("[decoded %s]"%enc) try: ret = viewmode(hdrs, content, limit) # Third-party viewers can fail in unexpected ways... diff --git a/libmproxy/console/flowview.py b/libmproxy/console/flowview.py index a6ee41eb..0106e075 100644 --- a/libmproxy/console/flowview.py +++ b/libmproxy/console/flowview.py @@ -555,8 +555,8 @@ class FlowView(common.WWrap): elif key == "z": if conn: self.flow.backup() - e = conn.headers["content-encoding"] or ["identity"] - if e[0] != "identity": + e = conn.headers.get_first("content-encoding", "identity") + if e != "identity": conn.decode() else: self.master.prompt_onekey( -- cgit v1.2.3