Skip to content

Commit

Permalink
Switch from 2to3 to six. Close #132.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikrose committed Jun 19, 2018
2 parents d77de4d + 86765e2 commit ed91a35
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: python
python:
- 2.7
- 3.4
- 3.5
- 3.6
- pypy

Expand Down
15 changes: 8 additions & 7 deletions blessings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import curses
from curses import setupterm, tigetnum, tigetstr, tparm
from fcntl import ioctl
from six import text_type, string_types

try:
from io import UnsupportedOperation as IOUnsupportedOperation
Expand Down Expand Up @@ -420,7 +421,7 @@ def derivative_colors(colors):
'shadow', 'standout', 'subscript', 'superscript']))


class ParametrizingString(unicode):
class ParametrizingString(text_type):
"""A Unicode string which can be called to parametrize it as a terminal
capability"""

Expand All @@ -432,7 +433,7 @@ def __new__(cls, formatting, normal=None):
"normal" capability.
"""
new = unicode.__new__(cls, formatting)
new = text_type.__new__(cls, formatting)
new._normal = normal
return new

Expand Down Expand Up @@ -461,7 +462,7 @@ def __call__(self, *args):
except TypeError:
# If the first non-int (i.e. incorrect) arg was a string, suggest
# something intelligent:
if len(args) == 1 and isinstance(args[0], basestring):
if len(args) == 1 and isinstance(args[0], string_types):
raise TypeError(
'A native or nonexistent capability template received '
'%r when it was expecting ints. You probably misspelled a '
Expand All @@ -472,12 +473,12 @@ def __call__(self, *args):
raise


class FormattingString(unicode):
class FormattingString(text_type):
"""A Unicode string which can be called upon a piece of text to wrap it in
formatting"""

def __new__(cls, formatting, normal):
new = unicode.__new__(cls, formatting)
new = text_type.__new__(cls, formatting)
new._normal = normal
return new

Expand All @@ -492,15 +493,15 @@ def __call__(self, text):
return self + text + self._normal


class NullCallableString(unicode):
class NullCallableString(text_type):
"""A dummy callable Unicode to stand in for ``FormattingString`` and
``ParametrizingString``
We use this when there is no tty and thus all capabilities should be blank.
"""
def __new__(cls):
new = unicode.__new__(cls, u'')
new = text_type.__new__(cls, u'')
return new

def __call__(self, *args):
Expand Down
11 changes: 5 additions & 6 deletions blessings/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
xterm-256color exists.
"""
from __future__ import with_statement # Make 2.5-compatible
from curses import tigetstr, tparm
from functools import partial
from StringIO import StringIO
import sys

from nose import SkipTest
from nose.tools import eq_
from six import StringIO

# This tests that __all__ is correct, since we use below everything that should
# be imported:
Expand Down Expand Up @@ -229,22 +228,22 @@ def test_nice_formatting_errors():
t = TestTerminal()
try:
t.bold_misspelled('hey')
except TypeError, e:
except TypeError as e:
assert 'probably misspelled' in e.args[0]

try:
t.bold_misspelled(u'hey') # unicode
except TypeError, e:
except TypeError as e:
assert 'probably misspelled' in e.args[0]

try:
t.bold_misspelled(None) # an arbitrary non-string
except TypeError, e:
except TypeError as e:
assert 'probably misspelled' not in e.args[0]

try:
t.bold_misspelled('a', 'b') # >1 string arg
except TypeError, e:
except TypeError as e:
assert 'probably misspelled' not in e.args[0]


Expand Down
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from setuptools import setup, find_packages


extra_setup = {}
if sys.version_info >= (3,):
extra_setup['use_2to3'] = True

setup(
name='blessings',
version='1.6.1',
Expand All @@ -23,6 +19,7 @@
author_email='erikrose@grinchcentral.com',
license='MIT',
packages=find_packages(exclude=['ez_setup']),
install_requires=['six'],
tests_require=['nose'],
test_suite='nose.collector',
url='https://github.com/erikrose/blessings',
Expand All @@ -49,5 +46,4 @@
'Topic :: Terminals'
],
keywords=['terminal', 'tty', 'curses', 'ncurses', 'formatting', 'style', 'color', 'console'],
**extra_setup
)
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tox]
envlist = py27, py34, py36
envlist = py{27,34,35,36,py}

[testenv]
commands = nosetests blessings
deps = nose
# So Python 3 runs don't pick up incompatible, un-2to3'd source from the cwd:
changedir = .tox
deps =
nose
six

0 comments on commit ed91a35

Please sign in to comment.