From 02a464591263e3e167fa40d1c080e22bddc23d4a Mon Sep 17 00:00:00 2001 From: Bernhard Scheirle Date: Mon, 14 Apr 2014 18:15:14 +0200 Subject: [PATCH] [pelican_comment_system] made python3 compatible --- pelican_comment_system/avatars.py | 6 ++++-- pelican_comment_system/comment.py | 2 +- pelican_comment_system/identicon/identicon.py | 17 +++++++++-------- .../pelican_comment_system.py | 7 ++++--- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pelican_comment_system/avatars.py b/pelican_comment_system/avatars.py index 5094d1c..d357f19 100644 --- a/pelican_comment_system/avatars.py +++ b/pelican_comment_system/avatars.py @@ -3,6 +3,8 @@ """ +from __future__ import unicode_literals + import logging import os @@ -12,7 +14,7 @@ import hashlib logger = logging.getLogger(__name__) _log = "pelican_comment_system: avatars: " try: - from identicon import identicon + from . identicon import identicon _identiconImported = True except ImportError as e: logger.warning(_log + "identicon deactivated: " + str(e)) @@ -66,7 +68,7 @@ def getAvatarPath(comment_id, metadata): for data in _identicon_data: if data in metadata: string = str(metadata[data]) - md5.update(string) + md5.update(string.encode('utf-8')) author += tuple([string]) else: logger.warning(_log + data + " is missing in comment: " + comment_id) diff --git a/pelican_comment_system/comment.py b/pelican_comment_system/comment.py index 84f03e6..cf5f4c8 100644 --- a/pelican_comment_system/comment.py +++ b/pelican_comment_system/comment.py @@ -2,7 +2,7 @@ """ """ - +from __future__ import unicode_literals from pelican import contents from pelican.contents import Content diff --git a/pelican_comment_system/identicon/identicon.py b/pelican_comment_system/identicon/identicon.py index 8318d87..eb4abe5 100755 --- a/pelican_comment_system/identicon/identicon.py +++ b/pelican_comment_system/identicon/identicon.py @@ -46,10 +46,10 @@ class Matrix2D(list): def __mul__(self, other): r = [] if isinstance(other, Matrix2D): - for y in xrange(3): - for x in xrange(3): + for y in range(3): + for x in range(3): v = 0.0 - for i in xrange(3): + for i in range(3): v += (self[i * 3 + x] * other[y * 3 + i]) r.append(v) else: @@ -119,7 +119,7 @@ class IdenticonRendererBase(object): # decode the code middle, corner, side, foreColor, backColor = self.decode(self.code) - + size = int(size) # make image image = Image.new("RGB", (size * 3, size * 3)) draw = ImageDraw.Draw(image) @@ -137,13 +137,13 @@ class IdenticonRendererBase(object): # side patch kwds['type'] = side[0] - for i in xrange(4): + for i in range(4): pos = [(1, 0), (2, 1), (1, 2), (0, 1)][i] self.drawPatch(pos, side[2] + 1 + i, side[1], **kwds) # corner patch kwds['type'] = corner[0] - for i in xrange(4): + for i in range(4): pos = [(0, 0), (2, 0), (2, 2), (0, 2)][i] self.drawPatch(pos, corner[2] + 1 + i, corner[1], **kwds) @@ -203,9 +203,10 @@ class DonRenderer(IdenticonRendererBase): MIDDLE_PATCH_SET = [0, 4, 8, 15] # modify path set - for idx in xrange(len(PATH_SET)): + for idx in range(len(PATH_SET)): if PATH_SET[idx]: p = map(lambda vec: (vec[0] / 4.0, vec[1] / 4.0), PATH_SET[idx]) + p = list(p) PATH_SET[idx] = p + p[:1] def decode(self, code): @@ -240,7 +241,7 @@ if __name__ == '__main__': import sys if len(sys.argv) < 2: - print 'usage: python identicon.py [CODE]....' + print('usage: python identicon.py [CODE]....') raise SystemExit for code in sys.argv[1:]: diff --git a/pelican_comment_system/pelican_comment_system.py b/pelican_comment_system/pelican_comment_system.py index f9cce59..aecf8a0 100644 --- a/pelican_comment_system/pelican_comment_system.py +++ b/pelican_comment_system/pelican_comment_system.py @@ -7,7 +7,7 @@ A Pelican plugin, which allows you to add comments to your articles. Author: Bernhard Scheirle """ - +from __future__ import unicode_literals import logging import os import copy @@ -19,8 +19,9 @@ from pelican import signals from pelican.readers import MarkdownReader from pelican.writers import Writer -import avatars -from comment import Comment +from . comment import Comment +from . import avatars + def pelican_initialized(pelican): from pelican.settings import DEFAULT_CONFIG