diff mercurial/patch.py @ 28861:86db5cb55d46

pycompat: switch to util.stringio for py3 compat
author timeless <timeless@mozdev.org>
date Sun, 10 Apr 2016 20:55:37 +0000
parents 8286f551b7ee
children 9d38a2061fd8
line wrap: on
line diff
--- a/mercurial/patch.py	Sun Apr 10 21:32:08 2016 +0000
+++ b/mercurial/patch.py	Sun Apr 10 20:55:37 2016 +0000
@@ -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)