Patchwork [5,of,5] pycompat: switch to util.stringio for py3 compat

login
register
mail settings
Submitter timeless@mozdev.org
Date April 10, 2016, 9:57 p.m.
Message ID <c4a1613bab8cd2905e27.1460325458@waste.org>
Download mbox | patch
Permalink /patch/14496/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - April 10, 2016, 9:57 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1460321737 0
#      Sun Apr 10 20:55:37 2016 +0000
# Node ID c4a1613bab8cd2905e271995e192b2f9db7e9886
# Parent  4b0632dccc1c8b346bfff5689aa75ed06a265c21
pycompat: switch to util.stringio for py3 compat
timeless - April 10, 2016, 10 p.m.
This is a placeholder series, the real series runs is Available At
https://bitbucket.org/timeless/mercurial-crew
             hg pull https://bitbucket.org/timeless/mercurial-crew -r
eeb488adee2f

If this series is applied to @committed (d54a7410307f) it will work
nicely. It doesn't actually work with @default (c5565fc8848d), as it
needs (68a946e83188 pycompat: util.stringio).

On Sun, Apr 10, 2016 at 5:57 PM, timeless <timeless@mozdev.org> wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1460321737 0
> #      Sun Apr 10 20:55:37 2016 +0000
> # Node ID c4a1613bab8cd2905e271995e192b2f9db7e9886
> # Parent  4b0632dccc1c8b346bfff5689aa75ed06a265c21
> pycompat: switch to util.stringio for py3 compat
>
> diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py
> --- a/hgext/convert/cvs.py
> +++ b/hgext/convert/cvs.py
> @@ -6,7 +6,6 @@
>  # GNU General Public License version 2 or any later version.
>  from __future__ import absolute_import
>
> -import cStringIO
>  import errno
>  import os
>  import re
> @@ -24,7 +23,7 @@
>      cvsps,
>  )
>
> -StringIO = cStringIO.StringIO
> +stringio = util.stringio
>  checktool = common.checktool
>  commit = common.commit
>  converter_source = common.converter_source
> @@ -228,7 +227,7 @@
>              # file-objects returned by socket.makefile() do not handle
>              # large read() requests very well.
>              chunksize = 65536
> -            output = StringIO()
> +            output = stringio()
>              while count > 0:
>                  data = fp.read(min(count, chunksize))
>                  if not data:
> diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
> --- a/hgext/convert/hg.py
> +++ b/hgext/convert/hg.py
> @@ -18,7 +18,6 @@
>  #   source.
>  from __future__ import absolute_import
>
> -import cStringIO
>  import os
>  import re
>  import time
> @@ -36,6 +35,8 @@
>      scmutil,
>      util,
>  )
> +stringio = util.stringio
> +
>  from mercurial.i18n import _
>  from . import common
>  mapfile = common.mapfile
> @@ -137,7 +138,7 @@
>              self.before()
>
>      def _rewritetags(self, source, revmap, data):
> -        fp = cStringIO.StringIO()
> +        fp = stringio()
>          for line in data.splitlines():
>              s = line.split(' ', 1)
>              if len(s) != 2:
> @@ -152,7 +153,7 @@
>          return fp.getvalue()
>
>      def _rewritesubstate(self, source, data):
> -        fp = cStringIO.StringIO()
> +        fp = stringio()
>          for line in data.splitlines():
>              s = line.split(' ', 1)
>              if len(s) != 2:
> diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
> --- a/hgext/convert/subversion.py
> +++ b/hgext/convert/subversion.py
> @@ -4,7 +4,6 @@
>  from __future__ import absolute_import
>
>  import cPickle as pickle
> -import cStringIO
>  import os
>  import re
>  import sys
> @@ -24,7 +23,7 @@
>
>  from . import common
>
> -StringIO = cStringIO.StringIO
> +stringio = util.stringio
>  propertycache = util.propertycache
>
>  commandline = common.commandline
> @@ -986,7 +985,7 @@
>              if self.module != new_module:
>                  self.module = new_module
>                  self.reparent(self.module)
> -            io = StringIO()
> +            io = stringio()
>              info = svn.ra.get_file(self.ra, file, revnum, io)
>              data = io.getvalue()
>              # ra.get_file() seems to keep a reference on the input buffer
> diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
> --- a/hgext/patchbomb.py
> +++ b/hgext/patchbomb.py
> @@ -65,7 +65,6 @@
>  '''
>  from __future__ import absolute_import
>
> -import cStringIO
>  import email as emailmod
>  import errno
>  import os
> @@ -83,6 +82,7 @@
>      scmutil,
>      util,
>  )
> +stringio = util.stringio
>  from mercurial.i18n import _
>
>  cmdtable = {}
> @@ -228,7 +228,7 @@
>          if r == prev and (repo[None].files() or repo[None].deleted()):
>              ui.warn(_('warning: working directory has '
>                        'uncommitted changes\n'))
> -        output = cStringIO.StringIO()
> +        output = stringio()
>          cmdutil.export(repo, [r], fp=output,
>                       opts=patch.difffeatureopts(ui, opts, git=True))
>          yield output.getvalue().split('\n')
> @@ -721,7 +721,7 @@
>              if not mbox:
>                  # Exim does not remove the Bcc field
>                  del m['Bcc']
> -            fp = cStringIO.StringIO()
> +            fp = stringio()
>              generator = emailmod.Generator.Generator(fp, mangle_from_=False)
>              generator.flatten(m, 0)
>              sendmail(sender_addr, to + bcc + cc, fp.getvalue())
> diff --git a/mercurial/archival.py b/mercurial/archival.py
> --- a/mercurial/archival.py
> +++ b/mercurial/archival.py
> @@ -7,7 +7,6 @@
>
>  from __future__ import absolute_import
>
> -import cStringIO
>  import gzip
>  import os
>  import struct
> @@ -26,6 +25,7 @@
>      scmutil,
>      util,
>  )
> +stringio = util.stringio
>
>  # from unzip source code:
>  _UNX_IFREG = 0x8000
> @@ -172,7 +172,7 @@
>              i.size = 0
>          else:
>              i.mode = mode
> -            data = cStringIO.StringIO(data)
> +            data = stringio(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
> @@ -7,7 +7,6 @@
>
>  from __future__ import absolute_import
>
> -import cStringIO
>  import errno
>  import os
>  import re
> @@ -46,6 +45,7 @@
>      templater,
>      util,
>  )
> +stringio = util.stringio
>
>  def ishunk(x):
>      hunkclasses = (crecordmod.uihunk, patch.recordhunk)
> @@ -211,7 +211,7 @@
>                  util.copyfile(repo.wjoin(f), tmpname, copystat=True)
>                  backups[f] = tmpname
>
> -            fp = cStringIO.StringIO()
> +            fp = stringio()
>              for c in chunks:
>                  fname = c.filename()
>                  if fname in backups:
> @@ -3302,7 +3302,7 @@
>
>          newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
>          # Apply changes
> -        fp = cStringIO.StringIO()
> +        fp = stringio()
>          for c in chunks:
>              c.write(fp)
>          dopatch = fp.tell()
> diff --git a/mercurial/crecord.py b/mercurial/crecord.py
> --- a/mercurial/crecord.py
> +++ b/mercurial/crecord.py
> @@ -10,7 +10,6 @@
>
>  from __future__ import absolute_import
>
> -import cStringIO
>  import locale
>  import os
>  import re
> @@ -25,6 +24,7 @@
>      patch as patchmod,
>      util,
>  )
> +stringio = util.stringio
>
>  # This is required for ncurses to display non-ASCII characters in default user
>  # locale encoding correctly.  --immerrr
> @@ -238,7 +238,7 @@
>
>
>      def prettystr(self):
> -        x = cStringIO.StringIO()
> +        x = stringio()
>          self.pretty(x)
>          return x.getvalue()
>
> @@ -449,7 +449,7 @@
>      pretty = write
>
>      def prettystr(self):
> -        x = cStringIO.StringIO()
> +        x = stringio()
>          self.pretty(x)
>          return x.getvalue()
>
> @@ -1506,7 +1506,7 @@
>                  return None
>
>              # write the initial patch
> -            patch = cStringIO.StringIO()
> +            patch = stringio()
>              patch.write(diffhelptext + hunkhelptext)
>              chunk.header.write(patch)
>              chunk.write(patch)
> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -988,8 +988,7 @@
>          output = ui.config('profiling', 'output')
>
>          if output == 'blackbox':
> -            import StringIO
> -            fp = StringIO.StringIO()
> +            fp = util.stringio()
>          elif output:
>              path = ui.expandpath(output)
>              fp = open(path, 'wb')
> diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
> --- a/mercurial/hgweb/protocol.py
> +++ b/mercurial/hgweb/protocol.py
> @@ -7,7 +7,6 @@
>
>  from __future__ import absolute_import
>
> -import cStringIO
>  import cgi
>  import urllib
>  import zlib
> @@ -20,6 +19,7 @@
>      util,
>      wireproto,
>  )
> +stringio = util.stringio
>
>  HGTYPE = 'application/mercurial-0.1'
>  HGERRTYPE = 'application/hg-error'
> @@ -66,7 +66,7 @@
>              fp.write(s)
>      def redirect(self):
>          self.oldio = self.ui.fout, self.ui.ferr
> -        self.ui.ferr = self.ui.fout = cStringIO.StringIO()
> +        self.ui.ferr = self.ui.fout = stringio()
>      def restore(self):
>          val = self.ui.fout.getvalue()
>          self.ui.ferr, self.ui.fout = self.oldio
> diff --git a/mercurial/httpclient/__init__.py b/mercurial/httpclient/__init__.py
> --- a/mercurial/httpclient/__init__.py
> +++ b/mercurial/httpclient/__init__.py
> @@ -41,7 +41,6 @@
>  # Many functions in this file have too many arguments.
>  # pylint: disable=R0913
>
> -import cStringIO
>  import errno
>  import httplib
>  import logging
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -8,7 +8,6 @@
>
>  from __future__ import absolute_import
>
> -import cStringIO
>  import collections
>  import copy
>  import email
> @@ -37,6 +36,7 @@
>      scmutil,
>      util,
>  )
> +stringio = util.stringio
>
>  gitre = re.compile('diff --git a/(.*) b/(.*)')
>  tabsplitter = re.compile(r'(\t+|[^\t]+)')
> @@ -60,7 +60,7 @@
>          return len(l) == 2 and ' ' not in l[0]
>
>      def chunk(lines):
> -        return cStringIO.StringIO(''.join(lines))
> +        return stringio(''.join(lines))
>
>      def hgsplit(stream, cur):
>          inheader = True
> @@ -93,7 +93,7 @@
>
>      def mimesplit(stream, cur):
>          def msgfp(m):
> -            fp = cStringIO.StringIO()
> +            fp = stringio()
>              g = email.Generator.Generator(fp, mangle_from_=False)
>              g.flatten(m)
>              fp.seek(0)
> @@ -246,7 +246,7 @@
>
>                  ui.debug('found patch at byte %d\n' % m.start(0))
>                  diffs_seen += 1
> -                cfp = cStringIO.StringIO()
> +                cfp = stringio()
>                  for line in payload[:m.start(0)].splitlines():
>                      if line.startswith('# HG changeset patch') and not hgpatch:
>                          ui.debug('patch generated by hg export\n')
> @@ -1057,7 +1057,7 @@
>                          continue
>                      # Remove comment lines
>                      patchfp = open(patchfn)
> -                    ncpatchfp = cStringIO.StringIO()
> +                    ncpatchfp = stringio()
>                      for line in patchfp:
>                          if not line.startswith('#'):
>                              ncpatchfp.write(line)
> @@ -1440,7 +1440,8 @@
>      ...     hunkscomingfromfilterpatch.extend(h.hunks)
>
>      >>> reversedhunks = reversehunks(hunkscomingfromfilterpatch)
> -    >>> fp = cStringIO.StringIO()
> +    >>> from . import util
> +    >>> fp = util.stringio()
>      >>> for c in reversedhunks:
>      ...      c.write(fp)
>      >>> fp.seek(0)
> @@ -1553,7 +1554,7 @@
>              }
>
>      p = parser()
> -    fp = cStringIO.StringIO()
> +    fp = stringio()
>      fp.write(''.join(originalchunks))
>      fp.seek(0)
>
> @@ -1732,7 +1733,7 @@
>          pos = lr.fp.tell()
>          fp = lr.fp
>      except IOError:
> -        fp = cStringIO.StringIO(lr.fp.read())
> +        fp = stringio(lr.fp.read())
>      gitlr = linereader(fp)
>      gitlr.push(firstline)
>      gitpatches = readgitpatch(gitlr)
> diff --git a/mercurial/pure/mpatch.py b/mercurial/pure/mpatch.py
> --- a/mercurial/pure/mpatch.py
> +++ b/mercurial/pure/mpatch.py
> @@ -7,10 +7,10 @@
>
>  from __future__ import absolute_import
>
> -import cStringIO
>  import struct
>
> -StringIO = cStringIO.StringIO
> +from . import pycompat
> +stringio = pycompat.stringio
>
>  class mpatchError(Exception):
>      """error raised when a delta cannot be decoded
> @@ -66,7 +66,7 @@
>      if not tl:
>          return a
>
> -    m = StringIO()
> +    m = stringio()
>
>      # 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
> @@ -7,11 +7,12 @@
>
>  from __future__ import absolute_import
>
> -import cStringIO
>  import struct
>  import zlib
>
>  from .node import nullid
> +from . import pycompat
> +stringio = pycompat.stringio
>
>  _pack = struct.pack
>  _unpack = struct.unpack
> @@ -90,7 +91,7 @@
>
>  def pack_dirstate(dmap, copymap, pl, now):
>      now = int(now)
> -    cs = cStringIO.StringIO()
> +    cs = stringio()
>      write = cs.write
>      write("".join(pl))
>      for f, e in dmap.iteritems():
> diff --git a/mercurial/url.py b/mercurial/url.py
> --- a/mercurial/url.py
> +++ b/mercurial/url.py
> @@ -10,7 +10,6 @@
>  from __future__ import absolute_import
>
>  import base64
> -import cStringIO
>  import httplib
>  import os
>  import socket
> @@ -25,6 +24,7 @@
>      sslutil,
>      util,
>  )
> +stringio = util.stringio
>
>  class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm):
>      def __init__(self, ui):
> @@ -273,7 +273,7 @@
>          res.length = None
>          res.chunked = 0
>          res.will_close = 1
> -        res.msg = httplib.HTTPMessage(cStringIO.StringIO())
> +        res.msg = httplib.HTTPMessage(stringio())
>          return False
>
>      res.msg = httplib.HTTPMessage(res.fp)
> diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
> --- a/tests/test-check-py3-compat.t
> +++ b/tests/test-check-py3-compat.t
> @@ -74,153 +74,129 @@
>    $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py
>    contrib/check-code.py: invalid syntax: (unicode error) 'unicodeescape' codec can't decode bytes in position *-*: malformed \N character escape (<unknown>, line *) (glob)
>    doc/hgmanpage.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
> -  hgext/acl.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
>    hgext/automv.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
> -  hgext/blackbox.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> +  hgext/blackbox.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    hgext/bugzilla.py: error importing module: <ImportError> No module named 'urlparse' (line *) (glob)
> -  hgext/censor.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> +  hgext/censor.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    hgext/chgserver.py: error importing module: <ImportError> No module named 'SocketServer' (line *) (glob)
> -  hgext/children.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/churn.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/clonebundles.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> +  hgext/children.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/churn.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/clonebundles.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    hgext/color.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
>    hgext/convert/bzr.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
>    hgext/convert/common.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
> -  hgext/convert/convcmd.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/convert/cvs.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> +  hgext/convert/convcmd.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
> +  hgext/convert/cvs.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
>    hgext/convert/cvsps.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
> -  hgext/convert/darcs.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  hgext/convert/darcs.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
>    hgext/convert/filemap.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> -  hgext/convert/git.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/convert/gnuarch.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/convert/hg.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> -  hgext/convert/monotone.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/convert/p*.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  hgext/convert/git.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> +  hgext/convert/gnuarch.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> +  hgext/convert/hg.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/convert/monotone.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
> +  hgext/convert/p*.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
>    hgext/convert/subversion.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
>    hgext/convert/transport.py: error importing module: <ImportError> No module named 'svn.client' (line *) (glob)
> -  hgext/eol.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/extdiff.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/factotum.py: error importing: <ImportError> No module named 'cStringIO' (error at url.py:*) (glob)
> +  hgext/eol.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/extdiff.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/factotum.py: error importing: <ImportError> No module named 'httplib' (error at url.py:*) (glob)
>    hgext/fetch.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
> -  hgext/fsmonitor/state.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/fsmonitor/watchmanclient.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/gpg.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/graphlog.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/hgcia.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/hgk.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/highlight/highlight.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  hgext/fsmonitor/watchmanclient.py: error importing module: <SystemError> Parent module 'hgext.fsmonitor' not loaded, cannot perform relative import (line *) (glob)
> +  hgext/gpg.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
> +  hgext/graphlog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/hgcia.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/hgk.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    hgext/histedit.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
> -  hgext/keyword.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/largefiles/basestore.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/largefiles/lfcommands.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/largefiles/lfutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  hgext/keyword.py: error importing: <ImportError> No module named 'BaseHTTPServer' (error at common.py:*) (glob)
> +  hgext/largefiles/basestore.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
> +  hgext/largefiles/lfcommands.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
> +  hgext/largefiles/lfutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    hgext/largefiles/localstore.py: error importing module: <ImportError> No module named 'lfutil' (line *) (glob)
> -  hgext/largefiles/overrides.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  hgext/largefiles/overrides.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
>    hgext/largefiles/proto.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
>    hgext/largefiles/remotestore.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
> -  hgext/largefiles/reposetup.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  hgext/largefiles/reposetup.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    hgext/largefiles/uisetup.py: error importing module: <SyntaxError> invalid syntax (archival.py, line *) (line *) (glob)
>    hgext/largefiles/wirestore.py: error importing module: <ImportError> No module named 'lfutil' (line *) (glob)
> -  hgext/mq.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/notify.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/pager.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/patchbomb.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> -  hgext/purge.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/rebase.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  hgext/record.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/relink.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/schemes.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  hgext/share.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> +  hgext/mq.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
> +  hgext/notify.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/pager.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/patchbomb.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/purge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/rebase.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
> +  hgext/record.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/relink.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/schemes.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  hgext/share.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    hgext/shelve.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
> -  hgext/strip.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  hgext/strip.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    hgext/transplant.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
> -  hgext/win*text.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
>    mercurial/archival.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
> -  mercurial/bookmarks.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/branchmap.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  mercurial/branchmap.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    mercurial/bundle*.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
>    mercurial/bundlerepo.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
>    mercurial/byterange.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
> -  mercurial/changegroup.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/changelog.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
> -  mercurial/cmdutil.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> +  mercurial/changegroup.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/changelog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/cmdutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    mercurial/commands.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
>    mercurial/commandserver.py: error importing module: <ImportError> No module named 'SocketServer' (line *) (glob)
> -  mercurial/config.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/context.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/copies.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/crecord.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> -  mercurial/destutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/dirstate.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/discovery.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/dispatch.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> +  mercurial/context.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/copies.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/crecord.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/dirstate.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/discovery.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/dispatch.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    mercurial/exchange.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
> -  mercurial/extensions.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  mercurial/filelog.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
> -  mercurial/filemerge.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/fileset.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  mercurial/extensions.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/filelog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/filemerge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/fileset.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    mercurial/formatter.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
> -  mercurial/graphmod.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/help.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  mercurial/hg.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  mercurial/graphmod.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/help.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/hg.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
>    mercurial/hgweb/common.py: error importing module: <ImportError> No module named 'BaseHTTPServer' (line *) (glob)
>    mercurial/hgweb/hgweb_mod.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
>    mercurial/hgweb/hgwebdir_mod.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
> -  mercurial/hgweb/protocol.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> +  mercurial/hgweb/protocol.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
>    mercurial/hgweb/request.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
>    mercurial/hgweb/server.py: error importing module: <ImportError> No module named 'BaseHTTPServer' (line *) (glob)
>    mercurial/hgweb/webcommands.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
>    mercurial/hgweb/webutil.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
>    mercurial/hgweb/wsgicgi.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
> -  mercurial/hook.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> +  mercurial/hook.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    mercurial/httpclient/_readers.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
>    mercurial/httpconnection.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
>    mercurial/httppeer.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
>    mercurial/keepalive.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
> -  mercurial/localrepo.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/lock.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/mail.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/manifest.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
> -  mercurial/match.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/mdiff.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
> -  mercurial/merge.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/minirst.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/namespaces.py: error importing: <ImportError> No module named 'cStringIO' (error at patch.py:*) (glob)
> -  mercurial/obsolete.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/patch.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> -  mercurial/pathutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/peer.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/pure/mpatch.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> -  mercurial/pure/parsers.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> -  mercurial/pushkey.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/pvec.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/registrar.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  mercurial/localrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/mail.py: error importing module: <AttributeError> module 'email' has no attribute 'Header' (line *) (glob)
> +  mercurial/manifest.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/merge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/namespaces.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/patch.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/pure/mpatch.py: error importing module: <ImportError> cannot import name 'pycompat' (line *) (glob)
> +  mercurial/pure/parsers.py: error importing module: <ImportError> No module named 'mercurial.pure.node' (line *) (glob)
>    mercurial/repair.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
> -  mercurial/repoview.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/revlog.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
> -  mercurial/revset.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/scmutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  mercurial/revlog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/revset.py: error importing module: <AttributeError> 'dict' object has no attribute 'iteritems' (line *) (glob)
> +  mercurial/scmutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    mercurial/scmwindows.py: error importing module: <ImportError> No module named '_winreg' (line *) (glob)
> -  mercurial/similar.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
> -  mercurial/simplemerge.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
> -  mercurial/sshpeer.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/sshserver.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  mercurial/sslutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> +  mercurial/simplemerge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/sshpeer.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at wireproto.py:*) (glob)
> +  mercurial/sshserver.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    mercurial/statichttprepo.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
> -  mercurial/store.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/streamclone.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/subrepo.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
> -  mercurial/tagmerge.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/tags.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/templatefilters.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/templatekw.py: error importing: <ImportError> No module named 'cStringIO' (error at patch.py:*) (glob)
> -  mercurial/templater.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/transaction.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/ui.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/unionrepo.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
> -  mercurial/url.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
> -  mercurial/util.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
> -  mercurial/verify.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
> +  mercurial/store.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/streamclone.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/subrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/templatefilters.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/templatekw.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/templater.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/ui.py: error importing: <ImportError> No module named 'cPickle' (error at formatter.py:*) (glob)
> +  mercurial/unionrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
> +  mercurial/url.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
> +  mercurial/verify.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
>    mercurial/win*.py: error importing module: <ImportError> No module named 'msvcrt' (line *) (glob)
>    mercurial/windows.py: error importing module: <ImportError> No module named '_winreg' (line *) (glob)
>    mercurial/wireproto.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
> diff --git a/tests/test-hgweb-no-path-info.t b/tests/test-hgweb-no-path-info.t
> --- a/tests/test-hgweb-no-path-info.t
> +++ b/tests/test-hgweb-no-path-info.t
> @@ -18,14 +18,17 @@
>    > from __future__ import absolute_import
>    > import os
>    > import sys
> -  > from StringIO import StringIO
>    > from mercurial.hgweb import (
>    >     hgweb,
>    >     hgwebdir,
>    > )
> +  > from mercurial import (
> +  >     util,
> +  > )
> +  > stringio = util.stringio
>    >
> -  > errors = StringIO()
> -  > input = StringIO()
> +  > errors = stringio()
> +  > input = stringio()
>    >
>    > def startrsp(status, headers):
>    >     print '---- STATUS'
> @@ -59,11 +62,11 @@
>    >     print '---- ERRORS'
>    >     print errors.getvalue()
>    >
> -  > output = StringIO()
> +  > output = stringio()
>    > env['QUERY_STRING'] = 'style=atom'
>    > process(hgweb('.', name='repo'))
>    >
> -  > output = StringIO()
> +  > output = stringio()
>    > env['QUERY_STRING'] = 'style=raw'
>    > process(hgwebdir({'repo': '.'}))
>    > EOF
> diff --git a/tests/test-hgweb-no-request-uri.t b/tests/test-hgweb-no-request-uri.t
> --- a/tests/test-hgweb-no-request-uri.t
> +++ b/tests/test-hgweb-no-request-uri.t
> @@ -18,14 +18,17 @@
>    > from __future__ import absolute_import
>    > import os
>    > import sys
> -  > from StringIO import StringIO
>    > from mercurial.hgweb import (
>    >     hgweb,
>    >     hgwebdir,
>    > )
> +  > from mercurial import (
> +  >     util,
> +  > )
> +  > stringio = util.stringio
>    >
> -  > errors = StringIO()
> -  > input = StringIO()
> +  > errors = stringio()
> +  > input = stringio()
>    >
>    > def startrsp(status, headers):
>    >     print '---- STATUS'
> @@ -58,22 +61,22 @@
>    >     print '---- ERRORS'
>    >     print errors.getvalue()
>    >
> -  > output = StringIO()
> +  > output = stringio()
>    > env['PATH_INFO'] = '/'
>    > env['QUERY_STRING'] = 'style=atom'
>    > process(hgweb('.', name = 'repo'))
>    >
> -  > output = StringIO()
> +  > output = stringio()
>    > env['PATH_INFO'] = '/file/tip/'
>    > env['QUERY_STRING'] = 'style=raw'
>    > process(hgweb('.', name = 'repo'))
>    >
> -  > output = StringIO()
> +  > output = stringio()
>    > env['PATH_INFO'] = '/'
>    > env['QUERY_STRING'] = 'style=raw'
>    > process(hgwebdir({'repo': '.'}))
>    >
> -  > output = StringIO()
> +  > output = stringio()
>    > env['PATH_INFO'] = '/repo/file/tip/'
>    > env['QUERY_STRING'] = 'style=raw'
>    > process(hgwebdir({'repo': '.'}))
> diff --git a/tests/test-hgweb-non-interactive.t b/tests/test-hgweb-non-interactive.t
> --- a/tests/test-hgweb-non-interactive.t
> +++ b/tests/test-hgweb-non-interactive.t
> @@ -10,16 +10,17 @@
>    > from __future__ import absolute_import
>    > import os
>    > import sys
> -  > from StringIO import StringIO
>    > from mercurial import (
>    >     dispatch,
>    >     hg,
>    >     ui as uimod,
> +  >     util,
>    > )
>    > ui = uimod.ui
>    > from mercurial.hgweb.hgweb_mod import (
>    >     hgweb,
>    > )
> +  > stringio = util.stringio
>    >
>    > class FileLike(object):
>    >     def __init__(self, real):
> @@ -35,9 +36,9 @@
>    >         return self.real.readline()
>    >
>    > sys.stdin = FileLike(sys.stdin)
> -  > errors = StringIO()
> -  > input = StringIO()
> -  > output = StringIO()
> +  > errors = stringio()
> +  > input = stringio()
> +  > output = stringio()
>    >
>    > def startrsp(status, headers):
>    >     print '---- STATUS'
> diff --git a/tests/test-simplemerge.py b/tests/test-simplemerge.py
> --- a/tests/test-simplemerge.py
> +++ b/tests/test-simplemerge.py
> @@ -36,8 +36,7 @@
>  CantReprocessAndShowBase = simplemerge.CantReprocessAndShowBase
>
>  def split_lines(t):
> -    from cStringIO import StringIO
> -    return StringIO(t).readlines()
> +    return util.stringio(t).readlines()
>
>  ############################################################
>  # test case data from the gnu diffutils manual
> diff --git a/tests/test-wireproto.py b/tests/test-wireproto.py
> --- a/tests/test-wireproto.py
> +++ b/tests/test-wireproto.py
> @@ -1,9 +1,10 @@
>  from __future__ import absolute_import, print_function
>
> -import StringIO
>  from mercurial import (
> +    util,
>      wireproto,
>  )
> +stringio = util.stringio
>
>  class proto(object):
>      def __init__(self, args):
> @@ -25,7 +26,7 @@
>          return wireproto.dispatch(self.serverrepo, proto(args), cmd)
>
>      def _callstream(self, cmd, **args):
> -        return StringIO.StringIO(self._call(cmd, **args))
> +        return stringio(self._call(cmd, **args))
>
>      @wireproto.batchable
>      def greet(self, name):
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py
--- a/hgext/convert/cvs.py
+++ b/hgext/convert/cvs.py
@@ -6,7 +6,6 @@ 
 # GNU General Public License version 2 or any later version.
 from __future__ import absolute_import
 
-import cStringIO
 import errno
 import os
 import re
@@ -24,7 +23,7 @@ 
     cvsps,
 )
 
-StringIO = cStringIO.StringIO
+stringio = util.stringio
 checktool = common.checktool
 commit = common.commit
 converter_source = common.converter_source
@@ -228,7 +227,7 @@ 
             # file-objects returned by socket.makefile() do not handle
             # large read() requests very well.
             chunksize = 65536
-            output = StringIO()
+            output = stringio()
             while count > 0:
                 data = fp.read(min(count, chunksize))
                 if not data:
diff --git a/hgext/convert/hg.py b/hgext/convert/hg.py
--- a/hgext/convert/hg.py
+++ b/hgext/convert/hg.py
@@ -18,7 +18,6 @@ 
 #   source.
 from __future__ import absolute_import
 
-import cStringIO
 import os
 import re
 import time
@@ -36,6 +35,8 @@ 
     scmutil,
     util,
 )
+stringio = util.stringio
+
 from mercurial.i18n import _
 from . import common
 mapfile = common.mapfile
@@ -137,7 +138,7 @@ 
             self.before()
 
     def _rewritetags(self, source, revmap, data):
-        fp = cStringIO.StringIO()
+        fp = stringio()
         for line in data.splitlines():
             s = line.split(' ', 1)
             if len(s) != 2:
@@ -152,7 +153,7 @@ 
         return fp.getvalue()
 
     def _rewritesubstate(self, source, data):
-        fp = cStringIO.StringIO()
+        fp = stringio()
         for line in data.splitlines():
             s = line.split(' ', 1)
             if len(s) != 2:
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -4,7 +4,6 @@ 
 from __future__ import absolute_import
 
 import cPickle as pickle
-import cStringIO
 import os
 import re
 import sys
@@ -24,7 +23,7 @@ 
 
 from . import common
 
-StringIO = cStringIO.StringIO
+stringio = util.stringio
 propertycache = util.propertycache
 
 commandline = common.commandline
@@ -986,7 +985,7 @@ 
             if self.module != new_module:
                 self.module = new_module
                 self.reparent(self.module)
-            io = StringIO()
+            io = stringio()
             info = svn.ra.get_file(self.ra, file, revnum, io)
             data = io.getvalue()
             # ra.get_file() seems to keep a reference on the input buffer
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -65,7 +65,6 @@ 
 '''
 from __future__ import absolute_import
 
