diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-05-31 17:33:57 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-05-31 17:33:57 -0700 |
commit | 1dd078beb23aa0b483f945eed39c0136984f81a6 (patch) | |
tree | c21863e80e79f934c1744ad1e5851d2ef95c9087 /netlib/wsgi.py | |
parent | ebeda5e8d261bcdd8763ce4e634d534b0285527c (diff) | |
parent | 44fdcb4b8291a5be6738f32d6fde307af3f2034e (diff) | |
download | mitmproxy-1dd078beb23aa0b483f945eed39c0136984f81a6.tar.gz mitmproxy-1dd078beb23aa0b483f945eed39c0136984f81a6.tar.bz2 mitmproxy-1dd078beb23aa0b483f945eed39c0136984f81a6.zip |
Merge pull request #1182 from cortesi/netlibimports
Reorganise netlib imports according to Google Style Guide
Diffstat (limited to 'netlib/wsgi.py')
-rw-r--r-- | netlib/wsgi.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/netlib/wsgi.py b/netlib/wsgi.py index cde562f8..7661388b 100644 --- a/netlib/wsgi.py +++ b/netlib/wsgi.py @@ -6,8 +6,7 @@ import six from io import BytesIO from six.moves import urllib -from netlib.utils import always_bytes, native -from . import http, tcp +from netlib import http, tcp, utils class ClientConn(object): @@ -55,38 +54,38 @@ class WSGIAdaptor(object): self.app, self.domain, self.port, self.sversion = app, domain, port, sversion def make_environ(self, flow, errsoc, **extra): - path = native(flow.request.path, "latin-1") + path = utils.native(flow.request.path, "latin-1") if '?' in path: - path_info, query = native(path, "latin-1").split('?', 1) + path_info, query = utils.native(path, "latin-1").split('?', 1) else: path_info = path query = '' environ = { 'wsgi.version': (1, 0), - 'wsgi.url_scheme': native(flow.request.scheme, "latin-1"), + 'wsgi.url_scheme': utils.native(flow.request.scheme, "latin-1"), 'wsgi.input': BytesIO(flow.request.content or b""), 'wsgi.errors': errsoc, 'wsgi.multithread': True, 'wsgi.multiprocess': False, 'wsgi.run_once': False, 'SERVER_SOFTWARE': self.sversion, - 'REQUEST_METHOD': native(flow.request.method, "latin-1"), + 'REQUEST_METHOD': utils.native(flow.request.method, "latin-1"), 'SCRIPT_NAME': '', 'PATH_INFO': urllib.parse.unquote(path_info), 'QUERY_STRING': query, - 'CONTENT_TYPE': native(flow.request.headers.get('Content-Type', ''), "latin-1"), - 'CONTENT_LENGTH': native(flow.request.headers.get('Content-Length', ''), "latin-1"), + 'CONTENT_TYPE': utils.native(flow.request.headers.get('Content-Type', ''), "latin-1"), + 'CONTENT_LENGTH': utils.native(flow.request.headers.get('Content-Length', ''), "latin-1"), 'SERVER_NAME': self.domain, 'SERVER_PORT': str(self.port), - 'SERVER_PROTOCOL': native(flow.request.http_version, "latin-1"), + 'SERVER_PROTOCOL': utils.native(flow.request.http_version, "latin-1"), } environ.update(extra) if flow.client_conn.address: - environ["REMOTE_ADDR"] = native(flow.client_conn.address.host, "latin-1") + environ["REMOTE_ADDR"] = utils.native(flow.client_conn.address.host, "latin-1") environ["REMOTE_PORT"] = flow.client_conn.address.port for key, value in flow.request.headers.items(): - key = 'HTTP_' + native(key, "latin-1").upper().replace('-', '_') + key = 'HTTP_' + utils.native(key, "latin-1").upper().replace('-', '_') if key not in ('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'): environ[key] = value return environ @@ -140,7 +139,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([[utils.always_bytes(k), utils.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 |