Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit f6c2dd8

Browse files
committed
Define the buffered socket can_read method.
1 parent bf5d204 commit f6c2dd8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

hyper/http20/bufsocket.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ def _buffer_end(self):
6161
"""
6262
return self._index + self._bytes_in_buffer
6363

64+
@property
65+
def can_read(self):
66+
"""
67+
Whether or not there is more data to read from the socket.
68+
"""
69+
if self._bytes_in_buffer:
70+
return True
71+
72+
read = select.select([self._sck], [], [], 0)[0]
73+
if read:
74+
return True
75+
76+
return False
77+
6478
def recv(self, amt):
6579
"""
6680
Read some data from the socket.

test/test_hyper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,7 @@ class DummySocket(object):
20292029
def __init__(self):
20302030
self.queue = []
20312031
self.buffer = BytesIO()
2032+
self.can_read = False
20322033

20332034
def send(self, data):
20342035
self.queue.append(data)

0 commit comments

Comments
 (0)