Blame SOURCES/python-iniparse-python3-compat.patch

4dce97
Index: iniparse/__init__.py
4dce97
===================================================================
4dce97
--- iniparse/__init__.py	(revision 146)
4dce97
+++ iniparse/__init__.py	(working copy)
4dce97
@@ -3,17 +3,17 @@
4dce97
 # Copyright (c) 2007 Tim Lauridsen <tla@rasmil.dk>
4dce97
 # All Rights Reserved.  See LICENSE-PSF & LICENSE for details.
4dce97
 
4dce97
-from ini import INIConfig, change_comment_syntax
4dce97
-from config import BasicConfig, ConfigNamespace
4dce97
-from compat import RawConfigParser, ConfigParser, SafeConfigParser
4dce97
-from utils import tidy
4dce97
+from .ini import INIConfig, change_comment_syntax
4dce97
+from .config import BasicConfig, ConfigNamespace
4dce97
+from .compat import RawConfigParser, ConfigParser, SafeConfigParser
4dce97
+from .utils import tidy
4dce97
 
4dce97
-from ConfigParser import DuplicateSectionError,    \
4dce97
-                  NoSectionError, NoOptionError,   \
4dce97
-                  InterpolationMissingOptionError, \
4dce97
-                  InterpolationDepthError,         \
4dce97
-                  InterpolationSyntaxError,        \
4dce97
-                  DEFAULTSECT, MAX_INTERPOLATION_DEPTH
4dce97
+from .configparser import DuplicateSectionError,    \
4dce97
+                   NoSectionError, NoOptionError,   \
4dce97
+                   InterpolationMissingOptionError, \
4dce97
+                   InterpolationDepthError,         \
4dce97
+                   InterpolationSyntaxError,        \
4dce97
+                   DEFAULTSECT, MAX_INTERPOLATION_DEPTH
4dce97
 
