Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

code changes based on 2to3 output

all the changes are 2.6+ compatible
  • Loading branch information...
commit 3b2101037232e10c8fcc4b0ae4952de3be459f4b 1 parent f47358a
@fabiomcosta fabiomcosta authored
View
12 tests/test_detectors.py
@@ -4,12 +4,12 @@
# thumbor imaging service
# https://github.com/globocom/thumbor/wiki
-# Licensed under the MIT license:
+# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com
from os.path import join, dirname, abspath
-from cStringIO import StringIO
+from io import StringIO
from thumbor.detectors.face_detector import Detector as FaceDetector
from thumbor.detectors.glasses_detector import Detector as GlassesDetector
@@ -19,6 +19,7 @@
__dirname = abspath(dirname(__file__))
+
def get_context_from(image, detectors):
filename = join(__dirname, 'fixtures', 'img', image)
buffer = open(filename).read()
@@ -32,10 +33,12 @@ def get_context_from(image, detectors):
detectors[0](index=0, detectors=detectors).detect(context)
return context
+
def test_should_not_create_focal_points_on_images_that_has_no_face():
focal_points = get_context_from('fixture1.png', [FaceDetector])['focal_points']
assert len(focal_points) == 0
+
def test_should_return_detect_a_face():
focal_points = get_context_from('face.jpg', [FaceDetector])['focal_points']
assert len(focal_points) == 1
@@ -43,13 +46,12 @@ def test_should_return_detect_a_face():
assert focal_points[0].y == 80.48
assert focal_points[0].weight == 13689
+
def test_should_not_detect_glasses():
focal_points = get_context_from('fixture1.png', [GlassesDetector])['focal_points']
assert len(focal_points) == 0
+
def test_should_detect_glasses():
focal_points = get_context_from('glasses.jpg', [GlassesDetector])['focal_points']
assert len(focal_points) == 1
-
-
-
View
13 tests/test_handlers.py
@@ -4,13 +4,13 @@
# thumbor imaging service
# https://github.com/globocom/thumbor/wiki
-# Licensed under the MIT license:
+# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com
import os
from os.path import join, abspath, dirname
-from cStringIO import StringIO
+from io import StringIO
import unittest
from PIL import Image
@@ -20,16 +20,18 @@
get_conf_path = lambda filename: abspath(join(os.environ.get('test_path', dirname(__file__)), 'fixtures', filename))
+
class MainHandlerSourcePathTest(AsyncHTTPTestCase):
-
+
def get_app(self):
return ThumborServiceApp(get_conf_path('conf1.py'))
-
+
def test_validates_passed_url_is_in_valid_source(self):
self.http_client.fetch(self.get_url('/unsafe/www.mydomain.com/logo2.jpg'), self.stop)
response = self.wait()
self.assertEqual(404, response.code)
+
class MainHandlerTest(AsyncHTTPTestCase):
def get_app(self):
@@ -40,6 +42,7 @@ def test_returns_success_status_code(self):
response = self.wait(timeout=20)
self.assertEqual(200, response.code)
+
class ImageTestCase(AsyncHTTPTestCase):
def get_app(self):
@@ -51,6 +54,7 @@ def fetch_image(self, url):
self.assertEqual(200, response.code)
return Image.open(StringIO(response.body))
+
class MainHandlerImagesTest(ImageTestCase):
def test_resizes_the_passed_image(self):
@@ -71,6 +75,7 @@ def test_flips_horizontaly_the_passed_image(self):
self.assertEqual(pixels, reversed_pixels_flipped, 'did not flip the image')
+
class MainHandlerFitInImagesTest(ImageTestCase):
def test_fits_in_image_horizontally(self):
View
16 thumbor/filters/__init__.py
@@ -12,15 +12,16 @@
STRIP_QUOTE = re.compile(r"^'(.+)'$")
+
def filter_method(*args, **kwargs):
def _filter_deco(fn):
def wrapper(self, *args2):
return fn(self, *args2)
defaults = None
- if fn.func_defaults:
- default_padding = [None] * (len(args) - (len(fn.func_defaults)))
- defaults = default_padding + list(fn.func_defaults)
+ if fn.__defaults__:
+ default_padding = [None] * (len(args) - (len(fn.__defaults__)))
+ defaults = default_padding + list(fn.__defaults__)
wrapper.filter_data = {
'name': fn.__name__,
@@ -57,6 +58,7 @@ def create_instances(self, context, filter_params):
filter_objs.append(instance)
return filter_objs
+
class BaseFilter(object):
PositiveNumber = {
@@ -86,7 +88,7 @@ class BaseFilter(object):
@classmethod
def pre_compile(cls):
- meths = filter(lambda f: hasattr(f, 'filter_data'), cls.__dict__.values())
+ meths = [f for f in list(cls.__dict__.values()) if hasattr(f, 'filter_data')]
if len(meths) == 0:
return
cls.runnable_method = meths[0]
@@ -124,7 +126,7 @@ def init_if_valid(cls, param, context):
else:
return None
- def __init__(self, params, context = None):
+ def __init__(self, params, context=None):
params = self.regex.match(params) if self.regex else None
if params:
params = [parser(param) if parser else param for parser, param in zip(self.parsers, params.groups()) if param]
@@ -132,7 +134,7 @@ def __init__(self, params, context = None):
self.context = context
self.engine = context.modules.engine if context and context.modules else None
- def run(self, callback = None):
+ def run(self, callback=None):
if self.params is None:
return
@@ -155,4 +157,4 @@ def run(self, callback = None):
if (not self.async_filter) and callback:
callback()
- return results
+ return results
View
2  thumbor/importer.py
@@ -9,6 +9,8 @@
# Copyright (c) 2011 globo.com timehome@corp.globo.com
from thumbor.utils import logger
+from functools import reduce
+
class Importer:
def __init__(self, config):
View
6 thumbor/storages/mongo_storage.py
@@ -9,13 +9,14 @@
# Copyright (c) 2011 globo.com timehome@corp.globo.com
from datetime import datetime, timedelta
-from cStringIO import StringIO
+from io import StringIO
from pymongo import Connection
import gridfs
from thumbor.storages import BaseStorage
+
class Storage(BaseStorage):
def __conn__(self):
@@ -104,7 +105,8 @@ def exists(self, path):
return True
def remove(self, path):
- if not self.exists(path): return
+ if not self.exists(path):
+ return
connection, db, storage = self.__conn__()
storage.remove({'path': path})
View
8 thumbor/utils.py
@@ -4,15 +4,17 @@
# thumbor imaging service
# https://github.com/globocom/thumbor/wiki
-# Licensed under the MIT license:
+# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com
import logging
+from functools import reduce
+
def real_import(name):
- if '.' in name:
+ if '.' in name:
return reduce(getattr, name.split('.')[1:], __import__(name))
return __import__(name)
-logger = logging.getLogger('thumbor')
+logger = logging.getLogger('thumbor')
Please sign in to comment.
Something went wrong with that request. Please try again.