mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 10:16:27 +00:00
py3++: iteritems
This commit is contained in:
parent
88d365cfe6
commit
6f902ffbb3
@ -2,6 +2,7 @@
|
|||||||
This inline script utilizes harparser.HAR from
|
This inline script utilizes harparser.HAR from
|
||||||
https://github.com/JustusW/harparser to generate a HAR log object.
|
https://github.com/JustusW/harparser to generate a HAR log object.
|
||||||
"""
|
"""
|
||||||
|
import six
|
||||||
from harparser import HAR
|
from harparser import HAR
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -111,7 +112,7 @@ def response(context, flow):
|
|||||||
|
|
||||||
# HAR timings are integers in ms, so we have to re-encode the raw timings to
|
# HAR timings are integers in ms, so we have to re-encode the raw timings to
|
||||||
# that format.
|
# that format.
|
||||||
timings = dict([(k, int(1000 * v)) for k, v in timings_raw.iteritems()])
|
timings = dict([(k, int(1000 * v)) for k, v in six.iteritems(timings_raw)])
|
||||||
|
|
||||||
# The full_time is the sum of all timings.
|
# The full_time is the sum of all timings.
|
||||||
# Timings set to -1 will be ignored as per spec.
|
# Timings set to -1 will be ignored as per spec.
|
||||||
|
@ -31,19 +31,19 @@
|
|||||||
~c CODE Response code.
|
~c CODE Response code.
|
||||||
rex Equivalent to ~u rex
|
rex Equivalent to ~u rex
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import, print_function
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import pyparsing as pp
|
import pyparsing as pp
|
||||||
|
|
||||||
|
|
||||||
class _Token:
|
class _Token(object):
|
||||||
|
|
||||||
def dump(self, indent=0, fp=sys.stdout):
|
def dump(self, indent=0, fp=sys.stdout):
|
||||||
print >> fp, "\t" * indent, self.__class__.__name__,
|
print("{spacing}{name}{expr}".format(
|
||||||
if hasattr(self, "expr"):
|
spacing="\t" * indent,
|
||||||
print >> fp, "(%s)" % self.expr,
|
name=self.__class__.__name__,
|
||||||
print >> fp
|
expr=getattr(self, "expr", "")
|
||||||
|
), file=fp)
|
||||||
|
|
||||||
|
|
||||||
class _Action(_Token):
|
class _Action(_Token):
|
||||||
@ -283,7 +283,7 @@ class FAnd(_Token):
|
|||||||
self.lst = lst
|
self.lst = lst
|
||||||
|
|
||||||
def dump(self, indent=0, fp=sys.stdout):
|
def dump(self, indent=0, fp=sys.stdout):
|
||||||
print >> fp, "\t" * indent, self.__class__.__name__
|
super(FAnd, self).dump(indent, fp)
|
||||||
for i in self.lst:
|
for i in self.lst:
|
||||||
i.dump(indent + 1, fp)
|
i.dump(indent + 1, fp)
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ class FOr(_Token):
|
|||||||
self.lst = lst
|
self.lst = lst
|
||||||
|
|
||||||
def dump(self, indent=0, fp=sys.stdout):
|
def dump(self, indent=0, fp=sys.stdout):
|
||||||
print >> fp, "\t" * indent, self.__class__.__name__
|
super(FOr, self).dump(indent, fp)
|
||||||
for i in self.lst:
|
for i in self.lst:
|
||||||
i.dump(indent + 1, fp)
|
i.dump(indent + 1, fp)
|
||||||
|
|
||||||
@ -311,7 +311,7 @@ class FNot(_Token):
|
|||||||
self.itm = itm[0]
|
self.itm = itm[0]
|
||||||
|
|
||||||
def dump(self, indent=0, fp=sys.stdout):
|
def dump(self, indent=0, fp=sys.stdout):
|
||||||
print >> fp, "\t" * indent, self.__class__.__name__
|
super(FNot, self).dump(indent, fp)
|
||||||
self.itm.dump(indent + 1, fp)
|
self.itm.dump(indent + 1, fp)
|
||||||
|
|
||||||
def __call__(self, f):
|
def __call__(self, f):
|
||||||
|
@ -5,6 +5,7 @@ import time
|
|||||||
import Queue
|
import Queue
|
||||||
|
|
||||||
import h2
|
import h2
|
||||||
|
import six
|
||||||
from h2.connection import H2Connection
|
from h2.connection import H2Connection
|
||||||
|
|
||||||
from netlib.tcp import ssl_read_select
|
from netlib.tcp import ssl_read_select
|
||||||
@ -172,7 +173,7 @@ class Http2Layer(Layer):
|
|||||||
if other_stream_id is not None:
|
if other_stream_id is not None:
|
||||||
other_conn.h2.safe_reset_stream(other_stream_id, event.error_code)
|
other_conn.h2.safe_reset_stream(other_stream_id, event.error_code)
|
||||||
elif isinstance(event, h2.events.RemoteSettingsChanged):
|
elif isinstance(event, h2.events.RemoteSettingsChanged):
|
||||||
new_settings = dict([(id, cs.new_value) for (id, cs) in event.changed_settings.iteritems()])
|
new_settings = dict([(id, cs.new_value) for (id, cs) in six.iteritems(event.changed_settings)])
|
||||||
other_conn.h2.safe_update_settings(new_settings)
|
other_conn.h2.safe_update_settings(new_settings)
|
||||||
elif isinstance(event, h2.events.ConnectionTerminated):
|
elif isinstance(event, h2.events.ConnectionTerminated):
|
||||||
# Do not immediately terminate the other connection.
|
# Do not immediately terminate the other connection.
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from netlib.utils import Serializable
|
from netlib.utils import Serializable
|
||||||
|
|
||||||
|
|
||||||
@ -23,7 +26,7 @@ class StateObject(Serializable):
|
|||||||
Retrieve object state.
|
Retrieve object state.
|
||||||
"""
|
"""
|
||||||
state = {}
|
state = {}
|
||||||
for attr, cls in self._stateobject_attributes.iteritems():
|
for attr, cls in six.iteritems(self._stateobject_attributes):
|
||||||
val = getattr(self, attr)
|
val = getattr(self, attr)
|
||||||
if hasattr(val, "get_state"):
|
if hasattr(val, "get_state"):
|
||||||
state[attr] = val.get_state()
|
state[attr] = val.get_state()
|
||||||
@ -36,7 +39,7 @@ class StateObject(Serializable):
|
|||||||
Load object state from data returned by a get_state call.
|
Load object state from data returned by a get_state call.
|
||||||
"""
|
"""
|
||||||
state = state.copy()
|
state = state.copy()
|
||||||
for attr, cls in self._stateobject_attributes.iteritems():
|
for attr, cls in six.iteritems(self._stateobject_attributes):
|
||||||
if state.get(attr) is None:
|
if state.get(attr) is None:
|
||||||
setattr(self, attr, state.pop(attr))
|
setattr(self, attr, state.pop(attr))
|
||||||
else:
|
else:
|
||||||
|
@ -67,6 +67,7 @@ like so::
|
|||||||
u'\u03b1'
|
u'\u03b1'
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import six
|
||||||
|
|
||||||
__ver_major__ = 0
|
__ver_major__ = 0
|
||||||
__ver_minor__ = 2
|
__ver_minor__ = 2
|
||||||
@ -172,7 +173,7 @@ def _rdumpq(q, size, value, encoding=None):
|
|||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
write("}")
|
write("}")
|
||||||
init_size = size = size + 1
|
init_size = size = size + 1
|
||||||
for (k, v) in value.iteritems():
|
for (k, v) in six.iteritems(value):
|
||||||
size = _rdumpq(q, size, v, encoding)
|
size = _rdumpq(q, size, v, encoding)
|
||||||
size = _rdumpq(q, size, k, encoding)
|
size = _rdumpq(q, size, k, encoding)
|
||||||
span = str(size - init_size)
|
span = str(size - init_size)
|
||||||
@ -236,7 +237,7 @@ def _gdumps(value, encoding):
|
|||||||
yield "]"
|
yield "]"
|
||||||
elif isinstance(value, (dict,)):
|
elif isinstance(value, (dict,)):
|
||||||
sub = []
|
sub = []
|
||||||
for (k, v) in value.iteritems():
|
for (k, v) in six.iteritems(value):
|
||||||
sub.extend(_gdumps(k))
|
sub.extend(_gdumps(k))
|
||||||
sub.extend(_gdumps(v))
|
sub.extend(_gdumps(v))
|
||||||
sub = "".join(sub)
|
sub = "".join(sub)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import six
|
||||||
import tornado.web
|
import tornado.web
|
||||||
import tornado.websocket
|
import tornado.websocket
|
||||||
import logging
|
import logging
|
||||||
@ -185,11 +187,11 @@ class FlowHandler(RequestHandler):
|
|||||||
def put(self, flow_id):
|
def put(self, flow_id):
|
||||||
flow = self.flow
|
flow = self.flow
|
||||||
flow.backup()
|
flow.backup()
|
||||||
for a, b in self.json.iteritems():
|
for a, b in six.iteritems(self.json):
|
||||||
|
|
||||||
if a == "request":
|
if a == "request":
|
||||||
request = flow.request
|
request = flow.request
|
||||||
for k, v in b.iteritems():
|
for k, v in six.iteritems(b):
|
||||||
if k in ["method", "scheme", "host", "path", "http_version"]:
|
if k in ["method", "scheme", "host", "path", "http_version"]:
|
||||||
setattr(request, k, str(v))
|
setattr(request, k, str(v))
|
||||||
elif k == "port":
|
elif k == "port":
|
||||||
@ -201,7 +203,7 @@ class FlowHandler(RequestHandler):
|
|||||||
|
|
||||||
elif a == "response":
|
elif a == "response":
|
||||||
response = flow.response
|
response = flow.response
|
||||||
for k, v in b.iteritems():
|
for k, v in six.iteritems(b):
|
||||||
if k == "msg":
|
if k == "msg":
|
||||||
response.msg = str(v)
|
response.msg = str(v)
|
||||||
elif k == "code":
|
elif k == "code":
|
||||||
@ -293,7 +295,7 @@ class Settings(RequestHandler):
|
|||||||
|
|
||||||
def put(self):
|
def put(self):
|
||||||
update = {}
|
update = {}
|
||||||
for k, v in self.json.iteritems():
|
for k, v in six.iteritems(self.json):
|
||||||
if k == "intercept":
|
if k == "intercept":
|
||||||
self.state.set_intercept(v)
|
self.state.set_intercept(v)
|
||||||
update[k] = v
|
update[k] = v
|
||||||
|
Loading…
Reference in New Issue
Block a user