# HG changeset patch
# User Matt Harbison <
matt_h...@yahoo.com>
# Date 1553389237 14400
# Sat Mar 23 21:00:37 2019 -0400
# Node ID 84b197ec8feef823b74bce41317ae6c6721b73a5
# Parent c3cf4955663324e790f692d543c3fd3357d935f0
py3: replace cStringIO with pycompat.bytesio
Fixed up after running `2to3 -w -n -f imports -f imports2 .`. There are other
imports that need fixing, but not all have a pycompat alias. So I'm splitting
these up.
diff --git a/TortoiseHgOverlayServer.py b/TortoiseHgOverlayServer.py
--- a/TortoiseHgOverlayServer.py
+++ b/TortoiseHgOverlayServer.py
@@ -30,7 +30,6 @@
import errno
import time
import threading
-import cStringIO
import Queue
import traceback
import gc
@@ -52,7 +51,11 @@
from mercurial import demandimport
demandimport.IGNORES.add('win32com.shell')
demandimport.enable()
-from mercurial import error
+from mercurial import (
+ error,
+ pycompat,
+)
+
from mercurial.windows import posixfile, unlink, rename
from tortoisehg.util.i18n import agettext as _
from tortoisehg.util import hglib, thread2, paths, shlib, version
@@ -280,7 +283,7 @@
if roots:
_ui = hglib.loadui()
failedroots = set()
- errorstream = cStringIO.StringIO()
+ errorstream = pycompat.bytesio()
_stderr = sys.stderr
sys.stderr = errorstream
try:
diff --git a/hgext3rd/thg.py b/hgext3rd/thg.py
--- a/hgext3rd/thg.py
+++ b/hgext3rd/thg.py
@@ -17,7 +17,11 @@
import sys
from mercurial.i18n import _
-from mercurial import registrar, ui
+from mercurial import (
+ pycompat,
+ registrar,
+ ui,
+)
testedwith = '4.3'
@@ -107,8 +111,7 @@
def cmdview(ui, repo, *pats, **opts):
"""start light interactive history viewer from tortoisehg"""
enforceversion()
- import cStringIO
- mystderr = cStringIO.StringIO()
+ mystderr = pycompat.bytesio()
origstderr = sys.stderr
sys.stderr = mystderr
sys.__stdout__ = sys.stdout
diff --git a/i18n/msgfmt.py b/i18n/msgfmt.py
--- a/i18n/msgfmt.py
+++ b/i18n/msgfmt.py
@@ -35,7 +35,10 @@
import struct
import array
-from cStringIO import StringIO
+
+from mercurial import (
+ pycompat,
+)
__version__ = "1.1-pythongettext"
@@ -224,4 +227,4 @@
self.po.close()
def getAsFile(self):
- return StringIO(self.get())
+ return pycompat.bytesio(self.get())
diff --git a/tests/helpers.py b/tests/helpers.py
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -8,10 +8,10 @@
import tempfile
import time
from collections import defaultdict
-try:
- import cStringIO as StringIO
-except ImportError:
- import StringIO
+
+from mercurial import (
+ pycompat,
+)
from nose import tools
@@ -151,8 +151,8 @@
origwd = os.getcwd()
ui = hglib.loadui()
ui.setconfig('ui', 'strict', True)
- ui.fout = StringIO.StringIO()
- ui.ferr = StringIO.StringIO()
+ ui.fout = pycompat.bytesio()
+ ui.ferr = pycompat.bytesio()
args = list(args)
req = dispatch.request(args, ui=ui)
if hasattr(req, 'earlyoptions'):
diff --git a/tests/wconfig_test.py b/tests/wconfig_test.py
--- a/tests/wconfig_test.py
+++ b/tests/wconfig_test.py
@@ -1,8 +1,12 @@
import os, tempfile
from nose.tools import *
from nose.plugins.skip import SkipTest
-from StringIO import StringIO
-from mercurial import config, error
+from mercurial import (
+ config,
+ error,
+ pycompat,
+)
+
from tortoisehg.util import wconfig
import helpers
@@ -23,7 +27,7 @@
return wconfig.config(newrconfig(vals))
def written(c):
- dest = StringIO()
+ dest = pycompat.bytesio()
c.write(dest)
return dest.getvalue()
@@ -221,7 +225,7 @@
def check_read_write():
c = newwconfig()
s = '[foo]\nbar = baz'
- c.read(path='foo', fp=StringIO(s))
+ c.read(path='foo', fp=pycompat.bytesio(s))
assert_equals(s, written(c).rstrip())
@with_wconfig
@@ -229,16 +233,16 @@
def check_read_write_missing_section_header_error():
c = newwconfig()
s = 'bar = baz' # missing header
- c.read(path='foo', fp=StringIO(s))
- c.write(StringIO())
+ c.read(path='foo', fp=pycompat.bytesio(s))
+ c.write(pycompat.bytesio())
@with_wconfig
@raises(error.ParseError)
def check_read_write_parsing_error():
c = newwconfig()
s = '[foo]\n:bar = baz' # Mercurial can parse it but INIConfig can't
- c.read(path='foo', fp=StringIO(s))
- c.write(StringIO())
+ c.read(path='foo', fp=pycompat.bytesio(s))
+ c.write(pycompat.bytesio())
@with_wconfig
def check_write_after_dict_setitem():
@@ -262,7 +266,7 @@
def check_read_write_rem():
c = newwconfig()
s = '[foo]\nrem = x'
- c.read(path='foo', fp=StringIO(s))
+ c.read(path='foo', fp=pycompat.bytesio(s))
c.set('foo', 'rem', 'y')
assert_equals('[foo]\nrem = y', written(c).rstrip())
@@ -270,7 +274,7 @@
def check_read_write_suboption():
c = newwconfig()
s = '[foo]\nbar:baz = x'
- c.read(path='foo', fp=StringIO(s))
+ c.read(path='foo', fp=pycompat.bytesio(s))
c.set('foo', 'bar:baz', 'y')
assert_equals('[foo]\nbar:baz = y', written(c).rstrip())
@@ -278,7 +282,7 @@
def check_read_write_suboption_removal():
c = newwconfig()
s = '[foo]\nbar:baz = x\nbar = y'
- c.read(path='foo', fp=StringIO(s))
+ c.read(path='foo', fp=pycompat.bytesio(s))
del c['foo']['bar:baz']
assert_equals('[foo]\nbar = y', written(c).rstrip())
diff --git a/thg b/thg
--- a/thg
+++ b/thg
@@ -111,9 +111,9 @@
or getattr(sys, 'frozen', None) != 'windows_exe'):
sys.exit(tortoisehg.hgqt.run.dispatch(argv))
else:
- import cStringIO
+ from mercurial import pycompat
from mercurial.utils import procutil
- mystderr = cStringIO.StringIO()
+ mystderr = pycompat.bytesio()
origstderr = sys.stderr
sys.stderr = mystderr
sys.__stdout__ = sys.stdout
diff --git a/tortoisehg/hgqt/chunks.py b/tortoisehg/hgqt/chunks.py
--- a/tortoisehg/hgqt/chunks.py
+++ b/tortoisehg/hgqt/chunks.py
@@ -7,7 +7,6 @@
from __future__ import absolute_import
-import cStringIO
import os
import re
@@ -285,7 +284,7 @@
if isinstance(ctx, patchctx):
repo.thgbackup(ctx._path)
fp = util.atomictempfile(ctx._path, 'wb')
- buf = cStringIO.StringIO()
+ buf = pycompat.bytesio()
try:
if ctx._ph.comments:
buf.write('\n'.join(ctx._ph.comments))
@@ -327,7 +326,7 @@
wf = repo.wvfs(self.currentFile, 'wb', atomictemp=True)
wf.write(self.diffbrowse.origcontents)
wf.close()
- fp = cStringIO.StringIO()
+ fp = pycompat.bytesio()
chunks[0].write(fp)
for c in kchunks:
c.write(fp)
@@ -394,7 +393,7 @@
else:
# Apply chunks to wfile
repo.thgbackup(repo.wjoin(wfile))
- fp = cStringIO.StringIO()
+ fp = pycompat.bytesio()
for c in chunks:
c.write(fp)
fp.seek(0)
@@ -451,7 +450,7 @@
else:
return []
else:
- buf = cStringIO.StringIO()
+ buf = pycompat.bytesio()
diffopts = patch.diffopts(repo.ui, {'git':True})
m = matchmod.exact(repo.root, repo.root, [wfile])
for p in patch.diff(repo, ctx.p1().node(), None, match=m,
@@ -781,12 +780,12 @@
elif isinstance(self._ctx.rev(), str):
chunks = self._ctx._files[filename]
else:
- header = patch.parsepatch(cStringIO.StringIO(fd.diff))[0]
+ header = patch.parsepatch(pycompat.bytesio(fd.diff))[0]
chunks = [header] + header.hunks
utext = []
for chunk in chunks[1:]:
- buf = cStringIO.StringIO()
+ buf = pycompat.bytesio()
chunk.selected = False
chunk.write(buf)
chunk.lines = buf.getvalue().splitlines()
diff --git a/tortoisehg/hgqt/filedata.py b/tortoisehg/hgqt/filedata.py
--- a/tortoisehg/hgqt/filedata.py
+++ b/tortoisehg/hgqt/filedata.py
@@ -6,10 +6,18 @@
# GNU General Public License version 2, incorporated herein by reference.
import os, posixpath
-import cStringIO
-from mercurial import commands, error, match, patch, subrepo, util
-from mercurial import copies
+from mercurial import (
+ commands,
+ copies,
+ error,
+ match,
+ patch,
+ pycompat,
+ subrepo,
+ util,
+)
+
from mercurial.utils import (
dateutil,
)
@@ -377,7 +385,7 @@
diffopts = patch.difffeatureopts(repo.ui)
diffopts.git = True
m = match.exact(repo.root, repo.root, [wfile])
- fp = cStringIO.StringIO()
+ fp = pycompat.bytesio()
copy = {}
if oldname != wfile:
@@ -401,7 +409,7 @@
values = []
lines = 0
for chunk in self.changes.hunks:
- buf = cStringIO.StringIO()
+ buf = pycompat.bytesio()
chunk.write(buf)
chunk.excluded = False
val = buf.getvalue()
diff --git a/tortoisehg/hgqt/rejects.py b/tortoisehg/hgqt/rejects.py
--- a/tortoisehg/hgqt/rejects.py
+++ b/tortoisehg/hgqt/rejects.py
@@ -7,8 +7,6 @@
from __future__ import absolute_import
-import cStringIO
-
from . import qsci as Qsci
from .qtcore import (
QPoint,
@@ -30,7 +28,10 @@
QVBoxLayout,
)
-from mercurial import patch
+from mercurial import (
+ patch,
+ pycompat,
+)
from ..util import hglib
from ..util.i18n import _
@@ -131,7 +132,7 @@
editor.setMarginLineNumbers(1, True)
editor.setMarginWidth(1, str(editor.lines())+'X')
- buf = cStringIO.StringIO()
+ buf = pycompat.bytesio()
try:
buf.write('diff -r aaaaaaaaaaaa -r bbbbbbbbbbb %s\n' % path)
buf.write(open(path + '.rej', 'rb').read())
@@ -196,7 +197,7 @@
def showChunk(self, row):
if row == -1 or self.updating:
return
- buf = cStringIO.StringIO()
+ buf = pycompat.bytesio()
chunk = self.chunks[row]
chunk.write(buf)
chunkstr = buf.getvalue().decode(self._textEncoding(), 'replace')
diff --git a/tortoisehg/hgqt/repowidget.py b/tortoisehg/hgqt/repowidget.py
--- a/tortoisehg/hgqt/repowidget.py
+++ b/tortoisehg/hgqt/repowidget.py
@@ -9,7 +9,6 @@
from __future__ import absolute_import
import binascii
-import cStringIO
import os
import shlex # used by runCustomCommand
import subprocess # used by runCustomCommand
@@ -2243,7 +2242,7 @@
else:
cmd += ['--repository', self.repo.root]
_ui = self.repo.ui.copy()
- _ui.ferr = cStringIO.StringIO()
+ _ui.ferr = pycompat.bytesio()
# avoid circular import of hgqt.run by importing it inplace
from . import run
res = run.dispatch(cmd, u=_ui)
diff --git a/tortoisehg/util/hglib.py b/tortoisehg/util/hglib.py
--- a/tortoisehg/util/hglib.py
+++ b/tortoisehg/util/hglib.py
@@ -7,7 +7,6 @@
from __future__ import absolute_import
-import cStringIO
import glob
import os
import re
@@ -1177,7 +1176,7 @@
_ = _gettext # TODO: use unicode version globally
# shlex can't process unicode on Python < 2.7.3
cmdline = cmdline.encode('utf-8')
- src = cStringIO.StringIO(cmdline)
+ src = pycompat.bytesio(cmdline)
lex = shlex.shlex(src, posix=True)
lex.whitespace_split = True
lex.commenters = ''
diff --git a/tortoisehg/util/patchctx.py b/tortoisehg/util/patchctx.py
--- a/tortoisehg/util/patchctx.py
+++ b/tortoisehg/util/patchctx.py
@@ -9,7 +9,6 @@
import os
import binascii
-import cStringIO
from mercurial import patch, util, error
from mercurial import node
@@ -183,7 +182,7 @@
if wfile == self._parseErrorFileName:
return '\n\n\nErrors while parsing patch:\n'+str(self._parseerror)
if wfile in self._files:
- buf = cStringIO.StringIO()
+ buf = pycompat.bytesio()
for chunk in self._files[wfile]:
chunk.write(buf)
return buf.getvalue()
diff --git a/tortoisehg/util/wconfig.py b/tortoisehg/util/wconfig.py
--- a/tortoisehg/util/wconfig.py
+++ b/tortoisehg/util/wconfig.py
@@ -7,7 +7,6 @@
import os
import re
-import cStringIO
import ConfigParser
from mercurial import error, util, config as config_mod
@@ -264,7 +263,7 @@
def writefile(config, path):
"""Write the given config obj to the specified file"""
# normalize line endings
- buf = cStringIO.StringIO()
+ buf = pycompat.bytesio()
config.write(buf)
data = '\n'.join(buf.getvalue().splitlines()) + '\n'