D10182: wireprotoserver: convert ErrorResponse to bytes

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Fri Mar 12 18:09:56 UTC 2021


mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  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__

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D10182

AFFECTED FILES
  mercurial/wireprotoserver.py
  mercurial/wireprotov2server.py

CHANGE DETAILS

diff --git a/mercurial/wireprotov2server.py b/mercurial/wireprotov2server.py
--- a/mercurial/wireprotov2server.py
+++ b/mercurial/wireprotov2server.py
@@ -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')
diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py
--- a/mercurial/wireprotoserver.py
+++ b/mercurial/wireprotoserver.py
@@ -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
 



To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list