comparison mercurial/keepalive.py @ 37297:97eedbd5a56c

keepalive: implement readinto() This is part of the standard I/O interface. It is used by the framing protocol. So we need to implement it so frames can be decoded. Differential Revision: https://phab.mercurial-scm.org/D2984
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 28 Mar 2018 12:44:35 -0700
parents d4a2e0d5d042
children 192b7ad06932
comparison
equal deleted inserted replaced
37296:78103e4138b1 37297:97eedbd5a56c
347 class HTTPHandler(KeepAliveHandler, urlreq.httphandler): 347 class HTTPHandler(KeepAliveHandler, urlreq.httphandler):
348 pass 348 pass
349 349
350 class HTTPResponse(httplib.HTTPResponse): 350 class HTTPResponse(httplib.HTTPResponse):
351 # we need to subclass HTTPResponse in order to 351 # we need to subclass HTTPResponse in order to
352 # 1) add readline() and readlines() methods 352 # 1) add readline(), readlines(), and readinto() methods
353 # 2) add close_connection() methods 353 # 2) add close_connection() methods
354 # 3) add info() and geturl() methods 354 # 3) add info() and geturl() methods
355 355
356 # in order to add readline(), read must be modified to deal with a 356 # in order to add readline(), read must be modified to deal with a
357 # buffer. example: readline must read a buffer and then spit back 357 # buffer. example: readline must read a buffer and then spit back
520 total += len(line) 520 total += len(line)
521 if sizehint and total >= sizehint: 521 if sizehint and total >= sizehint:
522 break 522 break
523 return list 523 return list
524 524
525 def readinto(self, dest):
526 res = self.read(len(dest))
527 if not res:
528 return 0
529
530 dest[0:len(res)] = res
531 return len(res)
532
525 def safesend(self, str): 533 def safesend(self, str):
526 """Send `str' to the server. 534 """Send `str' to the server.
527 535
528 Shamelessly ripped off from httplib to patch a bad behavior. 536 Shamelessly ripped off from httplib to patch a bad behavior.
529 """ 537 """