-import cStringIO
 import email as emailmod
 import errno
 import os
@@ -83,6 +82,7 @@ 
     scmutil,
     util,
 )
+stringio = util.stringio
 from mercurial.i18n import _
 
 cmdtable = {}
@@ -228,7 +228,7 @@ 
         if r == prev and (repo[None].files() or repo[None].deleted()):
             ui.warn(_('warning: working directory has '
                       'uncommitted changes\n'))
-        output = cStringIO.StringIO()
+        output = stringio()
         cmdutil.export(repo, [r], fp=output,
                      opts=patch.difffeatureopts(ui, opts, git=True))
         yield output.getvalue().split('\n')
@@ -721,7 +721,7 @@ 
             if not mbox:
                 # Exim does not remove the Bcc field
                 del m['Bcc']
-            fp = cStringIO.StringIO()
+            fp = stringio()
             generator = emailmod.Generator.Generator(fp, mangle_from_=False)
             generator.flatten(m, 0)
             sendmail(sender_addr, to + bcc + cc, fp.getvalue())
diff --git a/mercurial/archival.py b/mercurial/archival.py
--- a/mercurial/archival.py
+++ b/mercurial/archival.py
@@ -7,7 +7,6 @@ 
 
 from __future__ import absolute_import
 
-import cStringIO
 import gzip
 import os
 import struct