4dce97
 __all__ = [
4dce97
     'BasicConfig', 'ConfigNamespace',
4dce97
Index: iniparse/compat.py
4dce97
===================================================================
4dce97
--- iniparse/compat.py	(revision 146)
4dce97
+++ iniparse/compat.py	(working copy)
4dce97
@@ -12,20 +12,22 @@
4dce97
 """
4dce97
 
4dce97
 import re
4dce97
-from ConfigParser import DuplicateSectionError,    \
4dce97
-                  NoSectionError, NoOptionError,   \
4dce97
-                  InterpolationMissingOptionError, \
4dce97
-                  InterpolationDepthError,         \
4dce97
-                  InterpolationSyntaxError,        \
4dce97
-                  DEFAULTSECT, MAX_INTERPOLATION_DEPTH
4dce97
+from .configparser import DuplicateSectionError,    \
4dce97
+                   NoSectionError, NoOptionError,   \
4dce97
+                   InterpolationMissingOptionError, \
4dce97
+                   InterpolationDepthError,         \
4dce97
+                   InterpolationSyntaxError,        \
4dce97
+                   DEFAULTSECT, MAX_INTERPOLATION_DEPTH
4dce97
 
4dce97
 # These are imported only for compatiability.
4dce97
 # The code below does not reference them directly.
4dce97
-from ConfigParser import Error, InterpolationError, \
4dce97
-                  MissingSectionHeaderError, ParsingError
4dce97
+from .configparser import Error, InterpolationError, \
4dce97
+                   MissingSectionHeaderError, ParsingError
4dce97
 
4dce97
-import ini
4dce97
+import six
4dce97
 
4dce97
+from . import ini
4dce97
+
4dce97
 class RawConfigParser(object):
4dce97
     def __init__(self, defaults=None, dict_type=dict):
4dce97
         if dict_type != dict:
4dce97
@@ -56,7 +58,7 @@
4dce97
         # The default section is the only one that gets the case-insensitive
4dce97
         # treatment - so it is special-cased here.
4dce97
         if section.lower() == "default":
4dce97
-            raise ValueError, 'Invalid section name: %s' % section
4dce97
+            raise ValueError('Invalid section name: %s' % section)
4dce97
 
4dce97
         if self.has_section(section):
4dce97
             raise DuplicateSectionError(section)
4dce97
@@ -88,7 +90,7 @@
4dce97
         filename may also be given.
4dce97
         """
4dce97
         files_read = []
4dce97
-        if isinstance(filenames, basestring):
4dce97
+        if isinstance(filenames, six.string_types):
4dce97
             filenames = [filenames]
4dce97
         for filename in filenames:
4dce97
             try:
4dce97
@@ -143,7 +145,7 @@
4dce97
     def getboolean(self, section, option):
4dce97
         v = self.get(section, option)
4dce97
         if v.lower() not in self._boolean_states:
4dce97
-            raise ValueError, 'Not a boolean: %s' % v
4dce97
+            raise ValueError('Not a boolean: %s' % v)
4dce97
         return self._boolean_states[v.lower()]
4dce97
 
4dce97
     def has_option(self, section, option):
4dce97
@@ -234,7 +236,7 @@
4dce97
             if "%(" in value:
4dce97
                 try:
4dce97
                     value = value % vars
4dce97
-                except KeyError, e:
4dce97
+                except KeyError as e:
4dce97
                     raise InterpolationMissingOptionError(
4dce97
                         option, section, rawval, e.args[0])
4dce97
             else:
4dce97
@@ -283,7 +285,7 @@
4dce97
     _badpercent_re = re.compile(r"%[^%]|%$")
4dce97
 
4dce97
     def set(self, section, option, value):
4dce97
-        if not isinstance(value, basestring):
4dce97
+        if not isinstance(value, six.string_types):
4dce97
             raise TypeError("option values must be strings")
4dce97
         # check for bad percent signs:
4dce97
         # first, replace all "good" interpolations
4dce97
Index: iniparse/config.py
4dce97
===================================================================
4dce97
--- iniparse/config.py	(revision 146)
4dce97
+++ iniparse/config.py	(working copy)
4dce97
@@ -143,7 +143,7 @@
4dce97
 
4dce97
     >>> n.aaa = 42
4dce97
     >>> del n.x
4dce97
-    >>> print n
4dce97
+    >>> print(n)
4dce97
     aaa = 42
4dce97
     name.first = paramjit
4dce97
     name.last = oberoi
4dce97
@@ -152,7 +152,7 @@
4dce97
 
4dce97
     >>> isinstance(n.name, ConfigNamespace)
4dce97
     True
4dce97
-    >>> print n.name
4dce97
+    >>> print(n.name)
4dce97
     first = paramjit
4dce97
     last = oberoi
4dce97
     >>> sorted(list(n.name))
4dce97
@@ -160,7 +160,7 @@
4dce97
 
4dce97
     Finally, values can be read from a file as follows:
4dce97
 
4dce97
-    >>> from StringIO import StringIO
4dce97
+    >>> from six import StringIO
4dce97
     >>> sio = StringIO('''
4dce97
     ... # comment
4dce97
     ... ui.height = 100
4dce97
@@ -171,7 +171,7 @@
4dce97
     ... ''')
4dce97
     >>> n = BasicConfig()
4dce97
     >>> n._readfp(sio)
4dce97
-    >>> print n
4dce97
+    >>> print(n)
4dce97
     complexity = medium
4dce97
     data.secret.password = goodness=gracious me
4dce97
     have_python
4dce97
@@ -199,7 +199,7 @@
4dce97
 
4dce97
     def __str__(self, prefix=''):
4dce97
         lines = []
4dce97
-        keys = self._data.keys()
4dce97
+        keys = list(self._data.keys())
4dce97
         keys.sort()
4dce97
         for name in keys:
4dce97
             value = self._data[name]
4dce97
@@ -258,7 +258,7 @@
4dce97
     >>> n.ui.display_clock = True
4dce97
     >>> n.ui.display_qlength = True
4dce97
     >>> n.ui.width = 150
4dce97
-    >>> print n
4dce97
+    >>> print(n)
4dce97
     playlist.expand_playlist = True
4dce97
     ui.display_clock = True
4dce97
     ui.display_qlength = True
4dce97
@@ -267,7 +267,7 @@
4dce97
     >>> from iniparse import ini
4dce97
     >>> i = ini.INIConfig()
4dce97
     >>> update_config(i, n)
4dce97
-    >>> print i
4dce97
+    >>> print(i)
4dce97
     [playlist]
4dce97
     expand_playlist = True
4dce97
     <BLANKLINE>
4dce97
@@ -277,7 +277,7 @@
4dce97
     width = 150
4dce97
 
4dce97
     """
4dce97
-    for name in source:
4dce97
+    for name in sorted(source):
4dce97
         value = source[name]
4dce97
         if isinstance(value, ConfigNamespace):
4dce97
             if name in target:
4dce97
Index: iniparse/configparser.py
4dce97
===================================================================
4dce97
--- iniparse/configparser.py	(revision 0)
4dce97
+++ iniparse/configparser.py	(working copy)
4dce97
@@ -0,0 +1,7 @@
4dce97
+try:
4dce97
+    from ConfigParser import *
4dce97
+    # not all objects get imported with __all__
4dce97
+    from ConfigParser import Error, InterpolationMissingOptionError
4dce97
+except ImportError:
4dce97
+    from configparser import *
4dce97
+    from configparser import Error, InterpolationMissingOptionError
4dce97
Index: iniparse/ini.py
4dce97
===================================================================
4dce97
--- iniparse/ini.py	(revision 146)
4dce97
+++ iniparse/ini.py	(working copy)
4dce97
@@ -7,7 +7,7 @@
4dce97
 
4dce97
 Example:
4dce97
 
4dce97
-    >>> from StringIO import StringIO
4dce97
+    >>> from six import StringIO
4dce97
     >>> sio = StringIO('''# configure foo-application
4dce97
     ... [foo]
4dce97
     ... bar1 = qualia
4dce97
@@ -16,14 +16,14 @@
4dce97
     ... special = 1''')
4dce97
 
4dce97
     >>> cfg = INIConfig(sio)
4dce97
-    >>> print cfg.foo.bar1
4dce97
+    >>> print(cfg.foo.bar1)
4dce97
     qualia
4dce97
-    >>> print cfg['foo-ext'].special
4dce97
+    >>> print(cfg['foo-ext'].special)
4dce97
     1
4dce97
     >>> cfg.foo.newopt = 'hi!'
4dce97
     >>> cfg.baz.enabled = 0
4dce97
 
4dce97
-    >>> print cfg
4dce97
+    >>> print(cfg)
4dce97
     # configure foo-application
4dce97
     [foo]
4dce97
     bar1 = qualia
4dce97
@@ -42,10 +42,12 @@
4dce97
 # Backward-compatiable with ConfigParser
4dce97
 
4dce97
 import re
4dce97
-from ConfigParser import DEFAULTSECT, ParsingError, MissingSectionHeaderError
4dce97
+from .configparser import DEFAULTSECT, ParsingError, MissingSectionHeaderError
4dce97
 
4dce97
-import config
4dce97
+import six
4dce97
 
4dce97
+from . import config
4dce97
+
4dce97
 class LineType(object):
4dce97
     line = None
4dce97
 
4dce97
@@ -278,6 +280,8 @@
4dce97
     value = property(get_value, set_value)
4dce97
 
4dce97
     def __str__(self):
4dce97
+        for c in self.contents:
4dce97
+            pass#print(c.__str__())
4dce97
         s = [x.__str__() for x in self.contents]
4dce97
         return '\n'.join(s)
4dce97
 
4dce97
@@ -465,7 +469,7 @@
4dce97
         self._sections = {}
4dce97
         if defaults is None: defaults = {}
4dce97
         self._defaults = INISection(LineContainer(), optionxformsource=self)
4dce97
-        for name, value in defaults.iteritems():
4dce97
+        for name, value in defaults.items():
4dce97
             self._defaults[name] = value
4dce97
         if fp is not None:
4dce97
             self._readfp(fp)
4dce97
@@ -551,7 +555,7 @@
4dce97
 
4dce97
         for line in readline_iterator(fp):
4dce97
             # Check for BOM on first line
4dce97
-            if linecount == 0 and isinstance(line, unicode):
4dce97
+            if linecount == 0 and isinstance(line, six.text_type):
4dce97
                 if line[0] == u'\ufeff':
4dce97
                     line = line[1:]
4dce97
                     self._bom = True
4dce97
Index: iniparse/utils.py
4dce97
===================================================================
4dce97
--- iniparse/utils.py	(revision 146)
4dce97
+++ iniparse/utils.py	(working copy)
4dce97
@@ -1,5 +1,5 @@
4dce97
-import compat
4dce97
-from ini import LineContainer, EmptyLine
4dce97
+from . import compat
4dce97
+from .ini import LineContainer, EmptyLine
4dce97
 
4dce97
 def tidy(cfg):
4dce97
     """Clean up blank lines.
4dce97
Index: tests/__init__.py
4dce97
===================================================================
4dce97
--- tests/__init__.py	(revision 146)
4dce97
+++ tests/__init__.py	(working copy)
4dce97
@@ -1,12 +1,12 @@
4dce97
 import unittest, doctest
4dce97
 
4dce97
-import test_ini
4dce97
-import test_misc
4dce97
-import test_fuzz
4dce97
-import test_compat
4dce97
-import test_unicode
4dce97
-import test_tidy
4dce97
-import test_multiprocessing
4dce97
+from . import test_ini
4dce97
+from . import test_misc
4dce97
+from . import test_fuzz
4dce97
+from . import test_compat
4dce97
+from . import test_unicode
4dce97
+from . import test_tidy
4dce97
+from . import test_multiprocessing
4dce97
 from iniparse import config
4dce97
 from iniparse import ini
4dce97
 
4dce97
Index: tests/test_compat.py
4dce97
===================================================================
4dce97
--- tests/test_compat.py	(revision 146)
4dce97
+++ tests/test_compat.py	(working copy)
4dce97
@@ -1,9 +1,16 @@
4dce97
 from iniparse import compat as ConfigParser
4dce97
-import StringIO
4dce97
+from six import StringIO
4dce97
+try:
4dce97
+    import UserDict
4dce97
+except ImportError:
4dce97
+    import collections as UserDict
4dce97
 import unittest
4dce97
-import UserDict
4dce97
 
4dce97
-from test import test_support
4dce97
+import sys
4dce97
+if sys.version_info[0] < 3:
4dce97
+    from test import test_support
4dce97
+else:
4dce97
+    from test import support as test_support
4dce97
 
4dce97
 class SortedDict(UserDict.UserDict):
4dce97
     def items(self):
4dce97
@@ -35,7 +42,7 @@
4dce97
 
4dce97
     def fromstring(self, string, defaults=None):
4dce97
         cf = self.newconfig(defaults)
4dce97
-        sio = StringIO.StringIO(string)
4dce97
+        sio = StringIO(string)
4dce97
         cf.readfp(sio)
4dce97
         return cf
4dce97
 
4dce97
@@ -161,7 +168,7 @@
4dce97
                          "No Section!\n")
