diff --git a/ox/html.py b/ox/html.py
index 2ba6179..dcdb246 100644
--- a/ox/html.py
+++ b/ox/html.py
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
# GPL 2008
-import sys
import re
import string
from six.moves.html_entities import name2codepoint
-from six import unichr
+from six import unichr, PY2
# Configuration for add_links() function
@@ -25,7 +24,7 @@ link_target_attribute_re = re.compile(r'(]*?)target=[^\s>]+')
html_gunk_re = re.compile(r'(?:
|<\/i>|<\/b>|<\/em>|<\/strong>|<\/?smallcaps>|<\/?uppercase>)', re.IGNORECASE)
hard_coded_bullets_re = re.compile(r'((?:(?:%s).*?[a-zA-Z].*?
\s*)+)' % '|'.join([re.escape(x) for x in DOTS]), re.DOTALL)
trailing_empty_content_re = re.compile(r'(?:(?: |\s|
)*?
\s*)+\Z')
-if sys.version[0] == 2:
+if PY2:
del x # Temporary variable
def escape(html):
diff --git a/ox/image.py b/ox/image.py
index a4ed5ef..82cf5c3 100644
--- a/ox/image.py
+++ b/ox/image.py
@@ -3,15 +3,23 @@
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division
-from hashlib import sha1
-import Image
-import ImageDraw
-import ImageFont
+
+try:
+ from PIL import Image
+ from PIL import ImageDraw
+ from PIL import ImageFont
+except:
+ import Image
+ import ImageDraw
+ import ImageFont
+
ZONE_INDEX = []
for pixel_index in range(64):
x, y = pixel_index % 8, int(pixel_index / 8)
ZONE_INDEX.append(int(x / 2) + int(y / 4) * 4)
+del x
+del y
def drawText(image, position, text, font_file, font_size, color):
draw = ImageDraw.Draw(image)
@@ -20,7 +28,7 @@ def drawText(image, position, text, font_file, font_size, color):
return draw.textsize(text, font=font)
def getHSL(rgb):
- rgb = map(lambda x: x / 255, rgb)
+ rgb = [x / 255 for x in rgb]
maximum = max(rgb)
minimum = min(rgb)
hsl = [0.0, 0.0, 0.0]
@@ -60,7 +68,7 @@ def getImageHash(image_file, mode):
zone_values[ZONE_INDEX[pixel_index]].append(pixel_value)
for zone_index, pixel_values in enumerate(zone_values):
# get the mean for each color channel
- mean = map(lambda x: int(round(sum(x) / 8)), zip(*pixel_values))
+ mean = [int(round(sum(x) / 8)) for x in zip(*pixel_values)]
# store the mean color of each zone as an 8-bit value:
# RRRGGGBB
color_index = sum((
@@ -128,7 +136,7 @@ def getRGB(hsl):
rgb[i] = v1 + ((v2 - v1) * 6 * (2/3 - v3))
else:
rgb[i] = v1
- return tuple(map(lambda x: int(x * 255), rgb))
+ return tuple([int(x * 255) for x in rgb])
def getTextSize(image, text, font_file, font_size):
draw = ImageDraw.Draw(image)
diff --git a/ox/js.py b/ox/js.py
index 13ead66..5bc68d5 100644
--- a/ox/js.py
+++ b/ox/js.py
@@ -1,16 +1,16 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
-import sys
-from ox.utils import json
+from six import PY2
+from .utils import json
def minify(source, comment=''):
# see https://github.com/douglascrockford/JSMin/blob/master/README
def get_next_non_whitespace_token():
pass
# python2 performance with unicode string is terrible
- if sys.version[0] == '2':
+ if PY2:
if isinstance(source, unicode):
source = source.encode('utf-8')
if isinstance(comment, unicode):