@@ -26,6 +25,7 @@ 
     scmutil,
     util,
 )
+stringio = util.stringio
 
 # from unzip source code:
 _UNX_IFREG = 0x8000
@@ -172,7 +172,7 @@ 
             i.size = 0
         else:
             i.mode = mode
-            data = cStringIO.StringIO(data)
+            data = stringio(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
@@ -7,7 +7,6 @@ 
 
 from __future__ import absolute_import
 
-import cStringIO
 import errno
 import os
 import re
@@ -46,6 +45,7 @@ 
     templater,
     util,
 )
+stringio = util.stringio
 
 def ishunk(x):
     hunkclasses = (crecordmod.uihunk, patch.recordhunk)
@@ -211,7 +211,7 @@ 
                 util.copyfile(repo.wjoin(f), tmpname, copystat=True)
                 backups[f] = tmpname
 
-            fp = cStringIO.StringIO()
+            fp = stringio()
             for c in chunks:
                 fname = c.filename()
                 if fname in backups:
@@ -3302,7 +3302,7 @@ 
 
         newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
         # Apply changes
-        fp = cStringIO.StringIO()
+        fp = stringio()
         for c in chunks:
             c.write(fp)
         dopatch = fp.tell()
diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -10,7 +10,6 @@ 
 
 from __future__ import absolute_import
 
