diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-07-25 13:31:04 +0200 |
---|---|---|
committer | Thomas Kriechbaumer <thomas@kriechbaumer.name> | 2015-08-18 21:08:01 +0200 |
commit | 62416daa4a3776563556fb45ef9bd749fb44c334 (patch) | |
tree | f3006adad3e4a4986245402668e77d669a31aa0b /netlib | |
parent | c92dc1b8682ed15b68890f18c65b3f31122e9fa4 (diff) | |
download | mitmproxy-62416daa4a3776563556fb45ef9bd749fb44c334.tar.gz mitmproxy-62416daa4a3776563556fb45ef9bd749fb44c334.tar.bz2 mitmproxy-62416daa4a3776563556fb45ef9bd749fb44c334.zip |
add Reader.peek()
Diffstat (limited to 'netlib')
-rw-r--r-- | netlib/tcp.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py index 22cd0965..b05e84f5 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -265,6 +265,24 @@ class Reader(_FileLike): ) return result + def peek(self, length): + """ + Tries to peek into the underlying file object. + + Returns: + Up to the next N bytes if peeking is successful. + None, otherwise. + + Raises: + NetLibSSLError if there was an error with pyOpenSSL. + """ + if isinstance(self.o, SSL.Connection) or isinstance(self.o, socket._fileobject): + try: + return self.o._sock.recv(length, socket.MSG_PEEK) + except SSL.Error as e: + raise NetLibSSLError(str(e)) + + class Address(object): |