Show More
@@ -125,24 +125,16 b' class HTTPResponse(object):' | |||
|
125 | 125 | This may block until either a line ending is found or the |
|
126 | 126 | response is complete. |
|
127 | 127 | """ |
|
128 | # TODO: move this into the reader interface where it can be | |
|
129 | # smarter (and probably avoid copies) | |
|
130 | bytes = [] | |
|
131 | while not bytes: | |
|
132 | try: | |
|
133 | bytes = [self._reader.read(1)] | |
|
134 | except _readers.ReadNotReady: | |
|
135 | self._select() | |
|
136 | while bytes[-1] != '\n' and not self.complete(): | |
|
128 | blocks = [] | |
|
129 | while True: | |
|
130 | self._reader.readto('\n', blocks) | |
|
131 | ||
|
132 | if blocks and blocks[-1][-1] == '\n' or self.complete(): | |
|
133 | break | |
|
134 | ||
|
137 | 135 | self._select() |
|
138 | bytes.append(self._reader.read(1)) | |
|
139 | if bytes[-1] != '\n': | |
|
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) | |
|
136 | ||
|
137 | return ''.join(blocks) | |
|
146 | 138 | |
|
147 | 139 | def read(self, length=None): |
|
148 | 140 | # if length is None, unbounded read |
@@ -96,6 +96,29 b' class AbstractReader(object):' | |||
|
96 | 96 | |
|
97 | 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 | 122 | def _load(self, data): # pragma: no cover |
|
100 | 123 | """Subclasses must implement this. |
|
101 | 124 |
General Comments 0
You need to be logged in to leave comments.
Login now