-import cStringIO
 import locale
 import os
 import re
@@ -25,6 +24,7 @@ 
     patch as patchmod,
     util,
 )
+stringio = util.stringio
 
 # This is required for ncurses to display non-ASCII characters in default user
 # locale encoding correctly.  --immerrr
@@ -238,7 +238,7 @@ 
 
 
     def prettystr(self):
-        x = cStringIO.StringIO()
+        x = stringio()
         self.pretty(x)
         return x.getvalue()
 
@@ -449,7 +449,7 @@ 
     pretty = write
 
     def prettystr(self):
-        x = cStringIO.StringIO()
+        x = stringio()
         self.pretty(x)
         return x.getvalue()
 
@@ -1506,7 +1506,7 @@ 
                 return None
 
             # write the initial patch
-            patch = cStringIO.StringIO()
+            patch = stringio()
             patch.write(diffhelptext + hunkhelptext)
             chunk.header.write(patch)
             chunk.write(patch)
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -988,8 +988,7 @@ 
         output = ui.config('profiling', 'output')
 
         if output == 'blackbox':
-            import StringIO
-            fp = StringIO.StringIO()
+            fp = util.stringio()
         elif output:
             path = ui.expandpath(output)
             fp = open(path, 'wb')
diff --git a/mercurial/hgweb/protocol.py b/mercurial/hgweb/protocol.py
--- a/mercurial/hgweb/protocol.py
+++ b/mercurial/hgweb/protocol.py
@@ -7,7 +7,6 @@ 
 
 from __future__ import absolute_import
 
