aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy')
-rw-r--r--libmproxy/console.py16
-rw-r--r--libmproxy/controller.py12
-rw-r--r--libmproxy/dump.py4
-rw-r--r--libmproxy/filt.py2
-rw-r--r--libmproxy/flow.py13
-rw-r--r--libmproxy/proxy.py1
-rw-r--r--libmproxy/script.py3
-rw-r--r--libmproxy/utils.py38
8 files changed, 30 insertions, 59 deletions
diff --git a/libmproxy/console.py b/libmproxy/console.py
index 82ddc6d9..ac90bc54 100644
--- a/libmproxy/console.py
+++ b/libmproxy/console.py
@@ -16,9 +16,8 @@
import mailcap, mimetypes, tempfile, os, subprocess, glob, time
import os.path, sys
import cStringIO
-import urwid.raw_display
import urwid
-import controller, utils, filt, proxy, flow, encoding
+import controller, utils, filt, proxy, flow
VIEW_CUTOFF = 1024*100
EVENTLOG_SIZE = 500
@@ -96,7 +95,6 @@ def format_flow(f, focus, extended=False, padding=2):
txt.append("\n")
txt.append(("text", ts))
txt.append(" "*(padding+2))
- met = ""
if f.response:
txt.append(
@@ -384,7 +382,7 @@ class ConnectionView(WWrap):
cmd = [c, name]
self.master.ui.stop()
try:
- ret = subprocess.call(cmd)
+ subprocess.call(cmd)
except:
self.master.statusbar.message("Can't start editor: %s" % c)
self.master.ui.start()
@@ -902,7 +900,6 @@ class BodyPile(urwid.Pile):
# This is essentially a copypasta from urwid.Pile's keypress handler.
# So much for "closed for modification, but open for extension".
- maxcol = size[0]
item_rows = None
if len(size)==2:
item_rows = self.get_item_rows( size, focus=True )
@@ -1024,11 +1021,11 @@ class ConsoleMaster(flow.FlowMaster):
def _view_conn_binary(self, content):
txt = []
- for offset, hex, s in utils.hexdump(content[:VIEW_CUTOFF]):
+ for offset, hexa, s in utils.hexdump(content[:VIEW_CUTOFF]):
txt.append(urwid.Text([
("offset", offset),
" ",
- ("text", hex),
+ ("text", hexa),
" ",
("text", s),
]))
@@ -1070,7 +1067,6 @@ class ConsoleMaster(flow.FlowMaster):
]
def _find_pretty_view(self, content, hdrItems):
- txt = []
ctype = None
for i in hdrItems:
if i[0].lower() == "content-type":
@@ -1167,7 +1163,7 @@ class ConsoleMaster(flow.FlowMaster):
c = os.environ.get("PAGER") or os.environ.get("EDITOR")
cmd = [c, name]
self.ui.stop()
- ret = subprocess.call(cmd, shell=shell)
+ subprocess.call(cmd, shell=shell)
self.ui.start()
os.unlink(name)
@@ -1555,7 +1551,7 @@ class ConsoleMaster(flow.FlowMaster):
def loop(self):
changed = True
try:
- while not controller.exit:
+ while not controller.should_exit:
startloop = time.time()
if changed:
self.statusbar.redraw()
diff --git a/libmproxy/controller.py b/libmproxy/controller.py
index 6fed201f..e3d5c834 100644
--- a/libmproxy/controller.py
+++ b/libmproxy/controller.py
@@ -16,7 +16,7 @@
import sys
import Queue, threading
-exit = False
+should_exit = False
#begin nocover
@@ -36,7 +36,7 @@ class Msg:
self.acked = False
try:
masterq.put(self, timeout=3)
- while not exit:
+ while not should_exit:
try:
g = self.q.get(timeout=0.5)
except Queue.Empty:
@@ -84,7 +84,7 @@ class Master:
if self.server:
slave = Slave(self.masterq, self.server)
slave.start()
- while not exit:
+ while not should_exit:
self.tick(self.masterq)
self.shutdown()
@@ -97,8 +97,8 @@ class Master:
msg.ack()
def shutdown(self):
- global exit
- if not exit:
- exit = True
+ global should_exit
+ if not should_exit:
+ should_exit = True
if self.server:
self.server.shutdown()
diff --git a/libmproxy/dump.py b/libmproxy/dump.py
index 23c80452..86af8be5 100644
--- a/libmproxy/dump.py
+++ b/libmproxy/dump.py
@@ -1,4 +1,4 @@
-import sys, os, traceback
+import sys, os
import flow, filt, utils
class DumpError(Exception): pass
@@ -225,6 +225,6 @@ class DumpMaster(flow.FlowMaster):
return
try:
return flow.FlowMaster.run(self)
- except BaseException, v:
+ except BaseException:
self.shutdown()
raise
diff --git a/libmproxy/filt.py b/libmproxy/filt.py
index 40cf7358..c3de6c11 100644
--- a/libmproxy/filt.py
+++ b/libmproxy/filt.py
@@ -315,6 +315,6 @@ def parse(s):
return bnf.parseString(s, parseAll=True)[0]
except pp.ParseException:
return None
- except ValueError, e:
+ except ValueError:
return None
diff --git a/libmproxy/flow.py b/libmproxy/flow.py
index def52caa..090c539a 100644
--- a/libmproxy/flow.py
+++ b/libmproxy/flow.py
@@ -2,7 +2,7 @@
This module provides more sophisticated flow tracking. These match requests
with their responses, and provide filtering and interception facilities.
"""
-import subprocess, base64, sys, json, hashlib, Cookie, cookielib, copy
+import subprocess, sys, json, hashlib, Cookie, cookielib
import proxy, threading, netstring, filt
import controller, version
@@ -78,7 +78,6 @@ class ServerPlaybackState:
self.fmap = {}
for i in flows:
if i.response:
- h = self._hash(i)
l = self.fmap.setdefault(self._hash(i), [])
l.append(i)
@@ -150,7 +149,6 @@ class StickyCookieState:
def handle_request(self, f):
if f.match(self.flt):
- cs = []
for i in self.jar.keys():
match = [
cookielib.domain_match(i[0], f.request.host),
@@ -334,7 +332,7 @@ class Flow:
return c
-class State:
+class State(object):
def __init__(self):
self._flow_map = {}
self._flow_list = []
@@ -387,8 +385,11 @@ class State:
Add an error response to the state. Returns the matching flow, or
None if there isn't one.
"""
- f = self._flow_map.get(err.request) if err.request else None
- if not f:
+ if err.request:
+ f = self._flow_map.get(err.request)
+ if not f:
+ return None
+ else:
return None
f.error = err
if f.match(self._limit) and not f in self.view:
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 6707b65b..3ecd1f32 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -853,7 +853,6 @@ def certificate_option_group(parser):
def process_certificate_option_group(parser, options):
- conf = {}
if options.cert:
options.cert = os.path.expanduser(options.cert)
if not os.path.exists(options.cert):
diff --git a/libmproxy/script.py b/libmproxy/script.py
index 897ebb72..92563cde 100644
--- a/libmproxy/script.py
+++ b/libmproxy/script.py
@@ -5,10 +5,9 @@
convenience functions to make loading and returning data from scripts
simple.
"""
-import sys, base64
+import sys
import flow
-
#begin nocover
def load_flow():
"""
diff --git a/libmproxy/utils.py b/libmproxy/utils.py
index 3dbeb620..677d3b22 100644
--- a/libmproxy/utils.py
+++ b/libmproxy/utils.py
@@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import re, os, subprocess, datetime, textwrap, errno
+import re, os, subprocess, datetime, textwrap
import time, functools, copy, cgi
import json
@@ -145,31 +145,6 @@ def hexdump(s):
return parts
-def isStringLike(anobj):
- try:
- # Avoid succeeding expensively if anobj is large.
- anobj[:0]+''
- except:
- return 0
- else:
- return 1
-
-
-def isSequenceLike(anobj):
- """
- Is anobj a non-string sequence type (list, tuple, iterator, or
- similar)? Crude, but mostly effective.
- """
- if not hasattr(anobj, "next"):
- if isStringLike(anobj):
- return 0
- try:
- anobj[:0]
- except:
- return 0
- return 1
-
-
def try_del(dict, key):
try:
del dict[key]
@@ -207,7 +182,6 @@ class Headers:
def __setitem__(self, k, hdrs):
k = self._kconv(k)
- first = None
new = self._filter_lst(k, self.lst)
for i in hdrs:
new.append((k, i))
@@ -328,7 +302,7 @@ class Data:
if not os.path.exists(fullpath):
raise ValueError, "dataPath: %s does not exist."%fullpath
return fullpath
-data = Data(__name__)
+pkg_data = Data(__name__)
def dummy_ca(path):
@@ -353,7 +327,7 @@ def dummy_ca(path):
"req",
"-new",
"-x509",
- "-config", data.path("resources/ca.cnf"),
+ "-config", pkg_data.path("resources/ca.cnf"),
"-nodes",
"-days", CERT_EXPIRY,
"-out", path,
@@ -425,8 +399,10 @@ def dummy_cert(certdir, ca, commonname):
confpath = os.path.join(certdir, commonname + ".cnf")
reqpath = os.path.join(certdir, commonname + ".req")
- template = open(data.path("resources/cert.cnf")).read()
- f = open(confpath, "w").write(template%(dict(commonname=commonname)))
+ template = open(pkg_data.path("resources/cert.cnf")).read()
+ f = open(confpath, "w")
+ f.write(template%(dict(commonname=commonname)))
+ f.close()
if ca:
# Create a dummy signed certificate. Uses same key as the signing CA