Skip to content

Commit

Permalink
Fix section color hashing when using Python 2
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 3, 2016
1 parent b90364e commit 01b65f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -11,6 +11,7 @@ Features
Bugfixes
--------

* Fix section color hashing when using Python 2
* Use ``en_US`` dictionary name with pyphen for better compatibility
* Fix graceful degradation if ``pyphen`` lacks dictionaries
* Add horizontal scrollbar to listings (via getnikola/nikola-themes#86)
Expand Down
9 changes: 8 additions & 1 deletion nikola/utils.py
Expand Up @@ -1801,7 +1801,14 @@ def colorize_str_from_base_color(string, base_color):
lightness and saturation untouched using HUSL colorspace.
"""
def hash_str(string, pos):
return hashlib.md5(string.encode('utf-8')).digest()[pos]
x = hashlib.md5(string.encode('utf-8')).digest()[pos]
try:
# Python 2: a string
# TODO: remove in v8
return ord(x)
except TypeError:
# Python 3: already an integer
return x

def degreediff(dega, degb):
return min(abs(dega - degb), abs((degb - dega) + 360))
Expand Down

0 comments on commit 01b65f8

Please sign in to comment.