[pacman-dev] [PATCH 5/8] Add shims to return a new Python StringIO instance.

Jeremy Heiner scalaprotractor at gmail.com
Wed Oct 9 20:35:08 EDT 2013


Reported by 2to3. StringIO moves to the io module in Python 3.

Signed-off-by: Jeremy Heiner <ScalaProtractor at gmail.com>
---
 test/pacman/pmdb.py  | 3 +--
 test/pacman/pmpkg.py | 5 ++---
 test/pacman/util.py  | 8 ++++++++
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py
index f4bc71d..7ee3a1e 100644
--- a/test/pacman/pmdb.py
+++ b/test/pacman/pmdb.py
@@ -19,7 +19,6 @@
 
 import os
 import shutil
-from StringIO import StringIO
 import tarfile
 
 import pmpkg
@@ -251,7 +250,7 @@ def generate(self):
                     filename = os.path.join(pkg.fullname(), name)
                     info = tarfile.TarInfo(filename)
                     info.size = len(data)
-                    tar.addfile(info, StringIO(data))
+                    tar.addfile(info, util.new_StringIO(data))
             tar.close()
             # TODO: this is a bit unnecessary considering only one test uses it
             serverpath = os.path.join(self.root, util.SYNCREPO, self.treename)
diff --git a/test/pacman/pmpkg.py b/test/pacman/pmpkg.py
index 69734b0..8f4a9bc 100644
--- a/test/pacman/pmpkg.py
+++ b/test/pacman/pmpkg.py
@@ -21,7 +21,6 @@
 import tempfile
 import stat
 import shutil
-from StringIO import StringIO
 import tarfile
 
 import util
@@ -152,7 +151,7 @@ def makepkg(self, path):
         for name, data in archive_files:
             info = tarfile.TarInfo(name)
             info.size = len(data)
-            tar.addfile(info, StringIO(data))
+            tar.addfile(info, util.new_StringIO(data))
 
         # Generate package file system
         for name in self.files:
@@ -175,7 +174,7 @@ def makepkg(self, path):
                 # TODO wow what a hack, adding a newline to match mkfile?
                 filedata = name + "\n"
                 info.size = len(filedata)
-                tar.addfile(info, StringIO(filedata))
+                tar.addfile(info, util.new_StringIO(filedata))
 
         tar.close()
 
diff --git a/test/pacman/util.py b/test/pacman/util.py
index 107a224..86d0eb2 100644
--- a/test/pacman/util.py
+++ b/test/pacman/util.py
@@ -68,6 +68,14 @@ def valuesview(x):
 def itemsview(x):
     return x.items() if sys.hexversion >= 0x03000000 else x.iteritems()
 
+def new_StringIO(source):
+    if sys.hexversion >= 0x03000000:
+        import io
+        return io.StringIO(source)
+    else:
+        import StringIO
+        return StringIO.StringIO(source)
+
 
 #
 # Methods to generate files
-- 
1.8.4



More information about the pacman-dev mailing list