Skip to content

Commit

Permalink
Merge pull request b-ryan#220 from ceholden/py3
Browse files Browse the repository at this point in the history
Py3 fixes to lib/color_compliment.py
  • Loading branch information
amtrivedi91 committed Dec 26, 2015
2 parents cac9346 + 5eda8d0 commit dc2c8ba
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/color_compliment.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#! /usr/bin/env python

from colortrans import *
from colorsys import hls_to_rgb, rgb_to_hls
from md5 import md5
from sys import argv
# md5 deprecated since Python 2.5
try:
from md5 import md5
except ImportError:
from hashlib import md5
import sys

# Original, non-relative import errors on Python3
from .colortrans import *

py3 = sys.version_info[0] == 3


def getOppositeColor(r,g,b):
Expand All @@ -27,6 +34,10 @@ def getOppositeColor(r,g,b):
return tuple([ int(x) for x in opp])

def stringToHashToColorAndOpposite(string):
# Python3: Unicode string must be encoded before digest
# Python2.7: works either way, but check in case breaks earlier py2
if py3:
string = string.encode('utf-8')
string = md5(string).hexdigest()[:6] # get a random color
color1 = rgbstring2tuple(string)
color2 = getOppositeColor(*color1)
Expand Down

0 comments on commit dc2c8ba

Please sign in to comment.