-import cStringIO
 import cgi
 import urllib
 import zlib
@@ -20,6 +19,7 @@ 
     util,
     wireproto,
 )
+stringio = util.stringio
 
 HGTYPE = 'application/mercurial-0.1'
 HGERRTYPE = 'application/hg-error'
@@ -66,7 +66,7 @@ 
             fp.write(s)
     def redirect(self):
         self.oldio = self.ui.fout, self.ui.ferr
-        self.ui.ferr = self.ui.fout = cStringIO.StringIO()
+        self.ui.ferr = self.ui.fout = stringio()
     def restore(self):
         val = self.ui.fout.getvalue()
         self.ui.ferr, self.ui.fout = self.oldio
diff --git a/mercurial/httpclient/__init__.py b/mercurial/httpclient/__init__.py
--- a/mercurial/httpclient/__init__.py
+++ b/mercurial/httpclient/__init__.py
@@ -41,7 +41,6 @@ 
 # Many functions in this file have too many arguments.
 # pylint: disable=R0913
 
-import cStringIO
 import errno
 import httplib
 import logging
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -8,7 +8,6 @@ 
 
 from __future__ import absolute_import
 
-import cStringIO
 import collections
 import copy
 import email
@@ -37,6 +36,7 @@ 
     scmutil,
     util,
 )
