diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-06-03 12:06:36 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-06-03 12:06:36 +1200 |
commit | e60860e65d06d2b4452b7ea94902d79eed11d78c (patch) | |
tree | 91a635bef6421248fa63a26255b52a6e96f98631 /test/pathod | |
parent | 36383a6146d605879bf8c2834370b09f42bfec06 (diff) | |
download | mitmproxy-e60860e65d06d2b4452b7ea94902d79eed11d78c.tar.gz mitmproxy-e60860e65d06d2b4452b7ea94902d79eed11d78c.tar.bz2 mitmproxy-e60860e65d06d2b4452b7ea94902d79eed11d78c.zip |
Make tcp.Client.connect return a context manager that closes the connection
Diffstat (limited to 'test/pathod')
-rw-r--r-- | test/pathod/tutils.py | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/test/pathod/tutils.py b/test/pathod/tutils.py index e674812b..b9f38d86 100644 --- a/test/pathod/tutils.py +++ b/test/pathod/tutils.py @@ -88,11 +88,11 @@ class DaemonTests(object): ssl=self.ssl, fp=logfp, ) - c.connect() - if params: - path = path + "?" + urllib.urlencode(params) - resp = c.request("get:%s" % path) - return resp + with c.connect(): + if params: + path = path + "?" + urllib.urlencode(params) + resp = c.request("get:%s" % path) + return resp def get(self, spec): logfp = StringIO() @@ -101,9 +101,9 @@ class DaemonTests(object): ssl=self.ssl, fp=logfp, ) - c.connect() - resp = c.request("get:/p/%s" % urllib.quote(spec).encode("string_escape")) - return resp + with c.connect(): + resp = c.request("get:/p/%s" % urllib.quote(spec).encode("string_escape")) + return resp def pathoc( self, @@ -128,16 +128,16 @@ class DaemonTests(object): fp=logfp, use_http2=use_http2, ) - c.connect(connect_to) - ret = [] - for i in specs: - resp = c.request(i) - if resp: - ret.append(resp) - for frm in c.wait(): - ret.append(frm) - c.stop() - return ret, logfp.getvalue() + with c.connect(connect_to): + ret = [] + for i in specs: + resp = c.request(i) + if resp: + ret.append(resp) + for frm in c.wait(): + ret.append(frm) + c.stop() + return ret, logfp.getvalue() tmpdir = tutils.tmpdir |