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
|
||||
https://github.com/JustusW/harparser to generate a HAR log object.
|
||||
"""
|
||||
import six
|
||||
from harparser import HAR
|
||||
|
||||
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
|
||||
# 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.
|
||||
# Timings set to -1 will be ignored as per spec.
|
||||
|
@ -31,19 +31,19 @@
|
||||
~c CODE Response code.
|
||||
rex Equivalent to ~u rex
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function
|
||||
import re
|
||||
import sys
|
||||
import pyparsing as pp
|
||||
|
||||
|
||||
class _Token:
|
||||
|
||||
class _Token(object):
|
||||
def dump(self, indent=0, fp=sys.stdout):
|
||||
print >> fp, "\t" * indent, self.__class__.__name__,
|
||||
if hasattr(self, "expr"):
|
||||
print >> fp, "(%s)" % self.expr,
|
||||
print >> fp
|
||||
print("{spacing}{name}{expr}".format(
|
||||
spacing="\t" * indent,
|
||||
name=self.__class__.__name__,
|
||||
expr=getattr(self, "expr", "")
|
||||
), file=fp)
|
||||
|
||||
|
||||
class _Action(_Token):
|
||||
@ -283,7 +283,7 @@ class FAnd(_Token):
|
||||
self.lst = lst
|
||||
|
||||
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:
|
||||
i.dump(indent + 1, fp)
|
||||
|
||||
@ -297,7 +297,7 @@ class FOr(_Token):
|
||||
self.lst = lst
|
||||
|
||||
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:
|
||||
i.dump(indent + 1, fp)
|
||||
|
||||
@ -311,7 +311,7 @@ class FNot(_Token):
|
||||
self.itm = itm[0]
|
||||
|
||||
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)
|
||||
|
||||
def __call__(self, f):
|
||||
|
@ -5,6 +5,7 @@ import time
|
||||
import Queue
|
||||
|
||||
import h2
|
||||
import six
|
||||
from h2.connection import H2Connection
|
||||
|
||||
from netlib.tcp import ssl_read_select
|
||||
@ -172,7 +173,7 @@ class Http2Layer(Layer):
|
||||
if other_stream_id is not None:
|
||||
other_conn.h2.safe_reset_stream(other_stream_id, event.error_code)
|
||||
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)
|
||||
elif isinstance(event, h2.events.ConnectionTerminated):
|
||||
# Do not immediately terminate the other connection.
|
||||
|
@ -1,4 +1,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
|
||||
from netlib.utils import Serializable
|
||||
|
||||
|
||||
@ -23,7 +26,7 @@ class StateObject(Serializable):
|
||||
Retrieve object state.
|
||||
"""
|
||||
state = {}
|
||||
for attr, cls in self._stateobject_attributes.iteritems():
|
||||
for attr, cls in six.iteritems(self._stateobject_attributes):
|
||||
val = getattr(self, attr)
|
||||
if hasattr(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.
|
||||
"""
|
||||
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:
|
||||
setattr(self, attr, state.pop(attr))
|
||||
else:
|
||||
|
@ -67,6 +67,7 @@ like so::
|
||||
u'\u03b1'
|
||||
|
||||
"""
|
||||
import six
|
||||
|
||||
__ver_major__ = 0
|
||||
__ver_minor__ = 2
|
||||
@ -172,7 +173,7 @@ def _rdumpq(q, size, value, encoding=None):
|
||||
if isinstance(value, dict):
|
||||
write("}")
|
||||
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, k, encoding)
|
||||
span = str(size - init_size)
|
||||
@ -236,7 +237,7 @@ def _gdumps(value, encoding):
|
||||
yield "]"
|
||||
elif isinstance(value, (dict,)):
|
||||
sub = []
|
||||
for (k, v) in value.iteritems():
|
||||
for (k, v) in six.iteritems(value):
|
||||
sub.extend(_gdumps(k))
|
||||
sub.extend(_gdumps(v))
|
||||
sub = "".join(sub)
|
||||
|
@ -1,5 +1,7 @@
|
||||
import os.path
|
||||
import re
|
||||
|
||||
import six
|
||||
import tornado.web
|
||||
import tornado.websocket
|
||||
import logging
|
||||
@ -185,11 +187,11 @@ class FlowHandler(RequestHandler):
|
||||
def put(self, flow_id):
|
||||
flow = self.flow
|
||||
flow.backup()
|
||||
for a, b in self.json.iteritems():
|
||||
for a, b in six.iteritems(self.json):
|
||||
|
||||
if a == "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"]:
|
||||
setattr(request, k, str(v))
|
||||
elif k == "port":
|
||||
@ -201,7 +203,7 @@ class FlowHandler(RequestHandler):
|
||||
|
||||
elif a == "response":
|
||||
response = flow.response
|
||||
for k, v in b.iteritems():
|
||||
for k, v in six.iteritems(b):
|
||||
if k == "msg":
|
||||
response.msg = str(v)
|
||||
elif k == "code":
|
||||
@ -293,7 +295,7 @@ class Settings(RequestHandler):
|
||||
|
||||
def put(self):
|
||||
update = {}
|
||||
for k, v in self.json.iteritems():
|
||||
for k, v in six.iteritems(self.json):
|
||||
if k == "intercept":
|
||||
self.state.set_intercept(v)
|
||||
update[k] = v
|
||||
|
Loading…
Reference in New Issue
Block a user