Merge "Drop Python 2.6 support"
This commit is contained in:
commit
7c547e7e1d
40
cliff/app.py
40
cliff/app.py
|
@ -1,7 +1,6 @@
|
|||
"""Application base class.
|
||||
"""
|
||||
|
||||
import codecs
|
||||
import inspect
|
||||
import locale
|
||||
import logging
|
||||
|
@ -14,24 +13,8 @@ from .complete import CompleteCommand
|
|||
from .help import HelpAction, HelpCommand
|
||||
from .utils import damerau_levenshtein, COST
|
||||
|
||||
# Make sure the cliff library has a logging handler
|
||||
# in case the app developer doesn't set up logging.
|
||||
# For py26 compat, create a NullHandler
|
||||
|
||||
if hasattr(logging, 'NullHandler'):
|
||||
NullHandler = logging.NullHandler
|
||||
else:
|
||||
class NullHandler(logging.Handler):
|
||||
def handle(self, record):
|
||||
pass
|
||||
|
||||
def emit(self, record):
|
||||
pass
|
||||
|
||||
def createLock(self):
|
||||
self.lock = None
|
||||
|
||||
logging.getLogger('cliff').addHandler(NullHandler())
|
||||
logging.getLogger('cliff').addHandler(logging.NullHandler())
|
||||
|
||||
|
||||
class App(object):
|
||||
|
@ -87,24 +70,9 @@ class App(object):
|
|||
locale.setlocale(locale.LC_ALL, '')
|
||||
except locale.Error:
|
||||
pass
|
||||
if sys.version_info[:2] == (2, 6):
|
||||
# Configure the input and output streams. If a stream is
|
||||
# provided, it must be configured correctly by the
|
||||
# caller. If not, make sure the versions of the standard
|
||||
# streams used by default are wrapped with encodings. This
|
||||
# works around a problem with Python 2.6 fixed in 2.7 and
|
||||
# later (http://hg.python.org/cpython/rev/e60ef17561dc/).
|
||||
lang, encoding = locale.getdefaultlocale()
|
||||
encoding = (getattr(sys.stdout, 'encoding', None) or
|
||||
encoding or
|
||||
self.DEFAULT_OUTPUT_ENCODING)
|
||||
self.stdin = stdin or codecs.getreader(encoding)(sys.stdin)
|
||||
self.stdout = stdout or codecs.getwriter(encoding)(sys.stdout)
|
||||
self.stderr = stderr or codecs.getwriter(encoding)(sys.stderr)
|
||||
else:
|
||||
self.stdin = stdin or sys.stdin
|
||||
self.stdout = stdout or sys.stdout
|
||||
self.stderr = stderr or sys.stderr
|
||||
self.stdin = stdin or sys.stdin
|
||||
self.stdout = stdout or sys.stdout
|
||||
self.stderr = stderr or sys.stderr
|
||||
|
||||
def build_option_parser(self, description, version,
|
||||
argparse_kwargs=None):
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
"""Application base class for displaying data.
|
||||
"""
|
||||
import abc
|
||||
|
||||
try:
|
||||
from itertools import compress
|
||||
except ImportError:
|
||||
# for py26 compat
|
||||
from itertools import izip
|
||||
|
||||
def compress(data, selectors):
|
||||
return (d for d, s in izip(data, selectors) if s)
|
||||
from itertools import compress
|
||||
|
||||
import six
|
||||
import stevedore
|
||||
|
|
|
@ -4,9 +4,7 @@ try:
|
|||
from StringIO import StringIO
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
import sys
|
||||
|
||||
import nose
|
||||
import mock
|
||||
|
||||
from cliff.app import App
|
||||
|
@ -275,146 +273,6 @@ def test_option_parser_abbrev_issue():
|
|||
app.run(['--debug', 'mycommand', '--end', '123'])
|
||||
|
||||
|
||||
def test_output_encoding_default():
|
||||
# The encoding should come from getdefaultlocale() because
|
||||
# stdout has no encoding set.
|
||||
if sys.version_info[:2] != (2, 6):
|
||||
raise nose.SkipTest('only needed for python 2.6')
|
||||
data = '\xc3\xa9'
|
||||
u_data = data.decode('utf-8')
|
||||
|
||||
class MyApp(App):
|
||||
def __init__(self):
|
||||
super(MyApp, self).__init__(
|
||||
description='testing',
|
||||
version='0.1',
|
||||
command_manager=CommandManager('tests'),
|
||||
)
|
||||
|
||||
stdout = StringIO()
|
||||
|
||||
getdefaultlocale = mock.Mock(return_value=('ignored', 'utf-8'))
|
||||
|
||||
with mock.patch('sys.stdout', stdout):
|
||||
with mock.patch('locale.getdefaultlocale', getdefaultlocale):
|
||||
app = MyApp()
|
||||
app.stdout.write(u_data)
|
||||
actual = stdout.getvalue()
|
||||
assert data == actual
|
||||
|
||||
|
||||
def test_output_encoding_cliff_default():
|
||||
# The encoding should come from cliff.App.DEFAULT_OUTPUT_ENCODING
|
||||
# because the other values are missing or None
|
||||
if sys.version_info[:2] != (2, 6):
|
||||
raise nose.SkipTest('only needed for python 2.6')
|
||||
data = '\xc3\xa9'
|
||||
u_data = data.decode('utf-8')
|
||||
|
||||
class MyApp(App):
|
||||
def __init__(self):
|
||||
super(MyApp, self).__init__(
|
||||
description='testing',
|
||||
version='0.1',
|
||||
command_manager=CommandManager('tests'),
|
||||
)
|
||||
|
||||
stdout = StringIO()
|
||||
getdefaultlocale = mock.Mock(return_value=('ignored', None))
|
||||
|
||||
with mock.patch('sys.stdout', stdout):
|
||||
with mock.patch('locale.getdefaultlocale', getdefaultlocale):
|
||||
app = MyApp()
|
||||
app.stdout.write(u_data)
|
||||
actual = stdout.getvalue()
|
||||
assert data == actual
|
||||
|
||||
|
||||
def test_output_encoding_sys():
|
||||
# The encoding should come from sys.stdout because it is set
|
||||
# there.
|
||||
if sys.version_info[:2] != (2, 6):
|
||||
raise nose.SkipTest('only needed for python 2.6')
|
||||
data = '\xc3\xa9'
|
||||
u_data = data.decode('utf-8')
|
||||
|
||||
class MyApp(App):
|
||||
def __init__(self):
|
||||
super(MyApp, self).__init__(
|
||||
description='testing',
|
||||
version='0.1',
|
||||
command_manager=CommandManager('tests'),
|
||||
)
|
||||
|
||||
stdout = StringIO()
|
||||
stdout.encoding = 'utf-8'
|
||||
getdefaultlocale = mock.Mock(return_value=('ignored', 'utf-16'))
|
||||
|
||||
with mock.patch('sys.stdout', stdout):
|
||||
with mock.patch('locale.getdefaultlocale', getdefaultlocale):
|
||||
app = MyApp()
|
||||
app.stdout.write(u_data)
|
||||
actual = stdout.getvalue()
|
||||
assert data == actual
|
||||
|
||||
|
||||
def test_error_encoding_default():
|
||||
# The encoding should come from getdefaultlocale() because
|
||||
# stdout has no encoding set.
|
||||
if sys.version_info[:2] != (2, 6):
|
||||
raise nose.SkipTest('only needed for python 2.6')
|
||||
data = '\xc3\xa9'
|
||||
u_data = data.decode('utf-8')
|
||||
|
||||
class MyApp(App):
|
||||
def __init__(self):
|
||||
super(MyApp, self).__init__(
|
||||
description='testing',
|
||||
version='0.1',
|
||||
command_manager=CommandManager('tests'),
|
||||
)
|
||||
|
||||
stderr = StringIO()
|
||||
getdefaultlocale = mock.Mock(return_value=('ignored', 'utf-8'))
|
||||
|
||||
with mock.patch('sys.stderr', stderr):
|
||||
with mock.patch('locale.getdefaultlocale', getdefaultlocale):
|
||||
app = MyApp()
|
||||
app.stderr.write(u_data)
|
||||
actual = stderr.getvalue()
|
||||
assert data == actual
|
||||
|
||||
|
||||
def test_error_encoding_sys():
|
||||
# The encoding should come from sys.stdout (not sys.stderr)
|
||||
# because it is set there.
|
||||
if sys.version_info[:2] != (2, 6):
|
||||
raise nose.SkipTest('only needed for python 2.6')
|
||||
data = '\xc3\xa9'
|
||||
u_data = data.decode('utf-8')
|
||||
|
||||
class MyApp(App):
|
||||
def __init__(self):
|
||||
super(MyApp, self).__init__(
|
||||
description='testing',
|
||||
version='0.1',
|
||||
command_manager=CommandManager('tests'),
|
||||
)
|
||||
|
||||
stdout = StringIO()
|
||||
stdout.encoding = 'utf-8'
|
||||
stderr = StringIO()
|
||||
getdefaultlocale = mock.Mock(return_value=('ignored', 'utf-16'))
|
||||
|
||||
with mock.patch('sys.stdout', stdout):
|
||||
with mock.patch('sys.stderr', stderr):
|
||||
with mock.patch('locale.getdefaultlocale', getdefaultlocale):
|
||||
app = MyApp()
|
||||
app.stderr.write(u_data)
|
||||
actual = stderr.getvalue()
|
||||
assert data == actual
|
||||
|
||||
|
||||
def _test_help(deferred_help):
|
||||
app, _ = make_app(deferred_help=deferred_help)
|
||||
with mock.patch.object(app, 'initialize_app') as init:
|
||||
|
|
Loading…
Reference in New Issue