Mercurial > public > mercurial-scm > hg
diff mercurial/url.py @ 51823:ace0da86edd0
urllib2: redo response.readlines addition via class patching
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Fri, 28 Jun 2024 16:26:06 +0200 |
parents | d718eddf01d9 |
children | b08de326bee4 |
line wrap: on
line diff
--- a/mercurial/url.py Wed Aug 21 22:15:05 2024 -0400 +++ b/mercurial/url.py Fri Jun 28 16:26:06 2024 +0200 @@ -499,6 +499,28 @@ return request +class readlinehandler(urlreq.basehandler): + def http_response(self, request, response): + class readlineresponse(response.__class__): + def readlines(self, sizehint=0): + total = 0 + list = [] + while True: + line = self.readline() + if not line: + break + list.append(line) + total += len(line) + if sizehint and total >= sizehint: + break + return list + + response.__class__ = readlineresponse + return response + + https_response = http_response + + handlerfuncs = [] @@ -564,6 +586,7 @@ ) handlers.extend([h(ui, passmgr) for h in handlerfuncs]) handlers.append(cookiehandler(ui)) + handlers.append(readlinehandler()) opener = urlreq.buildopener(*handlers) # keepalive.py's handlers will populate these attributes if they exist.