def test_can_get_handlers_with_blacklist(self): ctx = self.get_context() ctx.config.UPLOAD_ENABLED = False ctx.config.USE_BLACKLIST = True app = ThumborServiceApp(ctx) handlers = app.get_handlers() expect(handlers).to_length(3)
def test_can_get_handlers_with_blacklist(self): ctx = mock.Mock(config=mock.Mock( UPLOAD_ENABLED=False, USE_BLACKLIST=True, )) app = ThumborServiceApp(ctx) handlers = app.get_handlers() expect(handlers).to_length(3)
def test_can_get_handlers(self): ctx = mock.Mock(config=mock.Mock( UPLOAD_ENABLED=False, USE_BLACKLIST=False, )) app = ThumborServiceApp(ctx) handlers = app.get_handlers() expect(handlers).to_length(2) expect(handlers[0][0]).to_equal(r'/healthcheck') expect(handlers[1][0]).to_equal(Url.regex())
def test_can_get_handlers(self): ctx = self.get_context() ctx.config.UPLOAD_ENABLED = False ctx.config.USE_BLACKLIST = False ctx.config.HEALTHCHECK_ROUTE = "/health" app = ThumborServiceApp(ctx) handlers = app.get_handlers() expect(handlers).to_length(2) expect(handlers[0][0]).to_equal(r"/health") expect(handlers[1][0]).to_equal(Url.regex())
def test_can_get_handlers_with_blacklist(self): ctx = mock.Mock( config=mock.Mock( UPLOAD_ENABLED=False, USE_BLACKLIST=True, ) ) app = ThumborServiceApp(ctx) handlers = app.get_handlers() expect(handlers).to_length(3)
def test_can_get_handlers(self): ctx = mock.Mock( config=mock.Mock( UPLOAD_ENABLED=False, USE_BLACKLIST=False, ) ) app = ThumborServiceApp(ctx) handlers = app.get_handlers() expect(handlers).to_length(2) expect(handlers[0][0]).to_equal(r'/healthcheck') expect(handlers[1][0]).to_equal(Url.regex())
def get_app(self): cfg = Config(SECURITY_KEY="ACME-SEC") server_params = ServerParameters(None, None, None, None, None, None) server_params.gifsicle_path = which("gifsicle") cfg.DETECTORS = [ "thumbor.detectors.face_detector", "thumbor.detectors.profile_detector", "thumbor.detectors.glasses_detector", "thumbor.detectors.feature_detector", ] cfg.STORAGE = "thumbor.storages.no_storage" cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = os.path.join(os.path.dirname(__file__), "imgs") cfg.ENGINE = getattr(self, "engine", None) cfg.USE_GIFSICLE_ENGINE = True cfg.FFMPEG_PATH = which("ffmpeg") cfg.ENGINE_THREADPOOL_SIZE = 10 cfg.OPTIMIZERS = [ "thumbor.optimizers.gifv", ] if not cfg.ENGINE: return None importer = Importer(cfg) importer.import_modules() ctx = Context(server_params, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') server_params = ServerParameters(None, None, None, None, None, None) server_params.gifsicle_path = which('gifsicle') cfg.DETECTORS = [ 'thumbor.detectors.face_detector', 'thumbor.detectors.profile_detector', 'thumbor.detectors.glasses_detector', 'thumbor.detectors.feature_detector', ] cfg.STORAGE = 'thumbor.storages.no_storage' cfg.LOADER = 'thumbor.loaders.file_loader' cfg.FILE_LOADER_ROOT_PATH = os.path.join(os.path.dirname(__file__), 'imgs') cfg.ENGINE = getattr(self, 'engine', None) cfg.MP4_ENGINE = 'thumbor.engines.mp4' cfg.USE_GIFSICLE_ENGINE = True cfg.FFMPEG_PATH = which('ffmpeg') cfg.FFPROBE_PATH = which('ffprobe') cfg.CONVERT_PATH = which('convert') cfg.ENGINE_THREADPOOL_SIZE = 10 cfg.OPTIMIZERS = [ 'thumbor.optimizers.gifv', ] if not cfg.ENGINE: return None importer = Importer(cfg) importer.import_modules() ctx = Context(server_params, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): cfg = Config.load(fixture_for('encrypted_handler_conf.py')) importer = Importer(cfg) importer.import_modules() ctx = Context(None, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') server_params = ServerParameters(None, None, None, None, None, None) server_params.gifsicle_path = which('gifsicle') cfg.DETECTORS = [ 'thumbor.detectors.face_detector', 'thumbor.detectors.profile_detector', 'thumbor.detectors.glasses_detector', 'thumbor.detectors.feature_detector', ] cfg.STORAGE = 'thumbor.storages.no_storage' cfg.LOADER = 'thumbor.loaders.file_loader' cfg.FILE_LOADER_ROOT_PATH = os.path.join(os.path.dirname(__file__), 'imgs') cfg.ENGINE = getattr(self, 'engine', None) cfg.USE_GIFSICLE_ENGINE = True if not cfg.ENGINE: return None importer = Importer(cfg) importer.import_modules() ctx = Context(server_params, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): cfg = Config(SECURITY_KEY='MYKEY') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path cfg.ALLOW_UNSAFE_URL = False cfg.ALLOW_OLD_URLS = True cfg.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True importer = Importer(cfg) importer.import_modules() server = ServerParameters(8891, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'MYKEY' ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) storage = FileStorage(Context(config=cfg, server=server)) # Store fixtures (image.jpg and image.txt) into the file storage storage.put('image.jpg', file(join(storage_path, 'image.jpg')).read()) storage.put_crypto( 'image.jpg' ) # Write a file on the file storage containing the security key return application
def get_app(self): storage_path = '/tmp/thumbor-engines-test/' if exists(storage_path): rmtree(storage_path) self.timeout_handle = None cfg = Config(SECURITY_KEY='ACME-SEC', FILE_STORAGE_ROOT_PATH=storage_path) server_params = ServerParameters(None, None, None, None, None, None) cfg.DETECTORS = [ 'thumbor.detectors.face_detector', 'thumbor.detectors.profile_detector', 'thumbor.detectors.glasses_detector', 'thumbor.detectors.feature_detector', ] conf_key = self._testMethodName.split('__')[1] conf = CONFS.get(conf_key, None) if conf: for key, value in conf.items(): setattr(cfg, key, value) importer = Importer(cfg) importer.import_modules() ctx = Context(server_params, cfg, importer) application = ThumborServiceApp(ctx) return application
def main(arguments=None): '''Runs thumbor server with the specified arguments.''' server_parameters = get_server_parameters(arguments) logging.basicConfig( level=getattr(logging, server_parameters.log_level.upper())) config = Config.load(server_parameters.config_path) importer = Importer(config) importer.import_modules() if server_parameters.security_key is not None: config.SECURITY_KEY = server_parameters.security_key if not isinstance(config.SECURITY_KEY, basestring): raise RuntimeError( 'No security key was found for this instance of thumbor. Please provide one using the conf file or a security key file.' ) context = Context(server=server_parameters, config=config, importer=importer) application = ThumborServiceApp(context) server = HTTPServer(application) server.bind(context.server.port, context.server.ip) server.start(1) try: tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: print print "-- thumbor closed by user interruption --"
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage' cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60 cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = tempfile.mkdtemp( prefix='thumbor_test') cfg.USE_GIFSICLE_ENGINE = True cfg.AUTO_WEBP = True cfg.OPTIMIZERS = [ 'thumbor.optimizers.gifv', ] importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, importer) ctx.server.gifsicle_path = which('gifsicle') application = ThumborServiceApp(ctx) self.engine = PILEngine(ctx) return application
def get_app(self): conf = open(join(fixtures_folder, 'file_loader_conf.py')).read() conf = conf.replace(r'@@rootdir@@', fixtures_folder) conf_file = tempfile.NamedTemporaryFile(mode='w+b', dir='/tmp', delete=False) conf_file.write(conf) conf_file.close() return ThumborServiceApp(conf_file.name)
def get_app(self): cfg = Config.load(fixture_for('encrypted_handler_conf.py')) server_params = ServerParameters(None, None, None, None, None, None) server_params.security_key = 'HandlerVows' importer = Importer(cfg) importer.import_modules() ctx = Context(server_params, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_handlers(self): handlers = ThumborServiceApp.get_handlers(self) # Remove the default image handler handlers.pop() # Then install our own image handler handlers.append((Url.regex(), RewriteHandler, { 'context': self.context })) return handlers
def get_app(self): cfg = Config() cfg.UPLOAD_ENABLED = True cfg.UPLOAD_PHOTO_STORAGE = 'thumbor.storages.file_storage' cfg.FILE_STORAGE_ROOT_PATH = file_storage_root_path cfg.UPLOAD_DELETE_ALLOWED = False importer = Importer(cfg) importer.import_modules() ctx = Context(None, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): cfg = Config() cfg.ENABLE_ORIGINAL_PHOTO_UPLOAD = True cfg.ORIGINAL_PHOTO_STORAGE = 'thumbor.storages.file_storage' cfg.FILE_STORAGE_ROOT_PATH = storage_path cfg.ALLOW_ORIGINAL_PHOTO_DELETION = False importer = Importer(cfg) importer.import_modules() ctx = Context(None, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(table): cfg = Config(HBASE_STORAGE_TABLE=table, HBASE_STORAGE_SERVER_PORT=9090, STORAGE='thumbor_hbase.storage') importer = Importer(cfg) importer.import_modules() server = ServerParameters(8888, 'localhost', 'thumbor.conf', None, 'info', None) ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): self.config = ( # This is a test case pylint: disable=attribute-defined-outside-init self.get_config()) self.server = ( # This is a test case pylint: disable=attribute-defined-outside-init self.get_server()) self.importer = ( # This is a test case pylint: disable=attribute-defined-outside-init self.get_importer()) self.request_handler = ( # This is a test case pylint: disable=attribute-defined-outside-init self.get_request_handler()) self.importer.import_modules() self.context = self.get_context() return ThumborServiceApp(self.context)
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(prevent_result_storage=False, detection_error=False): cfg = Config.load(fixture_for('max_age_conf.py')) server_params = ServerParameters(None, None, None, None, None, None) cfg.DETECTORS = [] if prevent_result_storage: cfg.DETECTORS.append('fixtures.prevent_result_storage_detector') if detection_error: cfg.DETECTORS.append('fixtures.detection_error_detector') importer = Importer(cfg) importer.import_modules() ctx = Context(server_params, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = 'thumbor.loaders.file_loader' cfg.FILE_LOADER_ROOT_PATH = storage_path cfg.OPTIMIZERS = [ 'thumbor_plugins.optimizers.jp2', ] importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) self.engine = PILEngine(ctx) return application
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC', LOADER='thumbor.loaders.file_loader', RESULT_STORAGE='thumbor.result_storages.file_storage', RESULT_STORAGE_STORES_UNSAFE=True, RESULT_STORAGE_EXPIRATION_SECONDS=2592000, FILE_LOADER_ROOT_PATH=storage_path, OPTIMIZERS=['thumbor.optimizers.jpegtran']) importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): self.default_filename = 'image' cfg = Config() cfg.UPLOAD_ENABLED = True cfg.UPLOAD_PUT_ALLOWED = True cfg.UPLOAD_PHOTO_STORAGE = 'thumbor.storages.file_storage' cfg.FILE_STORAGE_ROOT_PATH = file_storage_root_path cfg.UPLOAD_DEFAULT_FILENAME = self.default_filename cfg.MIN_WIDTH = 40 cfg.MIN_HEIGHT = 40 cfg.UPLOAD_MAX_SIZE = 72000 importer = Importer(cfg) importer.import_modules() ctx = Context(None, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): file_storage_root_path = '/tmp/thumbor-vows/storage' if exists(file_storage_root_path): rmtree(file_storage_root_path) cfg = Config() cfg.USE_BLACKLIST = True cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = abspath(join(dirname(__file__), 'fixtures/')) cfg.STORAGE = 'thumbor.storages.file_storage' cfg.FILE_STORAGE_ROOT_PATH = file_storage_root_path importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'debug', None) ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) return application
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path cfg.AUTO_WEBP = True cfg.USE_GIFSICLE_ENGINE = True importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' ctx = Context(server, cfg, importer) ctx.server.gifsicle_path = which('gifsicle') application = ThumborServiceApp(ctx) self.engine = PILEngine(ctx) return application
def get_app(self): cfg = Config( SECURITY_KEY='ACME-SEC', LOADER='thumbor.loaders.file_loader', RESULT_STORAGE_STORES_UNSAFE=False, RESULT_STORAGE_EXPIRATION_SECONDS=2592000, FILE_LOADER_ROOT_PATH=storage_path, OPTIMIZERS=[], USE_GIFSICLE_ENGINE=True, ) importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' server.gifsicle_path = which('gifsicle') ctx = Context(server, cfg, importer) application = ThumborServiceApp(ctx) return application
def main(): '''Converts a given url with the specified arguments.''' parser = optparse.OptionParser(usage='thumbor-url [options] imageurl or type thumbor-url -h (--help) for help', description=__doc__, version=__version__) parser.add_option('-k', '--key', dest='key', default=None, help = 'The security key to encrypt the url with [default: %default].' ) parser.add_option('-w', '--width', dest='width', type='int', default=0, help = 'The target width for the image [default: %default].' ) parser.add_option('-e', '--height', dest='height', type='int', default=0, help = 'The target height for the image [default: %default].' ) parser.add_option('-s', '--smart', action='store_true', dest='smart', default=False, help = 'Indicates that smart cropping should be used.' ) parser.add_option('-f', '--horizontal-flip', action='store_true', dest='horizontal_flip', default=False, help = 'Indicates that the image should be horizontally flipped.' ) parser.add_option('-v', '--vertical-flip', action='store_true', dest='vertical_flip', default=False, help = 'Indicates that the image should be vertically flipped.') parser.add_option('-a', '--halign', dest='halign', default='center', help = 'The horizontal alignment to use for cropping [default: %default].' ) parser.add_option('-i', '--valign', dest='valign', default='middle', help = 'The vertical alignment to use for cropping [default: %default].' ) parser.add_option('-c', '--crop', dest='crop', default=None, help = 'The coordinates of the points to manual cropping in the format leftxtop:rightxbottom (100x200:400x500) [default: %default].' ) (parsed_options, arguments) = parser.parse_args() if not arguments: print 'Error: The image argument is mandatory. For more information type thumbor-url -h' return image_url = arguments[0] if image_url.startswith('/'): image_url = image_url[1:] conf_file = ThumborServiceApp.get_conf_file('') if conf_file: print print "USING CONFIGURATION FILE AT %s" % conf_file print parse_config_file(conf_file) if not parsed_options.key and not conf_file: print 'Error: The -k or --key argument is mandatory. For more information type thumbor-url -h' return security_key = options.SECURITY_KEY if not parsed_options.key else parsed_options.key crypt = Crypto(security_key) crop_left = crop_top = crop_right = crop_bottom = 0 if parsed_options.crop: crops = parsed_options.crop.split(':') crop_left, crop_top = crops[0].split('x') crop_right, crop_bottom = crops[1].split('x') opt = crypt.encrypt(parsed_options.width, parsed_options.height, parsed_options.smart, parsed_options.horizontal_flip, parsed_options.vertical_flip, parsed_options.halign, parsed_options.valign, crop_left, crop_top, crop_right, crop_bottom, image_url) url = '/%s/%s' % (opt, image_url) print 'Encrypted URL: "%s" (without quotes)' % url
def get_app(self): app = ThumborServiceApp(get_conf_path('default.py')) return app
def get_app(self): return ThumborServiceApp(get_conf_path('jsonp.py'))