wireprotoserver: convert ErrorResponse to bytes stable
authorMatt Harbison <matt_harbison@yahoo.com>
Thu, 11 Mar 2021 21:07:04 -0500
branchstable
changeset 46697 71443f742886
parent 46696 ed0899e01628
child 46698 f64806207752
wireprotoserver: convert ErrorResponse to bytes Caught by pytype: File "/mnt/c/Users/Matt/hg/mercurial/wireprotoserver.py", line 236, in handlewsgirequest: Function _bytestr.__init__ was called with the wrong arguments [wrong-arg-types] Expected: (self, ints: Iterable[int]) Actually passed: (self, ints: mercurial.hgweb.common.ErrorResponse) The following methods aren't implemented on mercurial.hgweb.common.ErrorResponse: __iter__ File "/mnt/c/Users/Matt/hg/mercurial/wireprotoserver.py", line 239, in handlewsgirequest: Function _bytestr.__init__ was called with the wrong arguments [wrong-arg-types] Expected: (self, ints: Iterable[int]) Actually passed: (self, ints: mercurial.hgweb.common.ErrorResponse) The following methods aren't implemented on mercurial.hgweb.common.ErrorResponse: __iter__ File "/mnt/c/Users/Matt/hg/mercurial/wireprotov2server.py", line 91, in handlehttpv2request: Function _bytestr.__init__ was called with the wrong arguments [wrong-arg-types] Expected: (self, ints: Iterable[int]) Actually passed: (self, ints: mercurial.hgweb.common.ErrorResponse) The following methods aren't implemented on mercurial.hgweb.common.ErrorResponse: __iter__ Differential Revision: https://phab.mercurial-scm.org/D10182
mercurial/wireprotoserver.py
mercurial/wireprotov2server.py
--- a/mercurial/wireprotoserver.py	Thu Mar 11 21:02:03 2021 -0500
+++ b/mercurial/wireprotoserver.py	Thu Mar 11 21:07:04 2021 -0500
@@ -24,6 +24,7 @@
 from .utils import (
     cborutil,
     compression,
+    stringutil,
 )
 
 stringio = util.stringio
@@ -233,10 +234,12 @@
     except hgwebcommon.ErrorResponse as e:
         for k, v in e.headers:
             res.headers[k] = v
-        res.status = hgwebcommon.statusmessage(e.code, pycompat.bytestr(e))
+        res.status = hgwebcommon.statusmessage(
+            e.code, stringutil.forcebytestr(e)
+        )
         # TODO This response body assumes the failed command was
         # "unbundle." That assumption is not always valid.
-        res.setbodybytes(b'0\n%s\n' % pycompat.bytestr(e))
+        res.setbodybytes(b'0\n%s\n' % stringutil.forcebytestr(e))
 
     return True
 
--- a/mercurial/wireprotov2server.py	Thu Mar 11 21:02:03 2021 -0500
+++ b/mercurial/wireprotov2server.py	Thu Mar 11 21:07:04 2021 -0500
@@ -88,7 +88,9 @@
     try:
         checkperm(rctx, req, b'pull' if permission == b'ro' else b'push')
     except hgwebcommon.ErrorResponse as e:
-        res.status = hgwebcommon.statusmessage(e.code, pycompat.bytestr(e))
+        res.status = hgwebcommon.statusmessage(
+            e.code, stringutil.forcebytestr(e)
+        )
         for k, v in e.headers:
             res.headers[k] = v
         res.setbodybytes(b'permission denied')