def __init__(self, server=None, config=None, importer=None, request_handler=None): ''' Class responsible for containing: * Server Configuration Parameters (port, ip, key, etc); * Configurations read from config file (or defaults); * Importer with imported modules (engine, filters, detectors, etc); * Request Parameters (width, height, smart, meta, etc). Each instance of this class MUST be unique per request. This class should not be cached in the server. :param server: :param config: :param importer: :param request_handler: ''' ThumborContext.__init__( self, server=server, config=config, importer=None, # Always load our ContextImporter request_handler=request_handler ) # Load our ContextImporter if importer: self.modules = ContextImporter(self, importer) self.filters_factory = FiltersFactory(self.modules.filters) if importer.metrics: self.metrics = importer.metrics(config) else: self.metrics = Metrics(config)
def to_context(self): self.engine = MockEngine((self.source_width, self.source_height)) flip_horizontally = self.target_width < 0 flip_vertically = self.target_height < 0 self.target_width = self.target_width == "orig" and "orig" or abs(self.target_width) self.target_height = self.target_height == "orig" and "orig" or abs(self.target_height) importer = Importer(None) ctx = Context(server=None, config=Config(), importer=importer) ctx.modules.engine = self.engine ctx.request = RequestParameters( buffer=None, debug=False, meta=False, crop={"left": self.crop_left, "top": self.crop_top, "right": self.crop_right, "bottom": self.crop_bottom}, adaptive=self.adaptive, fit_in=self.fit_in, horizontal_flip=flip_horizontally, vertical_flip=flip_vertically, width=self.target_width, height=self.target_height, halign=self.halign, valign=self.valign, focal_points=self.focal_points, smart=True, extension="JPEG", filters=[], quality=80, image="some.jpeg", ) return ctx
def get_context(self): cfg = self.get_config() ctx = Context(None, cfg, None) ctx.request = self.get_request() self.context = ctx self.file_storage = FileStorage(self.context) return ctx
def topic(self): config = Config( AUTO_WEBP=False, RESULT_STORAGE_FILE_STORAGE_ROOT_PATH="/tmp/thumbor/result_storages%s" % (random.choice(['', '/']))) context = Context(config=config) context.request = RequestParameters(accepts_webp=False) return FileStorage(context)
def get_context(self): conf = Config() conf.STATSD_HOST = '' ctx = Context(config=conf) ctx.request = RequestParameters() return ctx
def topic(self): config = Config() context = Context(None, config, Importer(config)) context.request = RequestParameters() engine = MockInvalidResultEngine(context=context) return engine.read()
def get_filter(self, filter_name, params_string="", config_context=None): config = Config( FILTERS=[filter_name], LOADER='thumbor.loaders.file_loader', FILE_LOADER_ROOT_PATH=join(dirname(realpath(__file__)), 'fixtures', 'filters') ) importer = Importer(config) importer.import_modules() req = RequestParameters() context = Context(config=config, importer=importer) context.request = req context.request.engine = context.modules.engine if config_context is not None: config_context(context) self.context = context fltr = importer.filters[0] fltr.pre_compile() context.transformer = Transformer(context) return fltr(params_string, context=context)
def get_context(self): conf = Config() conf.STATSD_HOST = '' ctx = Context(config=conf) ctx.request = RequestParameters() ctx.request.filters.append('auto') return ctx
def get_context(self): conf = Config() conf.STATSD_HOST = '' conf.FFMPEG_PATH = which('ffmpeg') ctx = Context(config=conf) ctx.request = RequestParameters() ctx.request.filters.append('gifv') return ctx
def topic(self): conf = Config() imp = Importer(conf) imp.filters = [Filter] ctx = Context(None, conf, imp) ctx.request = RequestParameters() filter_instances = ctx.filters_factory.create_instances(ctx, "format(invalid)") filter_instances[0].run()
def topic(self): conf = Config() imp = Importer(conf) imp.filters = [Filter] ctx = Context(None, conf, imp) ctx.request = RequestParameters() runner = ctx.filters_factory.create_instances(ctx, "format(invalid)") filter_instances = runner.filter_instances[thumbor.filters.PHASE_POST_TRANSFORM] filter_instances[0].run()
def get_optimizer(self, filters=None, progressive=False): conf = Config() conf.STATSD_HOST = '' conf.JPEGTRAN_PATH = '/somewhere/jpegtran' conf.PROGRESSIVE_JPEG = progressive req = RequestParameters(filters=filters) ctx = Context(config=conf) ctx.request = req optimizer = Optimizer(ctx) return optimizer
def topic(self): conf = Config() req = RequestParameters(quality=100) ctx = Context(None, conf, None) ctx.request = req filters = [Filter] compile_filters(filters) filter_instances = create_instances(ctx, filters, "quality(10)") filter_instances[0].run_filter() return ctx.request.quality
def topic(self, callback): self.conn = S3Connection() self.conn.create_bucket(s3_bucket) config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket) ctx = Context(config=config, server=get_server('ACME-SEC')) ctx.request = Request ctx.request.url = 'my-image.jpg' storage = Storage(ctx) storage.put(IMAGE_BYTES, callback=callback)
def topic(self): self.conn = S3Connection() self.conn.create_bucket(s3_bucket) config = Config(RESULT_STORAGE_BUCKET=s3_bucket) ctx = Context(config=config, server=get_server('ACME-SEC')) ctx.request = Request ctx.request.url = 'my-image.jpg' storage = Storage(ctx) path = storage.put(IMAGE_BYTES) return path
def topic(self): conf = Config() imp = Importer(conf) imp.filters = [Filter] ctx = Context(None, conf, imp) ctx.request = RequestParameters() runner = ctx.filters_factory.create_instances(ctx, "rotate(540)") filter_instances = runner.filter_instances[thumbor.filters.PHASE_POST_TRANSFORM] filter_instances[0].engine = RotateEngine() filter_instances[0].run() return filter_instances[0].engine.rotate_val
def topic(self, callback): self.conn = S3Connection() self.conn.create_bucket(s3_bucket) config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket, TC_AWS_STORE_METADATA=True) ctx = Context(config=config, server=get_server('ACME-SEC')) ctx.headers = {'Content-Type': 'image/webp', 'Some-Other-Header': 'doge-header'} ctx.request = Request ctx.request.url = 'my-image-meta.jpg' storage = Storage(ctx) storage.put(IMAGE_BYTES) file_abspath = storage._normalize_path(ctx.request.url) storage.storage.get(file_abspath, callback=callback)
def topic(self): self.conn = S3Connection() self.conn.create_bucket(s3_bucket) config = Config(RESULT_STORAGE_BUCKET=s3_bucket, RESULT_STORAGE_S3_STORE_METADATA=True) ctx = Context(config=config, server=get_server('ACME-SEC')) ctx.request_handler = RequestHandler() ctx.request = Request ctx.request.url = 'my-image-meta.jpg' storage = Storage(ctx) storage.put(IMAGE_BYTES) file_abspath = storage.normalize_path(ctx.request.url) file_key = storage.storage.get_key(file_abspath) return file_key.content_type, file_key.metadata, file_key.read()
def to_context(self, detectors=[], ignore_detector_error=False): self.engine = MockEngine((self.source_width, self.source_height)) flip_horizontally = self.target_width < 0 flip_vertically = self.target_height < 0 self.target_width = self.target_width == "orig" and "orig" or abs(self.target_width) self.target_height = self.target_height == "orig" and "orig" or abs(self.target_height) importer = Importer(None) importer.detectors = detectors importer.storage = NoStorage config = Config() config.IGNORE_SMART_ERRORS = ignore_detector_error ctx = Context(server=None, config=config, importer=importer) ctx.modules.engine = self.engine ctx.request = RequestParameters( buffer=None, debug=False, meta=self.meta, crop={ 'left': self.crop_left, 'top': self.crop_top, 'right': self.crop_right, 'bottom': self.crop_bottom }, adaptive=self.adaptive, full=self.full, fit_in=self.fit_in, horizontal_flip=flip_horizontally, vertical_flip=flip_vertically, width=self.target_width, height=self.target_height, halign=self.halign, valign=self.valign, focal_points=self.focal_points, smart=True, extension="JPEG", filters=[], quality=80, image="some.jpeg" ) ctx.request.engine = self.engine ctx.request.engine.extension = ".jpeg" return ctx
def topic(self): conf = Config() conf.ENGINE = 'thumbor.engines.pil' imp = Importer(conf) imp.import_modules() imp.filters = [Filter] ctx = Context(None, conf, imp) for item in DATA: ctx.modules.engine.image = ctx.modules.engine.gen_image(item[1],'#fff') req = RequestParameters(fit_in=True,width=item[0][0],height=item[0][1]) ctx.request = req filter_instances = ctx.filters_factory.create_instances(ctx, "fill(blue)") filter_instances[0].run() yield (filter_instances[0].engine.image.size,item[2])
def get_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage' cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60 cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path cfg.AUTO_WEBP = 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.request = self.get_request() ctx.server.gifsicle_path = which('gifsicle') return ctx
def topic(self): config = Config() server = ServerParameters( 8889, 'localhost', 'thumbor.conf', None, 'info', None ) context = Context(server, config, Importer(config)) context.server.gifsicle_path = which('gifsicle') context.request = RequestParameters() with open("%s/animated_image.gif" % FIXTURES_FOLDER, "rb") as f: buffer = f.read() engine = GifEngine(context=context) engine.load(buffer, '.gif') return engine.read()
def get_filter(self, filter_name, params_string="", config_context=None): config = Config( FILTERS=[filter_name], ) importer = Importer(config) importer.import_modules() req = RequestParameters() context = Context(config=config, importer=importer) context.request = req context.request.engine = context.modules.engine if config_context is not None: config_context(context) fltr = importer.filters[0] fltr.pre_compile() context.transformer = Transformer(context) return fltr(params_string, context=context)
def test_can_create_context(self): ctx = Context() expect(ctx.server).to_be_null() expect(ctx.config).to_be_null() expect(ctx.modules).to_be_null() expect(ctx.metrics).not_to_be_null() expect(ctx.metrics).to_be_instance_of(Metrics) expect(ctx.filters_factory).to_be_instance_of(FiltersFactory) expect(ctx.filters_factory.filter_classes_map).to_be_empty() expect(ctx.request_handler).to_be_null() expect(ctx.thread_pool).to_be_instance_of(ThreadPool) expect(ctx.headers).to_be_instance_of(dict) expect(ctx.headers).to_be_empty()
def test_load_with_some_excluded_headers(self): url = self.get_url('/') config = Config() handler_mock_options = { "Accept-Encoding": "gzip", "User-Agent": "Thumbor", "Host": "localhost", "Accept": "*/*", "X-Server": "thumbor" } ctx = Context(None, config, None, HandlerMock(handler_mock_options)) loader.load(ctx, url, self.stop) result = self.wait() expect(result).to_be_instance_of(LoaderResult) expect(result.buffer).Not.to_include("X-Server:thumbor")
def get_context(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 = self.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() return Context(None, cfg, importer)
def topic(self): config = Config() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) config.PILLOW_JPEG_SUBSAMPLING = 2 config.PILLOW_JPEG_QTABLES = 'web_high' context = Context(server, config, Importer(config)) with open("%s/quantization.jpg" % FIXTURES_FOLDER, "rb") as f: buffer = f.read() engine = PIL.Engine(context=context) engine.load(buffer, '.jpg') engine.read('.jpg', None) return engine.image
def get_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.STORAGE = "thumbor.storages.no_storage" 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') return ctx
def test_can_load_image(self): client = botocore.session.get_session().create_client('s3') client.create_bucket(Bucket=s3_bucket) client.put_object( Bucket=s3_bucket, Key=''.join(['root_path', IMAGE_PATH]), Body=IMAGE_BYTES, ContentType='image/jpeg', ) conf = Config(TC_AWS_LOADER_BUCKET=s3_bucket, TC_AWS_LOADER_ROOT_PATH='root_path') image = yield s3_loader.load(Context(config=conf), IMAGE_PATH) self.assertEqual(image, IMAGE_BYTES)
def get_app(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path cfg.ALLOW_UNSAFE_URL = False cfg.ALLOW_OLD_URLS = True importer = Importer(cfg) importer.import_modules() server = ServerParameters(8890, '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_context(self): self.default_filename = "image" cfg = Config() cfg.UPLOAD_ENABLED = True cfg.UPLOAD_PHOTO_STORAGE = "thumbor.storages.file_storage" cfg.FILE_STORAGE_ROOT_PATH = self.root_path cfg.UPLOAD_DELETE_ALLOWED = False cfg.UPLOAD_PUT_ALLOWED = True cfg.UPLOAD_DEFAULT_FILENAME = self.default_filename cfg.MAX_ID_LENGTH = 36 importer = Importer(cfg) importer.import_modules() return Context(None, cfg, importer)
def main(arguments=None): '''Runs thumbor server with the specified arguments.''' server_parameters = get_server_parameters(arguments) lookup_paths = [os.curdir, expanduser('~'), '/etc/', dirname(__file__)] config = Config.load(server_parameters.config_path, conf_name='thumbor.conf', lookup_paths=lookup_paths) logging.basicConfig(level=getattr(logging, server_parameters.log_level.upper()), format=config.THUMBOR_LOG_FORMAT, datefmt=config.THUMBOR_LOG_DATE_FORMAT) importer = Importer(config) importer.import_modules() if importer.error_handler_class is not None: importer.error_handler = importer.error_handler_class(config) if server_parameters.security_key is None: server_parameters.security_key = config.SECURITY_KEY if not isinstance(server_parameters.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 = importer.import_class(server_parameters.app_class)(context) server = HTTPServer(application) server.bind(context.server.port, context.server.ip) server.start(1) try: logging.debug('thumbor running at %s:%d' % (context.server.ip, context.server.port)) tornado.ioloop.IOLoop.instance().start() except KeyboardInterrupt: print print "-- thumbor closed by user interruption --"
def get_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.JPEGTRAN_PATH = which('jpegtran') cfg.PROGRESSIVE_JPEG = True, cfg.RESULT_STORAGE_STORES_UNSAFE = True, cfg.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) return ctx
def test_load_with_all_headers(self): url = self.get_url('/') config = Config() config.HTTP_LOADER_FORWARD_ALL_HEADERS = True handler_mock_options = { "X-Test": "123", "DNT": "1", "X-Server": "thumbor" } ctx = Context(None, config, None, HandlerMock(handler_mock_options)) loader.load(ctx, url, self.stop) result = self.wait() expect(result).to_be_instance_of(LoaderResult) expect(result.buffer.decode()).to_include("Dnt:1\n") expect(result.buffer.decode()).to_include("X-Server:thumbor\n") expect(result.buffer.decode()).to_include("X-Test:123\n")
def get_context(self): cfg = Config(SECURITY_KEY='MYKEY') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.ALLOW_UNSAFE_URL = False cfg.ALLOW_OLD_URLS = True cfg.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True cfg.STORAGE = 'thumbor.storages.file_storage' cfg.STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path importer = Importer(cfg) importer.import_modules() server = ServerParameters(8891, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'MYKEY' return Context(server, cfg, importer)
def topic(self, callback): self.conn = S3Connection() self.conn.create_bucket(s3_bucket) config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket) storage = Storage(Context(config=config, server=get_server('ACME-SEC'))) storage.put(IMAGE_URL % '4', IMAGE_BYTES) # 1: we put the image def check_created(created): expect(created).to_equal(True) # 2.1: assertion... def once_removed(rm): storage.exists(IMAGE_URL % '4', callback=callback) #4: we check if the image exists storage.remove(IMAGE_URL % '4', callback=once_removed) # 3: we delete it storage.exists(IMAGE_URL % '4', callback=check_created) # 2: we check it exists
def get_app(self): self.default_filename = 'image' 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 = True cfg.UPLOAD_PUT_ALLOWED = False cfg.UPLOAD_DEFAULT_FILENAME = self.default_filename importer = Importer(cfg) importer.import_modules() ctx = Context(None, cfg, importer) application = ThumborServiceApp(ctx) return application
def topic(self): config = Config(FILE_STORAGE_ROOT_PATH="/tmp/thumbor/file_storage/") root_path = join(config.FILE_STORAGE_ROOT_PATH, dirname(SAME_IMAGE_URL % 999)) if exists(root_path): shutil.rmtree(root_path) old_exists = Storage.storages.exists Storage.storages.exists = lambda path: False try: storage = Storage.Storage(Context(config=config, server=get_server('ACME-SEC'))) storage.put(SAME_IMAGE_URL % 998, IMAGE_BYTES) storage.put(SAME_IMAGE_URL % 999, IMAGE_BYTES) finally: Storage.storages.exists = old_exists return storage.get(SAME_IMAGE_URL % 999)
def test_can_server_app_class_override_config(): server = ServerParameters( port=8888, ip="0.0.0.0", config_path="/my/config_path.conf", keyfile="./tests/fixtures/thumbor.key", log_level="debug", app_class="server.app", ) cfg = Config( APP_CLASS="config.app", ) importer = Importer(cfg) ctx = Context(config=cfg, importer=importer, server=server) expect(ctx.app_class).to_equal("server.app")
def get_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.FFMPEG_PATH = which('ffmpeg') 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') return ctx
def test_load_with_empty_accept(self): url = self.get_url('/') config = Config() handler_mock_options = { "Accept-Encoding": "gzip", "User-Agent": "Thumbor", "Host": "localhost", "Accept": "", "X-Server": "thumbor" } ctx = Context(None, config, None, HandlerMock(handler_mock_options)) loader.load(ctx, url, self.stop) result = self.wait() expect(result).to_be_instance_of(LoaderResult) expect(result.buffer.decode()).to_include( "Accept:image/*;q=0.9,*/*;q=0.1\n")
def get_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage' cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60 cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path cfg.SEND_IF_MODIFIED_LAST_MODIFIED_HEADERS = True importer = Importer(cfg) importer.import_modules() server = ServerParameters(8889, 'localhost', 'thumbor.conf', None, 'info', None) server.security_key = 'ACME-SEC' return Context(server, cfg, importer)
def get_context(self): cfg = Config(SECURITY_KEY="ACME-SEC") cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.STORAGE = "thumbor.storages.no_storage" cfg.AUTO_WEBP = True cfg.USE_GIFSICLE_ENGINE = True cfg.RESPECT_ORIENTATION = 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") return ctx
def test_can_server_app_class_override_config(self): server = ServerParameters( port=8888, ip='0.0.0.0', config_path='/tmp/config_path.conf', keyfile='./tests/fixtures/thumbor.key', log_level='debug', app_class='server.app', ) cfg = Config( APP_CLASS='config.app', ) importer = Importer(cfg) ctx = Context(config=cfg, importer=importer, server=server) expect(ctx.app_class).to_equal('server.app')
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): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path cfg.STORAGE = "thumbor.storages.file_storage" cfg.FILE_STORAGE_ROOT_PATH = FILE_STORAGE_ROOT_PATH if exists(FILE_STORAGE_ROOT_PATH): rmtree(FILE_STORAGE_ROOT_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(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = storage_path cfg.AUTO_WEBP = 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') 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_context(self): cfg = Config(SECURITY_KEY="ACME-SEC") cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.FFMPEG_PATH = which("ffmpeg") 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") return ctx
def get_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = '/tmp/path/that/does/not/exist' cfg.RESULT_STORAGE = 'thumbor.result_storages.file_storage' cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60 cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path cfg.AUTO_WEBP = 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) return ctx
def get_context(self): cfg = Config(SECURITY_KEY="ACME-SEC") cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.JPEGTRAN_PATH = which("jpegtran") cfg.PROGRESSIVE_JPEG = (True,) cfg.RESULT_STORAGE_STORES_UNSAFE = (True,) cfg.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) return ctx
def get_context(self): cfg = Config(SECURITY_KEY="ACME-SEC") cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path cfg.RESULT_STORAGE = "thumbor.result_storages.file_storage" cfg.RESULT_STORAGE_EXPIRATION_SECONDS = 60 cfg.RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = self.root_path cfg.AUTO_WEBP = 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) return ctx
def get_context(self): cfg = Config() ctx = Context(None, cfg, None) ctx.request = RequestParameters(url='image.jpg') self.context = ctx return ctx
def topic(self): config = Config() context = Context(config=config) context.request = RequestParameters(url="image.jpg") fs = NoStorage(context) return fs.put(100)
def topic(self, callback): config = Config(RESULT_STORAGE_FILE_STORAGE_ROOT_PATH=STORAGE_PATH) context = Context(config=config) context.request = RequestParameters(url='image.jpg') fs = FileStorage(context) fs.get(callback=callback)
def topic(self, callback): config = Config() context = Context(config=config) context.request = RequestParameters(url="image.jpg") fs = NoStorage(context) fs.get(callback=callback)
def topic(self): config = Config(AUTO_WEBP=False) context = Context(config=config) context.request = RequestParameters(accepts_webp=True) return Storage(context)