aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-05-29 11:14:46 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-05-29 11:14:46 +1200
commited415877d48251774012bd6aad4be91e9d558b79 (patch)
treee12a399c6df498f24aa5eeb9652dfaa90ab98dae /netlib
parent00426534982ab7fba5617ad6422c13483a8e6521 (diff)
parent7971dce2231bc32c25b962d425d8ad935568a699 (diff)
downloadmitmproxy-ed415877d48251774012bd6aad4be91e9d558b79.tar.gz
mitmproxy-ed415877d48251774012bd6aad4be91e9d558b79.tar.bz2
mitmproxy-ed415877d48251774012bd6aad4be91e9d558b79.zip
Merge branch 'master' into solidcore
Diffstat (limited to 'netlib')
-rw-r--r--netlib/http/cookies.py2
-rw-r--r--netlib/http/headers.py14
-rw-r--r--netlib/http/http1/assemble.py2
-rw-r--r--netlib/http/message.py18
-rw-r--r--netlib/http/request.py2
-rw-r--r--netlib/multidict.py1
-rw-r--r--netlib/socks.py2
-rw-r--r--netlib/tcp.py1
-rw-r--r--netlib/tutils.py3
-rw-r--r--netlib/version_check.py1
-rw-r--r--netlib/websockets/frame.py2
-rw-r--r--netlib/websockets/protocol.py26
-rw-r--r--netlib/wsgi.py10
13 files changed, 44 insertions, 40 deletions
diff --git a/netlib/http/cookies.py b/netlib/http/cookies.py
index 88c76870..2be93e18 100644
--- a/netlib/http/cookies.py
+++ b/netlib/http/cookies.py
@@ -3,7 +3,6 @@ import re
from email.utils import parsedate_tz, formatdate, mktime_tz
from netlib.multidict import ImmutableMultiDict
-from .. import odict
"""
A flexible module for cookie parsing and manipulation.
@@ -28,6 +27,7 @@ variants. Serialization follows RFC6265.
# TODO: Disallow LHS-only Cookie values
+
def _read_until(s, start, term):
"""
Read until one of the characters in term is reached.
diff --git a/netlib/http/headers.py b/netlib/http/headers.py
index 60d3f429..2caf8d51 100644
--- a/netlib/http/headers.py
+++ b/netlib/http/headers.py
@@ -14,12 +14,18 @@ from ..utils import always_bytes
# See also: http://lucumr.pocoo.org/2013/7/2/the-updated-guide-to-unicode/
if six.PY2: # pragma: no cover
- _native = lambda x: x
- _always_bytes = lambda x: x
+ def _native(x):
+ return x
+
+ def _always_bytes(x):
+ return x
else:
# While headers _should_ be ASCII, it's not uncommon for certain headers to be utf-8 encoded.
- _native = lambda x: x.decode("utf-8", "surrogateescape")
- _always_bytes = lambda x: always_bytes(x, "utf-8", "surrogateescape")
+ def _native(x):
+ return x.decode("utf-8", "surrogateescape")
+
+ def _always_bytes(x):
+ return always_bytes(x, "utf-8", "surrogateescape")
class Headers(MultiDict):
diff --git a/netlib/http/http1/assemble.py b/netlib/http/http1/assemble.py
index f06ad5a1..2f941877 100644
--- a/netlib/http/http1/assemble.py
+++ b/netlib/http/http1/assemble.py
@@ -1,9 +1,9 @@
from __future__ import absolute_import, print_function, division
from ... import utils
-import itertools
from ...exceptions import HttpException
+
def assemble_request(request):
if request.content is None:
raise HttpException("Cannot assemble flow with missing content")
diff --git a/netlib/http/message.py b/netlib/http/message.py
index 028f43a1..13d401a7 100644
--- a/netlib/http/message.py
+++ b/netlib/http/message.py
@@ -4,17 +4,23 @@ import warnings
import six
-from ..multidict import MultiDict
from .headers import Headers
from .. import encoding, utils
+from ..utils import always_bytes
if six.PY2: # pragma: no cover
- _native = lambda x: x
- _always_bytes = lambda x: x
+ def _native(x):
+ return x
+
+ def _always_bytes(x):
+ return x
else:
- # While the HTTP head _should_ be ASCII, it's not uncommon for certain headers to be utf-8 encoded.
- _native = lambda x: x.decode("utf-8", "surrogateescape")
- _always_bytes = lambda x: utils.always_bytes(x, "utf-8", "surrogateescape")
+ # While headers _should_ be ASCII, it's not uncommon for certain headers to be utf-8 encoded.
+ def _native(x):
+ return x.decode("utf-8", "surrogateescape")
+
+ def _always_bytes(x):
+ return always_bytes(x, "utf-8", "surrogateescape")
class MessageData(utils.Serializable):
diff --git a/netlib/http/request.py b/netlib/http/request.py
index 056a2d93..5a528bf2 100644
--- a/netlib/http/request.py
+++ b/netlib/http/request.py
@@ -1,14 +1,12 @@
from __future__ import absolute_import, print_function, division
import re
-import warnings
import six
from six.moves import urllib
from netlib import utils
from netlib.http import cookies
-from netlib.odict import ODict
from .. import encoding
from ..multidict import MultiDictView
from .headers import Headers
diff --git a/netlib/multidict.py b/netlib/multidict.py
index 8e657363..da482620 100644
--- a/netlib/multidict.py
+++ b/netlib/multidict.py
@@ -2,7 +2,6 @@ from __future__ import absolute_import, print_function, division
from abc import ABCMeta, abstractmethod
-from typing import Tuple, TypeVar
try:
from collections.abc import MutableMapping
diff --git a/netlib/socks.py b/netlib/socks.py
index 57ccd1be..675fa784 100644
--- a/netlib/socks.py
+++ b/netlib/socks.py
@@ -147,7 +147,7 @@ class UsernamePasswordAuth(object):
class UsernamePasswordAuthResponse(object):
- __slots__ = ("ver", "status")
+ __slots__ = ("ver", "status")
def __init__(self, ver, status):
self.ver = ver
diff --git a/netlib/tcp.py b/netlib/tcp.py
index 8e3ae65e..c7231dbb 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -71,6 +71,7 @@ sslversion_choices = {
"TLSv1_2": (SSL.TLSv1_2_METHOD, SSL_BASIC_OPTIONS),
}
+
class SSLKeyLogger(object):
def __init__(self, filename):
diff --git a/netlib/tutils.py b/netlib/tutils.py
index 18d632f0..b8a3bafc 100644
--- a/netlib/tutils.py
+++ b/netlib/tutils.py
@@ -91,8 +91,7 @@ class RaisesContext(object):
test_data = utils.Data(__name__)
# FIXME: Temporary workaround during repo merge.
-import os
-test_data.dirname = os.path.join(test_data.dirname,"..","test","netlib")
+test_data.dirname = os.path.join(test_data.dirname, "..", "test", "netlib")
def treq(**kwargs):
diff --git a/netlib/version_check.py b/netlib/version_check.py
index 8e05b458..63f3e876 100644
--- a/netlib/version_check.py
+++ b/netlib/version_check.py
@@ -10,7 +10,6 @@ import os.path
import six
import OpenSSL
-from . import version
PYOPENSSL_MIN_VERSION = (0, 15)
diff --git a/netlib/websockets/frame.py b/netlib/websockets/frame.py
index fce2c9d3..da5a97f3 100644
--- a/netlib/websockets/frame.py
+++ b/netlib/websockets/frame.py
@@ -14,7 +14,7 @@ from netlib import utils
MAX_16_BIT_INT = (1 << 16)
MAX_64_BIT_INT = (1 << 64)
-DEFAULT=object()
+DEFAULT = object()
OPCODE = utils.BiDi(
CONTINUE=0x00,
diff --git a/netlib/websockets/protocol.py b/netlib/websockets/protocol.py
index 1e95fa1c..101d5484 100644
--- a/netlib/websockets/protocol.py
+++ b/netlib/websockets/protocol.py
@@ -1,24 +1,23 @@
+"""
+Colleciton of utility functions that implement small portions of the RFC6455
+WebSockets Protocol Useful for building WebSocket clients and servers.
+Emphassis is on readabilty, simplicity and modularity, not performance or
+completeness
+This is a work in progress and does not yet contain all the utilites need to
+create fully complient client/servers #
+Spec: https://tools.ietf.org/html/rfc6455
-# Colleciton of utility functions that implement small portions of the RFC6455
-# WebSockets Protocol Useful for building WebSocket clients and servers.
-#
-# Emphassis is on readabilty, simplicity and modularity, not performance or
-# completeness
-#
-# This is a work in progress and does not yet contain all the utilites need to
-# create fully complient client/servers #
-# Spec: https://tools.ietf.org/html/rfc6455
+The magic sha that websocket servers must know to prove they understand
+RFC6455
+"""
-# The magic sha that websocket servers must know to prove they understand
-# RFC6455
from __future__ import absolute_import
import base64
import hashlib
import os
-import binascii
import six
from ..http import Headers
@@ -95,21 +94,18 @@ class WebsocketsProtocol(object):
upgrade="websocket"
)
-
@classmethod
def check_client_handshake(self, headers):
if headers.get("upgrade") != "websocket":
return
return headers.get("sec-websocket-key")
-
@classmethod
def check_server_handshake(self, headers):
if headers.get("upgrade") != "websocket":
return
return headers.get("sec-websocket-accept")
-
@classmethod
def create_server_nonce(self, client_nonce):
return base64.b64encode(hashlib.sha1(client_nonce + websockets_magic).digest())
diff --git a/netlib/wsgi.py b/netlib/wsgi.py
index d6dfae5d..cde562f8 100644
--- a/netlib/wsgi.py
+++ b/netlib/wsgi.py
@@ -1,15 +1,15 @@
from __future__ import (absolute_import, print_function, division)
-from io import BytesIO, StringIO
-import urllib
+
import time
import traceback
-
import six
+from io import BytesIO
from six.moves import urllib
from netlib.utils import always_bytes, native
from . import http, tcp
+
class ClientConn(object):
def __init__(self, address):
@@ -140,7 +140,7 @@ class WSGIAdaptor(object):
elif state["status"]:
raise AssertionError('Response already started')
state["status"] = status
- state["headers"] = http.Headers([[always_bytes(k), always_bytes(v)] for k,v in headers])
+ state["headers"] = http.Headers([[always_bytes(k), always_bytes(v)] for k, v in headers])
if exc_info:
self.error_page(soc, state["headers_sent"], traceback.format_tb(exc_info[2]))
state["headers_sent"] = True
@@ -154,7 +154,7 @@ class WSGIAdaptor(object):
write(i)
if not state["headers_sent"]:
write(b"")
- except Exception as e:
+ except Exception:
try:
s = traceback.format_exc()
errs.write(s.encode("utf-8", "replace"))