diff --git a/mercurial/archival.py b/mercurial/archival.py --- a/mercurial/archival.py +++ b/mercurial/archival.py @@ -7,6 +7,7 @@ import gzip +import io import os import struct import tarfile @@ -30,8 +31,6 @@ from .utils import stringutil -stringio = util.stringio - # from unzip source code: _UNX_IFREG = 0x8000 _UNX_IFLNK = 0xA000 @@ -115,7 +114,7 @@ ) } - out = util.stringio() + out = io.BytesIO() fm = formatter.formatter(repo.ui, out, b'archive', opts) fm.startitem() @@ -184,7 +183,7 @@ i.size = 0 else: i.mode = mode - data = stringio(data) + data = io.BytesIO(data) self.z.addfile(i, data) def done(self): diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -8,6 +8,7 @@ import copy as copymod import errno +import io import os import re @@ -73,8 +74,6 @@ for t in (Any, Dict): assert t -stringio = util.stringio - # templates of common command options dryrunopts = [ @@ -575,7 +574,7 @@ util.copyfile(repo.wjoin(f), tmpname, copystat=True) backups[f] = tmpname - fp = stringio() + fp = io.BytesIO() for c in chunks: fname = c.filename() if fname in backups: @@ -3704,7 +3703,7 @@ if tobackup is None: tobackup = set() # Apply changes - fp = stringio() + fp = io.BytesIO() # chunks are serialized per file, but files aren't sorted for f in sorted({c.header.filename() for c in chunks if ishunk(c)}): prntstatusmsg(b'revert', f) diff --git a/mercurial/crecord.py b/mercurial/crecord.py --- a/mercurial/crecord.py +++ b/mercurial/crecord.py @@ -9,6 +9,7 @@ # (Itself based on Bryan O'Sullivan's record extension.) +import io import os import re import signal @@ -29,8 +30,6 @@ ) from .utils import stringutil -stringio = util.stringio - # patch comments based on the git one diffhelptext = _( b"""# To remove '-' lines, make them ' ' lines (context). @@ -226,7 +225,7 @@ self.hunks = [uihunk(h, self) for h in self.hunks] def prettystr(self): - x = stringio() + x = io.BytesIO() self.pretty(x) return x.getvalue() @@ -463,7 +462,7 @@ pretty = write def prettystr(self): - x = stringio() + x = io.BytesIO() self.pretty(x) return x.getvalue() @@ -1799,7 +1798,7 @@ return None # write the initial patch - patch = stringio() + patch = io.BytesIO() patch.write(diffhelptext + hunkhelptext) chunk.header.write(patch) chunk.write(patch) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -11,6 +11,7 @@ import contextlib import copy import errno +import io import os import re import shutil @@ -45,8 +46,6 @@ stringutil, ) -stringio = util.stringio - gitre = re.compile(br'diff --git a/(.*) b/(.*)') tabsplitter = re.compile(br'(\t+|[^\t]+)') wordsplitter = re.compile( @@ -74,7 +73,7 @@ return len(l) == 2 and b' ' not in l[0] def chunk(lines): - return stringio(b''.join(lines)) + return io.BytesIO(b''.join(lines)) def hgsplit(stream, cur): inheader = True @@ -107,7 +106,7 @@ def mimesplit(stream, cur): def msgfp(m): - fp = stringio() + fp = io.BytesIO() # pytype: disable=wrong-arg-types g = mail.Generator(fp, mangle_from_=False) # pytype: enable=wrong-arg-types @@ -290,7 +289,7 @@ ui.debug(b'found patch at byte %d\n' % m.start(0)) diffs_seen += 1 - cfp = stringio() + cfp = io.BytesIO() for line in payload[: m.start(0)].splitlines(): if line.startswith(b'# HG changeset patch') and not hgpatch: ui.debug(b'patch generated by hg export\n') @@ -599,7 +598,7 @@ self.created = 0 self.maxsize = maxsize if self.maxsize is None: - self.maxsize = 4 * (2 ** 20) + self.maxsize = 4 * (2**20) self.size = 0 self.data = {} @@ -1258,7 +1257,7 @@ continue # Remove comment lines patchfp = open(patchfn, 'rb') - ncpatchfp = stringio() + ncpatchfp = io.BytesIO() for line in patchfp: line = util.fromnativeeol(line) if not line.startswith(b'#'): @@ -1677,7 +1676,7 @@ >>> reversedhunks = reversehunks(hunkscomingfromfilterpatch) >>> from . import util - >>> fp = util.stringio() + >>> fp = io.BytesIO() >>> for c in reversedhunks: ... c.write(fp) >>> fp.seek(0) or None @@ -1734,7 +1733,7 @@ ... 7 ... 8 ... +9''' - >>> out = util.stringio() + >>> out = io.BytesIO() >>> headers = parsepatch([rawpatch], maxcontext=1) >>> for header in headers: ... header.write(out) @@ -1841,7 +1840,7 @@ } p = parser() - fp = stringio() + fp = io.BytesIO() fp.write(b''.join(originalchunks)) fp.seek(0) @@ -2030,7 +2029,7 @@ pos = lr.fp.tell() fp = lr.fp except IOError: - fp = stringio(lr.fp.read()) + fp = io.BytesIO(lr.fp.read()) gitlr = linereader(fp) gitlr.push(firstline) gitpatches = readgitpatch(gitlr) diff --git a/mercurial/profiling.py b/mercurial/profiling.py --- a/mercurial/profiling.py +++ b/mercurial/profiling.py @@ -7,6 +7,7 @@ import contextlib +import io from .i18n import _ from .pycompat import ( @@ -225,7 +226,7 @@ try: if self._output == b'blackbox': - self._fp = util.stringio() + self._fp = io.BytesIO() elif self._output: path = util.expandpath(self._output) self._fp = open(path, b'wb') diff --git a/mercurial/pure/mpatch.py b/mercurial/pure/mpatch.py --- a/mercurial/pure/mpatch.py +++ b/mercurial/pure/mpatch.py @@ -10,9 +10,6 @@ import struct -stringio = io.BytesIO - - class mpatchError(Exception): """error raised when a delta cannot be decoded""" @@ -71,7 +68,7 @@ if not tl: return a - m = stringio() + m = io.BytesIO() # load our original text m.write(a) diff --git a/mercurial/pure/parsers.py b/mercurial/pure/parsers.py --- a/mercurial/pure/parsers.py +++ b/mercurial/pure/parsers.py @@ -25,8 +25,6 @@ from ..revlogutils import nodemap as nodemaputil from ..revlogutils import constants as revlog_constants -stringio = io.BytesIO - _pack = struct.pack _unpack = struct.unpack @@ -955,7 +953,7 @@ def pack_dirstate(dmap, copymap, pl): - cs = stringio() + cs = io.BytesIO() write = cs.write write(b"".join(pl)) for f, e in dmap.items(): diff --git a/mercurial/url.py b/mercurial/url.py --- a/mercurial/url.py +++ b/mercurial/url.py @@ -9,6 +9,7 @@ import base64 +import io import socket from .i18n import _ @@ -29,7 +30,6 @@ ) httplib = util.httplib -stringio = util.stringio urlerr = util.urlerr urlreq = util.urlreq @@ -276,7 +276,7 @@ res.length = None res.chunked = 0 res.will_close = 1 - res.msg = httplib.HTTPMessage(stringio()) + res.msg = httplib.HTTPMessage(io.BytesIO()) return False res.msg = httplib.HTTPMessage(res.fp) diff --git a/mercurial/wireprotoserver.py b/mercurial/wireprotoserver.py --- a/mercurial/wireprotoserver.py +++ b/mercurial/wireprotoserver.py @@ -6,6 +6,7 @@ import contextlib +import io import struct import threading @@ -24,8 +25,6 @@ stringutil, ) -stringio = util.stringio - urlerr = util.urlerr urlreq = util.urlreq @@ -117,7 +116,7 @@ oldout = self._ui.fout olderr = self._ui.ferr - out = util.stringio() + out = io.BytesIO() try: self._ui.fout = out