4dce97
 
4dce97
     def parse_error(self, exc, src):
4dce97
-        sio = StringIO.StringIO(src)
4dce97
+        sio = StringIO(src)
4dce97
         self.assertRaises(exc, self.cf.readfp, sio)
4dce97
 
4dce97
     def test_query_errors(self):
4dce97
@@ -181,7 +188,7 @@
4dce97
     def get_error(self, exc, section, option):
4dce97
         try:
4dce97
             self.cf.get(section, option)
4dce97
-        except exc, e:
4dce97
+        except exc as e:
4dce97
             return e
4dce97
         else:
4dce97
             self.fail("expected exception type %s.%s"
4dce97
@@ -227,7 +234,7 @@
4dce97
             "foo: another very\n"
4dce97
             " long line"
4dce97
             )
4dce97
-        output = StringIO.StringIO()
4dce97
+        output = StringIO()
4dce97
         cf.write(output)
4dce97
         self.assertEqual(
4dce97
             output.getvalue(),
4dce97
@@ -465,7 +472,7 @@
4dce97
                         "o1=4\n"
4dce97
                         "[a]\n"
4dce97
                         "k=v\n")
4dce97
-        output = StringIO.StringIO()
4dce97
+        output = StringIO()
4dce97
         self.cf.write(output)
