]> granicus.if.org Git - zziplib/commitdiff
test: StringIO compatibility with Python 3
authorPatrick Steinhardt <ps@pks.im>
Wed, 22 May 2019 19:21:16 +0000 (21:21 +0200)
committerPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2019 06:35:33 +0000 (08:35 +0200)
With Python 3, StringIO has been moved from the "cStringIO" module to
the "io" module. Use a try-catch block to intercept ImportErrors and
fall back to the new module to support both Python 2 and Python 3.

test/zziptests.py

index 49f43f6c3b2c28aa1711be0d6c0316d5b2b82e9c..e605c6adb0762b0830f2172ec008c948eae9a9f0 100644 (file)
@@ -8,7 +8,11 @@ import shutil
 import random
 import re
 from fnmatch import fnmatchcase as matches
-from cStringIO import StringIO
+
+try:
+    from cStringIO import StringIO
+except ImportError:
+    from io import StringIO
 
 try:
     from urllib import quote_plus, urlretrieve