Mercurial > hg
diff mercurial/httpclient/_readers.py @ 19038:36733ab7fa05
http2: sane readline
It turns out that it pays off to read more than a byte at a time with
a select in between :)
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Fri, 01 Feb 2013 15:00:23 -0800 |
parents | 1fde25ad9396 |
children | fae47ecaa952 |
line wrap: on
line diff
--- a/mercurial/httpclient/_readers.py Fri Feb 01 14:41:35 2013 -0800 +++ b/mercurial/httpclient/_readers.py Fri Feb 01 15:00:23 2013 -0800 @@ -96,6 +96,29 @@ return result + def readto(self, delimstr, blocks = None): + """return available data chunks up to the first one in which delimstr + occurs. No data will be returned after delimstr -- the chunk in which + it occurs will be split and the remainder pushed back onto the available + data queue. If blocks is supplied chunks will be added to blocks, otherwise + a new list will be allocated. + """ + if blocks is None: + blocks = [] + + while self._done_chunks: + b = self.popchunk() + i = b.find(delimstr) + len(delimstr) + if i: + if i < len(b): + self.pushchunk(b[i:]) + blocks.append(b[:i]) + break + else: + blocks.append(b) + + return blocks + def _load(self, data): # pragma: no cover """Subclasses must implement this.