##// END OF EJS Templates
http2: sane readline...
Brendan Cully -
r19038:36733ab7 default
parent child Browse files
Show More
@@ -125,24 +125,16 b' class HTTPResponse(object):'
125 This may block until either a line ending is found or the
125 This may block until either a line ending is found or the
126 response is complete.
126 response is complete.
127 """
127 """
128 # TODO: move this into the reader interface where it can be
128 blocks = []
129 # smarter (and probably avoid copies)
129 while True:
130 bytes = []
130 self._reader.readto('\n', blocks)
131 while not bytes:
131
132 try:
132 if blocks and blocks[-1][-1] == '\n' or self.complete():
133 bytes = [self._reader.read(1)]
133 break
134 except _readers.ReadNotReady:
134
135 self._select()
136 while bytes[-1] != '\n' and not self.complete():
137 self._select()
135 self._select()
138 bytes.append(self._reader.read(1))
136
139 if bytes[-1] != '\n':
137 return ''.join(blocks)
140 next = self._reader.read(1)
141 while next and next != '\n':
142 bytes.append(next)
143 next = self._reader.read(1)
144 bytes.append(next)
145 return ''.join(bytes)
146
138
147 def read(self, length=None):
139 def read(self, length=None):
148 # if length is None, unbounded read
140 # if length is None, unbounded read
@@ -96,6 +96,29 b' class AbstractReader(object):'
96
96
97 return result
97 return result
98
98
99 def readto(self, delimstr, blocks = None):
100 """return available data chunks up to the first one in which delimstr
101 occurs. No data will be returned after delimstr -- the chunk in which
102 it occurs will be split and the remainder pushed back onto the available
103 data queue. If blocks is supplied chunks will be added to blocks, otherwise
104 a new list will be allocated.
105 """
106 if blocks is None:
107 blocks = []
108
109 while self._done_chunks:
110 b = self.popchunk()
111 i = b.find(delimstr) + len(delimstr)
112 if i:
113 if i < len(b):
114 self.pushchunk(b[i:])
115 blocks.append(b[:i])
116 break
117 else:
118 blocks.append(b)
119
120 return blocks
121
99 def _load(self, data): # pragma: no cover
122 def _load(self, data): # pragma: no cover
100 """Subclasses must implement this.
123 """Subclasses must implement this.
101
124
General Comments 0
You need to be logged in to leave comments. Login now