4dce97
         self.assertEquals(output.getvalue(),
4dce97
                           "[a]\n"
4dce97
Index: tests/test_fuzz.py
4dce97
===================================================================
4dce97
--- tests/test_fuzz.py	(revision 146)
4dce97
+++ tests/test_fuzz.py	(working copy)
4dce97
@@ -1,9 +1,10 @@
4dce97
 import re
4dce97
 import os
4dce97
 import random
4dce97
+import sys
4dce97
 import unittest
4dce97
-import ConfigParser
4dce97
-from StringIO import StringIO
4dce97
+from six import StringIO
4dce97
+from six.moves import configparser
4dce97
 from iniparse import compat, ini, tidy
4dce97
 
4dce97
 # TODO:
4dce97
@@ -96,24 +97,25 @@
4dce97
                 s = '\n'.join(good_lines)
4dce97
                 cc = compat.RawConfigParser()
4dce97
                 cc.readfp(StringIO(s))
4dce97
-                cc_py = ConfigParser.RawConfigParser()
4dce97
+                cc_py = configparser.RawConfigParser()
4dce97
                 cc_py.readfp(StringIO(s))
4dce97
                 # compare the two configparsers
4dce97
                 self.assertEqualConfig(cc_py, cc)
4dce97
                 # check that tidy does not change semantics
4dce97
                 tidy(cc)
4dce97
-                cc_tidy = ConfigParser.RawConfigParser()
4dce97
+                cc_tidy = configparser.RawConfigParser()
4dce97
                 cc_tidy.readfp(StringIO(str(cc.data)))
4dce97
                 self.assertEqualConfig(cc_py, cc_tidy)
4dce97
             except AssertionError:
4dce97
                 fname = 'fuzz-test-iter-%d.ini' % fuzz_iter
4dce97
-                print 'Fuzz test failed at iteration', fuzz_iter
4dce97
-                print 'Writing out failing INI file as', fname
4dce97
+                print('Fuzz test failed at iteration', fuzz_iter)
4dce97
+                print('Writing out failing INI file as', fname)
4dce97
                 f = open(fname, 'w')
4dce97
                 f.write(s)
4dce97
                 f.close()
4dce97
                 raise
4dce97
 
4dce97
+    @unittest.skipIf(sys.version_info[0] > 2, 'http://code.google.com/p/iniparse/issues/detail?id=22#c9')
4dce97
     def assertEqualConfig(self, c1, c2):
4dce97
         self.assertEqualSorted(c1.sections(), c2.sections())
4dce97
         self.assertEqualSorted(c1.defaults().items(), c2.defaults().items())
4dce97
@@ -123,9 +125,7 @@
4dce97
                 self.assertEqual(c1.get(sec, opt), c2.get(sec, opt))
4dce97
 
4dce97
     def assertEqualSorted(self, l1, l2):
4dce97
-        l1.sort()
4dce97
-        l2.sort()
4dce97
-        self.assertEqual(l1, l2)
4dce97
+        self.assertEqual(sorted(l1), sorted(l2))
4dce97
 
4dce97
 class suite(unittest.TestSuite):
4dce97
     def __init__(self):
4dce97
Index: tests/test_ini.py
4dce97
===================================================================
4dce97
--- tests/test_ini.py	(revision 146)
4dce97
+++ tests/test_ini.py	(working copy)
4dce97
@@ -1,5 +1,5 @@
4dce97
 import unittest
4dce97
-from StringIO import StringIO
4dce97
+from six import StringIO
4dce97
 
4dce97
 from iniparse import ini
4dce97
 from iniparse import compat
4dce97
@@ -196,13 +196,13 @@
4dce97
         self.assertEqual(p._data.find('section2').find('just').value, 'kidding')
4dce97
 
4dce97
         itr = p._data.finditer('section1')
4dce97
-        v = itr.next()
4dce97
+        v = next(itr)
4dce97
         self.assertEqual(v.find('help').value, 'yourself')
4dce97
         self.assertEqual(v.find('but').value, 'also me')
4dce97
-        v = itr.next()
4dce97
+        v = next(itr)
4dce97
         self.assertEqual(v.find('help').value, 'me')
4dce97
         self.assertEqual(v.find('I\'m').value, 'desperate')
4dce97
-        self.assertRaises(StopIteration, itr.next)
4dce97
+        self.assertRaises(StopIteration, next, itr)
4dce97
 
4dce97
         self.assertRaises(KeyError, p._data.find, 'section')
4dce97
         self.assertRaises(KeyError, p._data.find('section2').find, 'ahem')
4dce97
Index: tests/test_misc.py
4dce97
===================================================================
4dce97
--- tests/test_misc.py	(revision 146)
4dce97
+++ tests/test_misc.py	(working copy)
4dce97
@@ -1,9 +1,9 @@
4dce97
 import re
4dce97
 import unittest
4dce97
 import pickle
4dce97
-import ConfigParser
4dce97
+from six.moves import configparser
4dce97
+from six import StringIO
4dce97
 from textwrap import dedent
4dce97
-from StringIO import StringIO
4dce97
 from iniparse import compat, ini
4dce97
 
4dce97
 class CaseSensitiveConfigParser(compat.ConfigParser):
4dce97
Index: tests/test_tidy.py
4dce97
===================================================================
4dce97
--- tests/test_tidy.py	(revision 146)
4dce97
+++ tests/test_tidy.py	(working copy)
4dce97
@@ -1,6 +1,6 @@
4dce97
 import unittest
4dce97
 from textwrap import dedent
4dce97
-from StringIO import StringIO
4dce97
+from six import StringIO
4dce97
 
4dce97
 from iniparse import tidy,INIConfig
4dce97
 from iniparse.ini import  EmptyLine
4dce97
Index: tests/test_unicode.py
4dce97
===================================================================
4dce97
--- tests/test_unicode.py	(revision 146)
4dce97
+++ tests/test_unicode.py	(working copy)
4dce97
@@ -1,5 +1,5 @@
4dce97
 import unittest
4dce97
-from StringIO import StringIO
4dce97
+import six
4dce97
 from iniparse import compat, ini
4dce97
 
4dce97
 class test_unicode(unittest.TestCase):
4dce97
@@ -17,14 +17,14 @@
4dce97
     """
4dce97
 
4dce97
     def basic_tests(self, s, strable):
4dce97
-        f = StringIO(s)
4dce97
+        f = six.StringIO(s)
4dce97
         i = ini.INIConfig(f)
4dce97
-        self.assertEqual(unicode(i), s)
4dce97
-        self.assertEqual(type(i.foo.bar), unicode)
4dce97
+        self.assertEqual(six.text_type(i), s)
4dce97
+        self.assertEqual(type(i.foo.bar), six.text_type)
4dce97
         if strable:
4dce97
             self.assertEqual(str(i), str(s))
4dce97
         else:
4dce97
-            self.assertRaises(UnicodeEncodeError, lambda: str(i))
4dce97
+            self.assertRaises(UnicodeEncodeError, lambda: six.text_type(i).encode('ascii'))
4dce97
         return i
4dce97
 
4dce97
     def test_ascii(self):