Add python3 compatability support
Add partial python 3.x compatibilty support. Change-Id: I52a3192a50b7f07d95b99c9c1b5abcd403b6dde8 Signed-off-by: Chuck Short <chuck.short@canonical.com>
This commit is contained in:
parent
2031b32456
commit
60511c9a4a
@ -57,8 +57,8 @@ html_last_updated_fmt = os.popen(git_cmd).read()
|
||||
latex_documents = [
|
||||
('index',
|
||||
'%s.tex' % project,
|
||||
u'%s Documentation' % project,
|
||||
u'OpenStack Foundation', 'manual'),
|
||||
'%s Documentation' % project,
|
||||
'OpenStack Foundation', 'manual'),
|
||||
]
|
||||
|
||||
# Example configuration for intersphinx: refer to the Python standard library.
|
||||
|
@ -265,11 +265,13 @@ import collections
|
||||
import copy
|
||||
import functools
|
||||
import glob
|
||||
import itertools
|
||||
import os
|
||||
import string
|
||||
import sys
|
||||
|
||||
from oslo.config import iniparser
|
||||
from six.moves import filter
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
@ -405,7 +407,7 @@ def _get_config_dirs(project=None):
|
||||
'/etc'
|
||||
]
|
||||
|
||||
return filter(bool, cfg_dirs)
|
||||
return list(filter(bool, cfg_dirs))
|
||||
|
||||
|
||||
def _search_dirs(dirs, basename, extension=""):
|
||||
@ -460,7 +462,7 @@ def find_config_files(project=None, prog=None, extension='.conf'):
|
||||
config_files.append(_search_dirs(cfg_dirs, project, extension))
|
||||
config_files.append(_search_dirs(cfg_dirs, prog, extension))
|
||||
|
||||
return filter(bool, config_files)
|
||||
return list(filter(bool, config_files))
|
||||
|
||||
|
||||
def _is_opt_registered(opts, opt):
|
||||
@ -1240,7 +1242,7 @@ class ConfigOpts(collections.Mapping):
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate over all registered opt and group names."""
|
||||
for key in self._opts.keys() + self._groups.keys():
|
||||
for key in itertools.chain(self._opts.keys(), self._groups.keys()):
|
||||
yield key
|
||||
|
||||
def __len__(self):
|
||||
@ -1691,7 +1693,7 @@ class ConfigOpts(collections.Mapping):
|
||||
raise ConfigFileParseError(pe.filename, str(pe))
|
||||
|
||||
if read_ok != config_files:
|
||||
not_read_ok = filter(lambda f: f not in read_ok, config_files)
|
||||
not_read_ok = [f for f in config_files if f not in read_ok]
|
||||
raise ConfigFilesNotFoundError(not_read_ok)
|
||||
|
||||
def _check_required_opts(self):
|
||||
|
@ -15,13 +15,13 @@
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
import StringIO
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import fixtures
|
||||
|
||||
from oslo.config.cfg import *
|
||||
from six.moves import StringIO
|
||||
from tests import utils
|
||||
|
||||
|
||||
@ -109,7 +109,7 @@ class BaseTestCase(utils.BaseTestCase):
|
||||
class UsageTestCase(BaseTestCase):
|
||||
|
||||
def test_print_usage(self):
|
||||
f = StringIO.StringIO()
|
||||
f = StringIO()
|
||||
self.conf([])
|
||||
self.conf.print_usage(file=f)
|
||||
self.assertTrue('usage: test FOO BAR' in f.getvalue())
|
||||
@ -119,7 +119,7 @@ class UsageTestCase(BaseTestCase):
|
||||
class HelpTestCase(BaseTestCase):
|
||||
|
||||
def test_print_help(self):
|
||||
f = StringIO.StringIO()
|
||||
f = StringIO()
|
||||
self.conf([])
|
||||
self.conf.print_help(file=f)
|
||||
self.assertTrue('usage: test FOO BAR' in f.getvalue())
|
||||
@ -391,7 +391,7 @@ class CliOptsTestCase(BaseTestCase):
|
||||
deps=('oof', 'old'))
|
||||
|
||||
def test_help(self):
|
||||
self.stubs.Set(sys, 'stdout', StringIO.StringIO())
|
||||
self.stubs.Set(sys, 'stdout', StringIO())
|
||||
self.assertRaises(SystemExit, self.conf, ['--help'])
|
||||
self.assertTrue('FOO BAR' in sys.stdout.getvalue())
|
||||
self.assertTrue('--version' in sys.stdout.getvalue())
|
||||
@ -399,7 +399,7 @@ class CliOptsTestCase(BaseTestCase):
|
||||
self.assertTrue('--config-file' in sys.stdout.getvalue())
|
||||
|
||||
def test_version(self):
|
||||
self.stubs.Set(sys, 'stderr', StringIO.StringIO())
|
||||
self.stubs.Set(sys, 'stderr', StringIO())
|
||||
self.assertRaises(SystemExit, self.conf, ['--version'])
|
||||
self.assertTrue('1.0' in sys.stderr.getvalue())
|
||||
|
||||
@ -1326,7 +1326,7 @@ class MappingInterfaceTestCase(BaseTestCase):
|
||||
self.assertEquals(len(self.conf), 3)
|
||||
self.assertEquals(self.conf['foo'], 'bar')
|
||||
self.assertEquals(self.conf.get('foo'), 'bar')
|
||||
self.assertTrue('bar' in self.conf.values())
|
||||
self.assertTrue('bar' in list(self.conf.values()))
|
||||
|
||||
def test_mapping_interface_with_group(self):
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
@ -1335,7 +1335,7 @@ class MappingInterfaceTestCase(BaseTestCase):
|
||||
self.conf(['--blaa-foo', 'bar'])
|
||||
|
||||
self.assertTrue('blaa' in self.conf)
|
||||
self.assertTrue('foo' in self.conf['blaa'])
|
||||
self.assertTrue('foo' in list(self.conf['blaa']))
|
||||
self.assertEquals(len(self.conf['blaa']), 1)
|
||||
self.assertEquals(self.conf['blaa']['foo'], 'bar')
|
||||
self.assertEquals(self.conf['blaa'].get('foo'), 'bar')
|
||||
@ -1948,7 +1948,7 @@ class SadPathTestCase(BaseTestCase):
|
||||
def test_bad_cli_arg(self):
|
||||
self.conf.register_opt(BoolOpt('foo'))
|
||||
|
||||
self.stubs.Set(sys, 'stderr', StringIO.StringIO())
|
||||
self.stubs.Set(sys, 'stderr', StringIO())
|
||||
|
||||
self.assertRaises(SystemExit, self.conf, ['--foo'])
|
||||
|
||||
@ -1958,7 +1958,7 @@ class SadPathTestCase(BaseTestCase):
|
||||
def _do_test_bad_cli_value(self, opt_class):
|
||||
self.conf.register_cli_opt(opt_class('foo'))
|
||||
|
||||
self.stubs.Set(sys, 'stderr', StringIO.StringIO())
|
||||
self.stubs.Set(sys, 'stderr', StringIO())
|
||||
|
||||
self.assertRaises(SystemExit, self.conf, ['--foo', 'bar'])
|
||||
|
||||
@ -2246,7 +2246,7 @@ class SubCommandTestCase(BaseTestCase):
|
||||
|
||||
def test_sub_command_no_handler(self):
|
||||
self.conf.register_cli_opt(SubCommandOpt('cmd'))
|
||||
self.stubs.Set(sys, 'stderr', StringIO.StringIO())
|
||||
self.stubs.Set(sys, 'stderr', StringIO())
|
||||
self.assertRaises(SystemExit, self.conf, [])
|
||||
self.assertTrue('error' in sys.stderr.getvalue())
|
||||
|
||||
@ -2259,7 +2259,7 @@ class SubCommandTestCase(BaseTestCase):
|
||||
description='bar bar',
|
||||
help='blaa blaa',
|
||||
handler=add_parsers))
|
||||
self.stubs.Set(sys, 'stdout', StringIO.StringIO())
|
||||
self.stubs.Set(sys, 'stdout', StringIO())
|
||||
self.assertRaises(SystemExit, self.conf, ['--help'])
|
||||
self.assertTrue('foo foo' in sys.stdout.getvalue())
|
||||
self.assertTrue('bar bar' in sys.stdout.getvalue())
|
||||
@ -2279,7 +2279,7 @@ class SubCommandTestCase(BaseTestCase):
|
||||
def test_sub_command_multiple(self):
|
||||
self.conf.register_cli_opt(SubCommandOpt('cmd1'))
|
||||
self.conf.register_cli_opt(SubCommandOpt('cmd2'))
|
||||
self.stubs.Set(sys, 'stderr', StringIO.StringIO())
|
||||
self.stubs.Set(sys, 'stderr', StringIO())
|
||||
self.assertRaises(SystemExit, self.conf, [])
|
||||
self.assertTrue('multiple' in sys.stderr.getvalue())
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
argparse
|
||||
six
|
||||
|
Loading…
x
Reference in New Issue
Block a user