+stringio = util.stringio
 
 gitre = re.compile('diff --git a/(.*) b/(.*)')
 tabsplitter = re.compile(r'(\t+|[^\t]+)')
@@ -60,7 +60,7 @@ 
         return len(l) == 2 and ' ' not in l[0]
 
     def chunk(lines):
-        return cStringIO.StringIO(''.join(lines))
+        return stringio(''.join(lines))
 
     def hgsplit(stream, cur):
         inheader = True
@@ -93,7 +93,7 @@ 
 
     def mimesplit(stream, cur):
         def msgfp(m):
-            fp = cStringIO.StringIO()
+            fp = stringio()
             g = email.Generator.Generator(fp, mangle_from_=False)
             g.flatten(m)
             fp.seek(0)
@@ -246,7 +246,7 @@ 
 
                 ui.debug('found patch at byte %d\n' % m.start(0))
                 diffs_seen += 1
-                cfp = cStringIO.StringIO()
+                cfp = stringio()
                 for line in payload[:m.start(0)].splitlines():
                     if line.startswith('# HG changeset patch') and not hgpatch:
                         ui.debug('patch generated by hg export\n')
@@ -1057,7 +1057,7 @@ 
                         continue
                     # Remove comment lines
                     patchfp = open(patchfn)
-                    ncpatchfp = cStringIO.StringIO()
+                    ncpatchfp = stringio()
                     for line in patchfp:
                         if not line.startswith('#'):
                             ncpatchfp.write(line)
@@ -1440,7 +1440,8 @@ 
     ...     hunkscomingfromfilterpatch.extend(h.hunks)
 
     >>> reversedhunks = reversehunks(hunkscomingfromfilterpatch)
-    >>> fp = cStringIO.StringIO()
+    >>> from . import util
+    >>> fp = util.stringio()
     >>> for c in reversedhunks:
     ...      c.write(fp)
     >>> fp.seek(0)
@@ -1553,7 +1554,7 @@ 
             }
 
     p = parser()
-    fp = cStringIO.StringIO()
+    fp = stringio()
     fp.write(''.join(originalchunks))
     fp.seek(0)
 
@@ -1732,7 +1733,7 @@ 
         pos = lr.fp.tell()
         fp = lr.fp
     except IOError:
-        fp = cStringIO.StringIO(lr.fp.read())
+        fp = stringio(lr.fp.read())
     gitlr = linereader(fp)
     gitlr.push(firstline)
     gitpatches = readgitpatch(gitlr)
diff --git a/mercurial/pure/mpatch.py b/mercurial/pure/mpatch.py
--- a/mercurial/pure/mpatch.py
+++ b/mercurial/pure/mpatch.py
@@ -7,10 +7,10 @@ 
 
 from __future__ import absolute_import
 
-import cStringIO
 import struct
 
