From 2d8a62a62e9871cb4a75d8487cb7818b0efba66d Mon Sep 17 00:00:00 2001
From: Vincent Danjean <vdanjean@debian.org>
Date: Wed, 27 Jun 2018 23:12:26 +0200
Subject: Fix syntax for python3 support (keeping python2 compatibility)

---
 grapefruit.py      | 10 +++++++---
 grapefruit_test.py |  9 ++++++---
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/grapefruit.py b/grapefruit.py
index 43d68f1..f6e5738 100755
--- a/grapefruit.py
+++ b/grapefruit.py
@@ -17,6 +17,10 @@
 
 '''GrapeFruit - Color manipulation in Python'''
 
+# both next line to support python3
+from functools import reduce
+from past.builtins import xrange
+
 # $Id: grapefruit.py 30 2008-06-01 20:44:26Z xbasty $
 __author__ = 'Xavier Basty <xbasty@gmail.com>'
 __version__ = '0.1a3'
@@ -285,7 +289,7 @@ class Color:
 
     '''
     if not(isinstance(values, tuple)):
-      raise TypeError, 'values must be a tuple'
+      raise TypeError('values must be a tuple')
 
     if mode=='rgb':
       self.__rgb = values
@@ -921,7 +925,7 @@ class Color:
     html = html.strip().lower()
     if html[0]=='#':
       html = html[1:]
-    elif Color.NAMED_COLOR.has_key(html):
+    elif html in Color.NAMED_COLOR:
       html = Color.NAMED_COLOR[html][1:]
 
     if len(html)==6:
@@ -929,7 +933,7 @@ class Color:
     elif len(html)==3:
       rgb = ['%c%c' % (v,v) for v in html]
     else:
-      raise ValueError, 'input #%s is not in #RRGGBB format' % html
+      raise ValueError('input #%s is not in #RRGGBB format' % html)
     
     return tuple(((int(n, 16) / 255.0) for n in rgb))
 
diff --git a/grapefruit_test.py b/grapefruit_test.py
index 5693c24..0aa0541 100755
--- a/grapefruit_test.py
+++ b/grapefruit_test.py
@@ -21,6 +21,9 @@
 __author__ = 'xbasty@gmail.com'
 __version__ = '0.1a3'
 
+# next line to support python3
+from past.builtins import xrange
+
 import unittest
 import grapefruit
 
@@ -32,13 +35,13 @@ class GrapeFruitTestCase(unittest.TestCase):
     '''
     if hasattr(first,'__iter__') and hasattr(second,'__iter__'):
       if len(first) != len(second):
-        raise self.failureException, (msg or "%r != %r" % (first, second))
+        raise self.failureException(msg or "%r != %r" % (first, second))
       
       for f, s in zip(first, second):
         if abs(s-f) > diff:
-          raise self.failureException, (msg or "%r != %r @ %f" % (first, second, diff))
+          raise self.failureException(msg or "%r != %r @ %f" % (first, second, diff))
     elif abs(second-first) > diff:
-      raise self.failureException, (msg or "%r != %r @ %f" % (first, second, diff))
+      raise self.failureException(msg or "%r != %r @ %f" % (first, second, diff))
   assertNear = failUnlessNear
 
 class ConversionTest(GrapeFruitTestCase):
