Skip to content

Commit

Permalink
hgmo: cast bytearray to bytes (bug 1506297); r=sheehan
Browse files Browse the repository at this point in the history
Mercurial 4.8 may emit bytearray instances from its WSGI application.
This is apparently against PEP-3333 and mod_wsgi complains.

This commit works around the bug by filtering for bytearray in
WSGI application output and casting to bytes.

The upstream bug should be fixed in 4.8.1.

Differential Revision: https://phabricator.services.mozilla.com/D11539

--HG--
extra : moz-landing-system : lando
  • Loading branch information
indygreg committed Nov 11, 2018
1 parent dcc39ea commit 9f75a4f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions hgext/hgmo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
wireprotov1server,
)
from mercurial.hgweb import (
request as requestmod,
webcommands,
webutil,
)
Expand Down Expand Up @@ -790,6 +791,14 @@ def mozbuildinfocommand(ui, repo, *paths, **opts):
return


def wsgisendresponse(orig, self):
for chunk in orig(self):
if isinstance(chunk, bytearray):
chunk = bytes(chunk)

yield chunk


def pull(orig, repo, remote, *args, **kwargs):
"""Wraps exchange.pull to fetch the remote clonebundles.manifest."""
res = orig(repo, remote, *args, **kwargs)
Expand Down Expand Up @@ -951,6 +960,10 @@ def hgwebfastannotate(orig, req, fctx, ui):


def extsetup(ui):
# TRACKING hg49 4.8 would emit bytearray instances against PEP-3333.
extensions.wrapfunction(requestmod.wsgiresponse, 'sendresponse',
wsgisendresponse)

extensions.wrapfunction(exchange, 'pull', pull)
extensions.wrapfunction(webutil, 'changesetentry', changesetentry)
extensions.wrapfunction(webutil, 'changelistentry', changelistentry)
Expand Down

0 comments on commit 9f75a4f

Please sign in to comment.