diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-05-05 10:47:02 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-05-05 10:47:02 +1200 |
commit | f2bc58cdd2f2b9b0025a88c0faccf55e10b29353 (patch) | |
tree | 9353f4b78f4bf8ec1e6b4169155da084a2c05ea9 /test/tutils.py | |
parent | 08b2e2a6a98fd175e1b49d62dffde34e91c77b1c (diff) | |
download | mitmproxy-f2bc58cdd2f2b9b0025a88c0faccf55e10b29353.tar.gz mitmproxy-f2bc58cdd2f2b9b0025a88c0faccf55e10b29353.tar.bz2 mitmproxy-f2bc58cdd2f2b9b0025a88c0faccf55e10b29353.zip |
Add tcp.Reader.safe_read, use it in socks and websockets
safe_read is guaranteed to raise or return a byte string of the
requested length. It's particularly useful for implementing binary
protocols.
Diffstat (limited to 'test/tutils.py')
-rw-r--r-- | test/tutils.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/test/tutils.py b/test/tutils.py index ea30f59c..141979f8 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -1,7 +1,20 @@ -import tempfile, os, shutil +import cStringIO +import tempfile +import os +import shutil from contextlib import contextmanager from libpathod import utils +from netlib import tcp + + +def treader(bytes): + """ + Construct a tcp.Read object from bytes. + """ + fp = cStringIO.StringIO(bytes) + return tcp.Reader(fp) + @contextmanager def tmpdir(*args, **kwargs): |