Mercurial > hg
changeset 48609:8039cca948f8
test-http-bad-server: use more readable name for variable
This make the code more accessible overall.
Differential Revision: https://phab.mercurial-scm.org/D12040
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 19 Jan 2022 19:14:17 +0100 |
parents | f87b632406a9 |
children | caa6694dac45 |
files | tests/testlib/badserverext.py |
diffstat | 1 files changed, 43 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/testlib/badserverext.py Fri Jan 21 02:07:13 2022 +0100 +++ b/tests/testlib/badserverext.py Wed Jan 19 19:14:17 2022 +0100 @@ -69,17 +69,21 @@ __slots__ = ( '_orig', '_logfp', - '_closeafterrecvbytes', - '_closeaftersendbytes', + '_close_after_recv_bytes', + '_close_after_send_bytes', ) def __init__( - self, obj, logfp, closeafterrecvbytes=0, closeaftersendbytes=0 + self, obj, logfp, close_after_recv_bytes=0, close_after_send_bytes=0 ): object.__setattr__(self, '_orig', obj) object.__setattr__(self, '_logfp', logfp) - object.__setattr__(self, '_closeafterrecvbytes', closeafterrecvbytes) - object.__setattr__(self, '_closeaftersendbytes', closeaftersendbytes) + object.__setattr__( + self, '_close_after_recv_bytes', close_after_recv_bytes + ) + object.__setattr__( + self, '_close_after_send_bytes', close_after_send_bytes + ) def __getattribute__(self, name): if name in ('makefile', 'sendall', '_writelog'): @@ -104,22 +108,22 @@ f = object.__getattribute__(self, '_orig').makefile(mode, bufsize) logfp = object.__getattribute__(self, '_logfp') - closeafterrecvbytes = object.__getattribute__( - self, '_closeafterrecvbytes' + close_after_recv_bytes = object.__getattribute__( + self, '_close_after_recv_bytes' ) - closeaftersendbytes = object.__getattribute__( - self, '_closeaftersendbytes' + close_after_send_bytes = object.__getattribute__( + self, '_close_after_send_bytes' ) return fileobjectproxy( f, logfp, - closeafterrecvbytes=closeafterrecvbytes, - closeaftersendbytes=closeaftersendbytes, + close_after_recv_bytes=close_after_recv_bytes, + close_after_send_bytes=close_after_send_bytes, ) def sendall(self, data, flags=0): - remaining = object.__getattribute__(self, '_closeaftersendbytes') + remaining = object.__getattribute__(self, '_close_after_send_bytes') # No read limit. Call original function. if not remaining: @@ -141,7 +145,7 @@ % (len(newdata), len(data), remaining, newdata) ) - object.__setattr__(self, '_closeaftersendbytes', remaining) + object.__setattr__(self, '_close_after_send_bytes', remaining) if remaining <= 0: self._writelog(b'write limit reached; closing socket') @@ -157,17 +161,21 @@ __slots__ = ( '_orig', '_logfp', - '_closeafterrecvbytes', - '_closeaftersendbytes', + '_close_after_recv_bytes', + '_close_after_send_bytes', ) def __init__( - self, obj, logfp, closeafterrecvbytes=0, closeaftersendbytes=0 + self, obj, logfp, close_after_recv_bytes=0, close_after_send_bytes=0 ): object.__setattr__(self, '_orig', obj) object.__setattr__(self, '_logfp', logfp) - object.__setattr__(self, '_closeafterrecvbytes', closeafterrecvbytes) - object.__setattr__(self, '_closeaftersendbytes', closeaftersendbytes) + object.__setattr__( + self, '_close_after_recv_bytes', close_after_recv_bytes + ) + object.__setattr__( + self, '_close_after_send_bytes', close_after_send_bytes + ) def __getattribute__(self, name): if name in ('_close', 'read', 'readline', 'write', '_writelog'): @@ -202,7 +210,7 @@ self._sock.shutdown(socket.SHUT_RDWR) def read(self, size=-1): - remaining = object.__getattribute__(self, '_closeafterrecvbytes') + remaining = object.__getattribute__(self, '_close_after_recv_bytes') # No read limit. Call original function. if not remaining: @@ -227,7 +235,7 @@ % (size, origsize, len(result), result) ) - object.__setattr__(self, '_closeafterrecvbytes', remaining) + object.__setattr__(self, '_close_after_recv_bytes', remaining) if remaining <= 0: self._writelog(b'read limit reached; closing socket') @@ -239,7 +247,7 @@ return result def readline(self, size=-1): - remaining = object.__getattribute__(self, '_closeafterrecvbytes') + remaining = object.__getattribute__(self, '_close_after_recv_bytes') # No read limit. Call original function. if not remaining: @@ -264,7 +272,7 @@ % (size, origsize, len(result), result) ) - object.__setattr__(self, '_closeafterrecvbytes', remaining) + object.__setattr__(self, '_close_after_recv_bytes', remaining) if remaining <= 0: self._writelog(b'read limit reached; closing socket') @@ -276,7 +284,7 @@ return result def write(self, data): - remaining = object.__getattribute__(self, '_closeaftersendbytes') + remaining = object.__getattribute__(self, '_close_after_send_bytes') # No byte limit on this operation. Call original function. if not remaining: @@ -298,7 +306,7 @@ result = object.__getattribute__(self, '_orig').write(newdata) - object.__setattr__(self, '_closeaftersendbytes', remaining) + object.__setattr__(self, '_close_after_send_bytes', remaining) if remaining <= 0: self._writelog(b'write limit reached; closing socket') @@ -319,10 +327,10 @@ recvbytes = self._ui.config(b'badserver', b'close-after-recv-bytes') recvbytes = recvbytes.split(b',') - self.closeafterrecvbytes = [int(v) for v in recvbytes if v] + self.close_after_recv_bytes = [int(v) for v in recvbytes if v] sendbytes = self._ui.config(b'badserver', b'close-after-send-bytes') sendbytes = sendbytes.split(b',') - self.closeaftersendbytes = [int(v) for v in sendbytes if v] + self.close_after_send_bytes = [int(v) for v in sendbytes if v] # Need to inherit object so super() works. class badrequesthandler(self.RequestHandlerClass, object): @@ -362,21 +370,21 @@ # is a hgweb.server._httprequesthandler. def process_request(self, socket, address): # Wrap socket in a proxy if we need to count bytes. - if self.closeafterrecvbytes: - closeafterrecvbytes = self.closeafterrecvbytes.pop(0) + if self.close_after_recv_bytes: + close_after_recv_bytes = self.close_after_recv_bytes.pop(0) else: - closeafterrecvbytes = 0 - if self.closeaftersendbytes: - closeaftersendbytes = self.closeaftersendbytes.pop(0) + close_after_recv_bytes = 0 + if self.close_after_send_bytes: + close_after_send_bytes = self.close_after_send_bytes.pop(0) else: - closeaftersendbytes = 0 + close_after_send_bytes = 0 - if closeafterrecvbytes or closeaftersendbytes: + if close_after_recv_bytes or close_after_send_bytes: socket = socketproxy( socket, self.errorlog, - closeafterrecvbytes=closeafterrecvbytes, - closeaftersendbytes=closeaftersendbytes, + close_after_recv_bytes=close_after_recv_bytes, + close_after_send_bytes=close_after_send_bytes, ) return super(badserver, self).process_request(socket, address)