[pelican_comment_system] made python3 compatible

This commit is contained in:
Bernhard Scheirle
2014-04-14 18:15:14 +02:00
parent 24fce038c3
commit 02a4645912
4 changed files with 18 additions and 14 deletions

View File

@@ -3,6 +3,8 @@
""" """
from __future__ import unicode_literals
import logging import logging
import os import os
@@ -12,7 +14,7 @@ import hashlib
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
_log = "pelican_comment_system: avatars: " _log = "pelican_comment_system: avatars: "
try: try:
from identicon import identicon from . identicon import identicon
_identiconImported = True _identiconImported = True
except ImportError as e: except ImportError as e:
logger.warning(_log + "identicon deactivated: " + str(e)) logger.warning(_log + "identicon deactivated: " + str(e))
@@ -66,7 +68,7 @@ def getAvatarPath(comment_id, metadata):
for data in _identicon_data: for data in _identicon_data:
if data in metadata: if data in metadata:
string = str(metadata[data]) string = str(metadata[data])
md5.update(string) md5.update(string.encode('utf-8'))
author += tuple([string]) author += tuple([string])
else: else:
logger.warning(_log + data + " is missing in comment: " + comment_id) logger.warning(_log + data + " is missing in comment: " + comment_id)

View File

@@ -2,7 +2,7 @@
""" """
""" """
from __future__ import unicode_literals
from pelican import contents from pelican import contents
from pelican.contents import Content from pelican.contents import Content

View File

@@ -46,10 +46,10 @@ class Matrix2D(list):
def __mul__(self, other): def __mul__(self, other):
r = [] r = []
if isinstance(other, Matrix2D): if isinstance(other, Matrix2D):
for y in xrange(3): for y in range(3):
for x in xrange(3): for x in range(3):
v = 0.0 v = 0.0
for i in xrange(3): for i in range(3):
v += (self[i * 3 + x] * other[y * 3 + i]) v += (self[i * 3 + x] * other[y * 3 + i])
r.append(v) r.append(v)
else: else:
@@ -119,7 +119,7 @@ class IdenticonRendererBase(object):
# decode the code # decode the code
middle, corner, side, foreColor, backColor = self.decode(self.code) middle, corner, side, foreColor, backColor = self.decode(self.code)
size = int(size)
# make image # make image
image = Image.new("RGB", (size * 3, size * 3)) image = Image.new("RGB", (size * 3, size * 3))
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
@@ -137,13 +137,13 @@ class IdenticonRendererBase(object):
# side patch # side patch
kwds['type'] = side[0] kwds['type'] = side[0]
for i in xrange(4): for i in range(4):
pos = [(1, 0), (2, 1), (1, 2), (0, 1)][i] pos = [(1, 0), (2, 1), (1, 2), (0, 1)][i]
self.drawPatch(pos, side[2] + 1 + i, side[1], **kwds) self.drawPatch(pos, side[2] + 1 + i, side[1], **kwds)
# corner patch # corner patch
kwds['type'] = corner[0] kwds['type'] = corner[0]
for i in xrange(4): for i in range(4):
pos = [(0, 0), (2, 0), (2, 2), (0, 2)][i] pos = [(0, 0), (2, 0), (2, 2), (0, 2)][i]
self.drawPatch(pos, corner[2] + 1 + i, corner[1], **kwds) self.drawPatch(pos, corner[2] + 1 + i, corner[1], **kwds)
@@ -203,9 +203,10 @@ class DonRenderer(IdenticonRendererBase):
MIDDLE_PATCH_SET = [0, 4, 8, 15] MIDDLE_PATCH_SET = [0, 4, 8, 15]
# modify path set # modify path set
for idx in xrange(len(PATH_SET)): for idx in range(len(PATH_SET)):
if PATH_SET[idx]: if PATH_SET[idx]:
p = map(lambda vec: (vec[0] / 4.0, vec[1] / 4.0), 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] PATH_SET[idx] = p + p[:1]
def decode(self, code): def decode(self, code):
@@ -240,7 +241,7 @@ if __name__ == '__main__':
import sys import sys
if len(sys.argv) < 2: if len(sys.argv) < 2:
print 'usage: python identicon.py [CODE]....' print('usage: python identicon.py [CODE]....')
raise SystemExit raise SystemExit
for code in sys.argv[1:]: for code in sys.argv[1:]:

View File

@@ -7,7 +7,7 @@ A Pelican plugin, which allows you to add comments to your articles.
Author: Bernhard Scheirle Author: Bernhard Scheirle
""" """
from __future__ import unicode_literals
import logging import logging
import os import os
import copy import copy
@@ -19,8 +19,9 @@ from pelican import signals
from pelican.readers import MarkdownReader from pelican.readers import MarkdownReader
from pelican.writers import Writer from pelican.writers import Writer
import avatars from . comment import Comment
from comment import Comment from . import avatars
def pelican_initialized(pelican): def pelican_initialized(pelican):
from pelican.settings import DEFAULT_CONFIG from pelican.settings import DEFAULT_CONFIG