-StringIO = cStringIO.StringIO
+from . import pycompat
+stringio = pycompat.stringio
 
 class mpatchError(Exception):
     """error raised when a delta cannot be decoded
@@ -66,7 +66,7 @@ 
     if not tl:
         return a
 
-    m = StringIO()
+    m = stringio()
 
     # 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
@@ -7,11 +7,12 @@ 
 
 from __future__ import absolute_import
 
-import cStringIO
 import struct
 import zlib
 
 from .node import nullid
+from . import pycompat
+stringio = pycompat.stringio
 
 _pack = struct.pack
 _unpack = struct.unpack
@@ -90,7 +91,7 @@ 
 
 def pack_dirstate(dmap, copymap, pl, now):
     now = int(now)
-    cs = cStringIO.StringIO()
+    cs = stringio()
     write = cs.write
     write("".join(pl))
     for f, e in dmap.iteritems():
diff --git a/mercurial/url.py b/mercurial/url.py
--- a/mercurial/url.py
+++ b/mercurial/url.py
@@ -10,7 +10,6 @@ 
 from __future__ import absolute_import
 
 import base64
-import cStringIO
 import httplib
 import os
 import socket
@@ -25,6 +24,7 @@ 
     sslutil,
     util,
 )
+stringio = util.stringio
 
 class passwordmgr(urllib2.HTTPPasswordMgrWithDefaultRealm):
     def __init__(self, ui):
@@ -273,7 +273,7 @@ 
         res.length = None
         res.chunked = 0
         res.will_close = 1
-        res.msg = httplib.HTTPMessage(cStringIO.StringIO())
+        res.msg = httplib.HTTPMessage(stringio())
         return False
 
     res.msg = httplib.HTTPMessage(res.fp)
diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t
+++ b/tests/test-check-py3-compat.t
@@ -74,153 +74,129 @@ 
   $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py
   contrib/check-code.py: invalid syntax: (unicode error) 'unicodeescape' codec can't decode bytes in position *-*: malformed \N character escape (<unknown>, line *) (glob)
   doc/hgmanpage.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
-  hgext/acl.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
   hgext/automv.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
-  hgext/blackbox.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
+  hgext/blackbox.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/bugzilla.py: error importing module: <ImportError> No module named 'urlparse' (line *) (glob)
-  hgext/censor.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
+  hgext/censor.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/chgserver.py: error importing module: <ImportError> No module named 'SocketServer' (line *) (glob)
-  hgext/children.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/churn.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/clonebundles.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
+  hgext/children.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/churn.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/clonebundles.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/color.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
   hgext/convert/bzr.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
   hgext/convert/common.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
-  hgext/convert/convcmd.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/convert/cvs.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
+  hgext/convert/convcmd.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
+  hgext/convert/cvs.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
   hgext/convert/cvsps.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
-  hgext/convert/darcs.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  hgext/convert/darcs.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
   hgext/convert/filemap.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
-  hgext/convert/git.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/convert/gnuarch.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/convert/hg.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
-  hgext/convert/monotone.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/convert/p*.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  hgext/convert/git.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
+  hgext/convert/gnuarch.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
+  hgext/convert/hg.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/convert/monotone.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
+  hgext/convert/p*.py: error importing module: <SystemError> Parent module 'hgext.convert' not loaded, cannot perform relative import (line *) (glob)
   hgext/convert/subversion.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
   hgext/convert/transport.py: error importing module: <ImportError> No module named 'svn.client' (line *) (glob)
-  hgext/eol.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/extdiff.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/factotum.py: error importing: <ImportError> No module named 'cStringIO' (error at url.py:*) (glob)
+  hgext/eol.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/extdiff.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/factotum.py: error importing: <ImportError> No module named 'httplib' (error at url.py:*) (glob)
   hgext/fetch.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
-  hgext/fsmonitor/state.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/fsmonitor/watchmanclient.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/gpg.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/graphlog.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/hgcia.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/hgk.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/highlight/highlight.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  hgext/fsmonitor/watchmanclient.py: error importing module: <SystemError> Parent module 'hgext.fsmonitor' not loaded, cannot perform relative import (line *) (glob)
+  hgext/gpg.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
+  hgext/graphlog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/hgcia.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/hgk.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/histedit.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
-  hgext/keyword.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/largefiles/basestore.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/largefiles/lfcommands.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/largefiles/lfutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  hgext/keyword.py: error importing: <ImportError> No module named 'BaseHTTPServer' (error at common.py:*) (glob)
+  hgext/largefiles/basestore.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
+  hgext/largefiles/lfcommands.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
+  hgext/largefiles/lfutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/largefiles/localstore.py: error importing module: <ImportError> No module named 'lfutil' (line *) (glob)
-  hgext/largefiles/overrides.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  hgext/largefiles/overrides.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
   hgext/largefiles/proto.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
   hgext/largefiles/remotestore.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
-  hgext/largefiles/reposetup.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  hgext/largefiles/reposetup.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/largefiles/uisetup.py: error importing module: <SyntaxError> invalid syntax (archival.py, line *) (line *) (glob)
   hgext/largefiles/wirestore.py: error importing module: <ImportError> No module named 'lfutil' (line *) (glob)
-  hgext/mq.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/notify.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/pager.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/patchbomb.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
-  hgext/purge.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/rebase.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  hgext/record.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/relink.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/schemes.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  hgext/share.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
+  hgext/mq.py: error importing module: <SyntaxError> invalid syntax (commands.py, line *) (line *) (glob)
+  hgext/notify.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/pager.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/patchbomb.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/purge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/rebase.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
+  hgext/record.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/relink.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/schemes.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  hgext/share.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/shelve.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
-  hgext/strip.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  hgext/strip.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   hgext/transplant.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
-  hgext/win*text.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
   mercurial/archival.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
-  mercurial/bookmarks.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/branchmap.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  mercurial/branchmap.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/bundle*.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
   mercurial/bundlerepo.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
   mercurial/byterange.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
-  mercurial/changegroup.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/changelog.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
-  mercurial/cmdutil.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
+  mercurial/changegroup.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/changelog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/cmdutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/commands.py: invalid syntax: invalid syntax (<unknown>, line *) (glob)
   mercurial/commandserver.py: error importing module: <ImportError> No module named 'SocketServer' (line *) (glob)
-  mercurial/config.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/context.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/copies.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/crecord.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
-  mercurial/destutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/dirstate.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/discovery.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/dispatch.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
+  mercurial/context.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/copies.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/crecord.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/dirstate.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/discovery.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/dispatch.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/exchange.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
-  mercurial/extensions.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  mercurial/filelog.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
-  mercurial/filemerge.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/fileset.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  mercurial/extensions.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/filelog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/filemerge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/fileset.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/formatter.py: error importing module: <ImportError> No module named 'cPickle' (line *) (glob)
-  mercurial/graphmod.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/help.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  mercurial/hg.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  mercurial/graphmod.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/help.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/hg.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at bundlerepo.py:*) (glob)
   mercurial/hgweb/common.py: error importing module: <ImportError> No module named 'BaseHTTPServer' (line *) (glob)
   mercurial/hgweb/hgweb_mod.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
   mercurial/hgweb/hgwebdir_mod.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
-  mercurial/hgweb/protocol.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
+  mercurial/hgweb/protocol.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
   mercurial/hgweb/request.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
   mercurial/hgweb/server.py: error importing module: <ImportError> No module named 'BaseHTTPServer' (line *) (glob)
   mercurial/hgweb/webcommands.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
   mercurial/hgweb/webutil.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
   mercurial/hgweb/wsgicgi.py: error importing module: <SystemError> Parent module 'mercurial.hgweb' not loaded, cannot perform relative import (line *) (glob)
-  mercurial/hook.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
+  mercurial/hook.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/httpclient/_readers.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
   mercurial/httpconnection.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
   mercurial/httppeer.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
   mercurial/keepalive.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
-  mercurial/localrepo.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/lock.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/mail.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/manifest.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
-  mercurial/match.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/mdiff.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
-  mercurial/merge.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/minirst.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/namespaces.py: error importing: <ImportError> No module named 'cStringIO' (error at patch.py:*) (glob)
-  mercurial/obsolete.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/patch.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
-  mercurial/pathutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/peer.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/pure/mpatch.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
-  mercurial/pure/parsers.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
-  mercurial/pushkey.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/pvec.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/registrar.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  mercurial/localrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/mail.py: error importing module: <AttributeError> module 'email' has no attribute 'Header' (line *) (glob)
+  mercurial/manifest.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/merge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/namespaces.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/patch.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/pure/mpatch.py: error importing module: <ImportError> cannot import name 'pycompat' (line *) (glob)
+  mercurial/pure/parsers.py: error importing module: <ImportError> No module named 'mercurial.pure.node' (line *) (glob)
   mercurial/repair.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
-  mercurial/repoview.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/revlog.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
-  mercurial/revset.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/scmutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  mercurial/revlog.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/revset.py: error importing module: <AttributeError> 'dict' object has no attribute 'iteritems' (line *) (glob)
+  mercurial/scmutil.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/scmwindows.py: error importing module: <ImportError> No module named '_winreg' (line *) (glob)
-  mercurial/similar.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
-  mercurial/simplemerge.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
-  mercurial/sshpeer.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/sshserver.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  mercurial/sslutil.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
+  mercurial/simplemerge.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/sshpeer.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at wireproto.py:*) (glob)
+  mercurial/sshserver.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/statichttprepo.py: error importing module: <ImportError> No module named 'urllib2' (line *) (glob)
-  mercurial/store.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/streamclone.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/subrepo.py: error importing: <ImportError> No module named 'cStringIO' (error at cmdutil.py:*) (glob)
-  mercurial/tagmerge.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/tags.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/templatefilters.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/templatekw.py: error importing: <ImportError> No module named 'cStringIO' (error at patch.py:*) (glob)
-  mercurial/templater.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/transaction.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/ui.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/unionrepo.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
-  mercurial/url.py: error importing module: <ImportError> No module named 'cStringIO' (line *) (glob)
-  mercurial/util.py: error importing: <ImportError> No module named 'cStringIO' (error at parsers.py:*) (glob)
-  mercurial/verify.py: error importing: <ImportError> No module named 'cStringIO' (error at mpatch.py:*) (glob)
+  mercurial/store.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/streamclone.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/subrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/templatefilters.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/templatekw.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/templater.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/ui.py: error importing: <ImportError> No module named 'cPickle' (error at formatter.py:*) (glob)
+  mercurial/unionrepo.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
+  mercurial/url.py: error importing module: <ImportError> No module named 'httplib' (line *) (glob)
+  mercurial/verify.py: error importing: <AttributeError> 'dict' object has no attribute 'iteritems' (error at revset.py:*) (glob)
   mercurial/win*.py: error importing module: <ImportError> No module named 'msvcrt' (line *) (glob)
   mercurial/windows.py: error importing module: <ImportError> No module named '_winreg' (line *) (glob)
   mercurial/wireproto.py: error importing module: <SyntaxError> invalid syntax (bundle*.py, line *) (line *) (glob)
diff --git a/tests/test-hgweb-no-path-info.t b/tests/test-hgweb-no-path-info.t
--- a/tests/test-hgweb-no-path-info.t
+++ b/tests/test-hgweb-no-path-info.t
@@ -18,14 +18,17 @@ 
   > from __future__ import absolute_import
   > import os
   > import sys
-  > from StringIO import StringIO
   > from mercurial.hgweb import (
   >     hgweb,
   >     hgwebdir,
   > )
+  > from mercurial import (
+  >     util,
+  > )
+  > stringio = util.stringio
   > 
-  > errors = StringIO()
-  > input = StringIO()
+  > errors = stringio()
+  > input = stringio()
   > 
   > def startrsp(status, headers):
   >     print '---- STATUS'
@@ -59,11 +62,11 @@ 
   >     print '---- ERRORS'
   >     print errors.getvalue()
   > 
-  > output = StringIO()
+  > output = stringio()
   > env['QUERY_STRING'] = 'style=atom'
   > process(hgweb('.', name='repo'))
   > 
-  > output = StringIO()
+  > output = stringio()
   > env['QUERY_STRING'] = 'style=raw'
   > process(hgwebdir({'repo': '.'}))
   > EOF
diff --git a/tests/test-hgweb-no-request-uri.t b/tests/test-hgweb-no-request-uri.t
--- a/tests/test-hgweb-no-request-uri.t
+++ b/tests/test-hgweb-no-request-uri.t
@@ -18,14 +18,17 @@ 
   > from __future__ import absolute_import
   > import os
   > import sys
-  > from StringIO import StringIO
   > from mercurial.hgweb import (
   >     hgweb,
   >     hgwebdir,
   > )
+  > from mercurial import (
+  >     util,
+  > )
+  > stringio = util.stringio
   > 
-  > errors = StringIO()
-  > input = StringIO()
+  > errors = stringio()
+  > input = stringio()
   > 
   > def startrsp(status, headers):
   >     print '---- STATUS'
@@ -58,22 +61,22 @@ 
   >     print '---- ERRORS'
   >     print errors.getvalue()
   > 
-  > output = StringIO()
+  > output = stringio()
   > env['PATH_INFO'] = '/'
   > env['QUERY_STRING'] = 'style=atom'
   > process(hgweb('.', name = 'repo'))
   > 
-  > output = StringIO()
+  > output = stringio()
   > env['PATH_INFO'] = '/file/tip/'
   > env['QUERY_STRING'] = 'style=raw'
   > process(hgweb('.', name = 'repo'))
   > 
-  > output = StringIO()
+  > output = stringio()
   > env['PATH_INFO'] = '/'
   > env['QUERY_STRING'] = 'style=raw'
   > process(hgwebdir({'repo': '.'}))
   > 
-  > output = StringIO()
+  > output = stringio()
   > env['PATH_INFO'] = '/repo/file/tip/'
   > env['QUERY_STRING'] = 'style=raw'
   > process(hgwebdir({'repo': '.'}))
diff --git a/tests/test-hgweb-non-interactive.t b/tests/test-hgweb-non-interactive.t
--- a/tests/test-hgweb-non-interactive.t
+++ b/tests/test-hgweb-non-interactive.t
@@ -10,16 +10,17 @@ 
   > from __future__ import absolute_import
   > import os
   > import sys
-  > from StringIO import StringIO
   > from mercurial import (
   >     dispatch,
   >     hg,
   >     ui as uimod,
+  >     util,
   > )
   > ui = uimod.ui
   > from mercurial.hgweb.hgweb_mod import (
   >     hgweb,
   > )
+  > stringio = util.stringio
   > 
   > class FileLike(object):
   >     def __init__(self, real):
@@ -35,9 +36,9 @@ 
   >         return self.real.readline()
   > 
   > sys.stdin = FileLike(sys.stdin)
-  > errors = StringIO()
-  > input = StringIO()
-  > output = StringIO()
+  > errors = stringio()
+  > input = stringio()
+  > output = stringio()
   > 
   > def startrsp(status, headers):
   >     print '---- STATUS'
diff --git a/tests/test-simplemerge.py b/tests/test-simplemerge.py
--- a/tests/test-simplemerge.py
+++ b/tests/test-simplemerge.py
@@ -36,8 +36,7 @@ 
 CantReprocessAndShowBase = simplemerge.CantReprocessAndShowBase
 
 def split_lines(t):
-    from cStringIO import StringIO
-    return StringIO(t).readlines()
+    return util.stringio(t).readlines()
 
 ############################################################
 # test case data from the gnu diffutils manual
diff --git a/tests/test-wireproto.py b/tests/test-wireproto.py
--- a/tests/test-wireproto.py
+++ b/tests/test-wireproto.py
@@ -1,9 +1,10 @@ 
 from __future__ import absolute_import, print_function
 
-import StringIO
 from mercurial import (
+    util,
     wireproto,
 )
+stringio = util.stringio
 
 class proto(object):
     def __init__(self, args):
@@ -25,7 +26,7 @@ 
         return wireproto.dispatch(self.serverrepo, proto(args), cmd)
 
     def _callstream(self, cmd, **args):
-        return StringIO.StringIO(self._call(cmd, **args))
+        return stringio(self._call(cmd, **args))
 
     @wireproto.batchable
     def greet(self, name):