def test_readlog(self): s = BytesIO(b"foobar\nfoobar") s = tcp.Reader(s) assert not s.is_logging() s.start_log() assert s.is_logging() s.readline() assert s.get_log() == b"foobar\n" s.read(1) assert s.get_log() == b"foobar\nf" s.start_log() assert s.get_log() == b"" s.read(1) assert s.get_log() == b"o" s.stop_log() tutils.raises(ValueError, s.get_log)
def test_reader_incomplete_error(self): s = BytesIO(b"foobar") s = tcp.Reader(s) tutils.raises(TcpReadIncomplete, s.safe_read, 10)
def test_reader_readline_disconnect(self): o = mock.MagicMock() o.read = mock.MagicMock(side_effect=socket.error) s = tcp.Reader(o) tutils.raises(TcpDisconnect, s.readline, 10)
def test_read_syscall_ssl_error(self): s = mock.MagicMock() s.read = mock.MagicMock(side_effect=SSL.SysCallError()) s = tcp.Reader(s) tutils.raises(TlsException, s.read, 1)
def test_reset_timestamps(self): s = BytesIO(b"foobar\nfoobar") s = tcp.Reader(s) s.first_byte_timestamp = 500 s.reset_timestamps() assert not s.first_byte_timestamp
def test_limit(self): s = BytesIO(b"foobar\nfoobar") s = tcp.Reader(s) assert s.readline(3) == b"foo"
def test_limitless(self): s = BytesIO(b"f" * (50 * 1024)) s = tcp.Reader(s) ret = s.read(-1) assert len(ret) == 50 * 1024
def from_bytes(cls, bytestring): """ Construct a websocket frame from an in-memory bytestring to construct a frame from a stream of bytes, use from_file() directly """ return cls.from_file(tcp.Reader(io.BytesIO(bytestring)))
def treader(bytes): """ Construct a tcp.Read object from bytes. """ fp = BytesIO(bytes) return tcp.Reader(fp)
def test_limitless(self): s = cStringIO.StringIO("f" * (50 * 1024)) s = tcp.Reader(s) ret = s.read(-1) assert len(ret) == 50 * 1024
def treader(bytes): """ Construct a tcp.Read object from bytes. """ fp = cStringIO.StringIO(bytes) return tcp.Reader(fp)
def test_limit(self): s = cStringIO.StringIO("foobar\nfoobar") s = tcp.Reader(s) assert s.readline(3) == "foo"
def hex_to_file(data): data = data.decode('hex') return tcp.Reader(cStringIO.StringIO(data))
def hex_to_file(data): data = data.decode('hex') return tcp.Reader(BytesIO(data))
def test_read_ssl_error(self): s = mock.MagicMock() s.read = mock.MagicMock(side_effect=SSL.Error()) s = tcp.Reader(s) tutils.raises(tcp.NetLibSSLError, s.read, 1)
def test_reader_incomplete_error(self): s = cStringIO.StringIO("foobar") s = tcp.Reader(s) tutils.raises(tcp.NetLibIncomplete, s.safe_read, 10)