From 5d3b11a1445b7ea58c3df6b0fadafee57bc7f131 Mon Sep 17 00:00:00 2001 From: KM4YRI Date: Thu, 12 Jan 2017 04:49:13 -0500 Subject: [PATCH] added Python six compatibility layer (#10) added dependency to `six` for better Python 2/3 compatibility --- pysstv/color.py | 9 ++------- pysstv/grayscale.py | 8 +------- pysstv/sstv.py | 17 +++-------------- requirements.txt | 1 + 4 files changed, 7 insertions(+), 28 deletions(-) diff --git a/pysstv/color.py b/pysstv/color.py index e70709c..48baf4a 100644 --- a/pysstv/color.py +++ b/pysstv/color.py @@ -1,12 +1,6 @@ #!/usr/bin/env python - from __future__ import division -try: # python 2/3 compatibility - xrange # will fail in python 3 -except NameError: - pass -else: - range = xrange +from six.moves import range from pysstv.sstv import byte_to_freq, FREQ_BLACK, FREQ_WHITE, FREQ_VIS_START from pysstv.grayscale import GrayscaleSSTV from itertools import chain @@ -14,6 +8,7 @@ from itertools import chain RED, GREEN, BLUE = range(3) + class ColorSSTV(GrayscaleSSTV): def on_init(self): self.pixels = self.image.load() diff --git a/pysstv/grayscale.py b/pysstv/grayscale.py index 63ce0aa..2b106d8 100644 --- a/pysstv/grayscale.py +++ b/pysstv/grayscale.py @@ -1,13 +1,7 @@ #!/usr/bin/env python from __future__ import division - -try: # python 2/3 compatibility - xrange # will fail in python 3 -except NameError: - pass -else: - range = xrange +from six.moves import range from pysstv.sstv import SSTV, byte_to_freq diff --git a/pysstv/sstv.py b/pysstv/sstv.py index e2e417e..535623a 100644 --- a/pysstv/sstv.py +++ b/pysstv/sstv.py @@ -1,24 +1,13 @@ #!/usr/bin/env python from __future__ import division, with_statement +from six.moves import range +from six.moves import map +from six.moves import zip from math import sin, pi from random import random from contextlib import closing -try: - import itertools.imap as map # python 2 -except ImportError: - pass # python 3 -try: - import itertools.izip as zip # python 2 -except ImportError: - pass # python 3 from itertools import cycle, chain -try: # python 2/3 compatibility - xrange # will fail in python 3 -except NameError: - pass -else: - range = xrange from array import array import wave diff --git a/requirements.txt b/requirements.txt index 4ed5a08..58e63c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +six==1.10.0 Pillow==2.2.1 mock==1.0.1 nose==1.3.0