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

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