Skip to content

Commit

Permalink
pycompat: account for pycompat.bytesio being removed in 6.2+ hg (Bu…
Browse files Browse the repository at this point in the history
…g 1762417) r=zeid

Use `io.BytesIO` in testing specific modules for Py3 only code (hooks
in this case) and add a function to paper over the differences on
`configwizard` where we may still need to run on Py2 in some cases.

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
cgsheeh committed Apr 6, 2022
1 parent a4198e1 commit 7f8b645
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
7 changes: 6 additions & 1 deletion hgext/configwizard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Manage Mercurial configuration in a Mozilla-tailored way."""

import difflib
import io
import os
import stat
import subprocess
Expand Down Expand Up @@ -394,6 +395,10 @@
except ImportError:
configitems = None

def bytesio():
if util.versiontuple(n=2) >= (6, 2):
return io.BytesIO()
return pycompat.bytesio()

def _vcthome(): # Returns the directory where the vct clone is located
here = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -1236,7 +1241,7 @@ def _checkmultiplevct(ui, cw):

def _handleconfigchange(ui, cw):
# Obtain the old and new content so we can show a diff.
newbuf = pycompat.bytesio()
newbuf = bytesio()
cw.write(newbuf)
newbuf.seek(0)
newlines = [pycompat.sysstr(l.rstrip()) for l in newbuf.readlines()]
Expand Down
13 changes: 4 additions & 9 deletions testing/advanced_url_intercept.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
creating the HTTPError exception), or None (null in JSON) which will cause a
URLError to be raised.
"""

# TODO: deprecate url-interceptor.
import io
import json

from mercurial import (
error,
Expand All @@ -38,10 +38,6 @@
urllibcompat,
)


import json


configtable = {}
configitem = registrar.configitem(configtable)

Expand All @@ -58,8 +54,7 @@ def open(self, req, data=None, timeout=None):
req (Request)
Returns:
pycompat.bytesio (Python version dependent) object with
extra `getcode` attribute.
io.BytesIO object with extra `getcode` attribute.
Raises:
HTTPError, URLError
Expand All @@ -83,7 +78,7 @@ def open(self, req, data=None, timeout=None):
response["code"],
b"", None, None)

return_obj = pycompat.bytesio(
return_obj = io.BytesIO(
pycompat.bytestr(json.dumps(response["data"]))
)

Expand Down
3 changes: 2 additions & 1 deletion testing/url-intercept.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Currently, some defaults are assumed. Functionality can be expanded as
needed.
"""
import io

from mercurial import (
error,
Expand Down Expand Up @@ -49,7 +50,7 @@ def open(self, url, data=None, timeout=None):
url, expected))

self.ui.write(b'intercepting url\n')
return pycompat.bytesio(response)
return io.BytesIO(response)


def extsetup(ui):
Expand Down

0 comments on commit 7f8b645

Please sign in to comment.