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.FFMPEG_PATH = which('ffmpeg') 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') return ctx
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', open(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_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_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): 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 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) if context.server.fd is not None: fd_number = get_as_integer(context.server.fd) if fd_number is None: with open(context.server.fd, 'r') as sock: fd_number = sock.fileno() sock = socket.fromfd(fd_number, socket.AF_INET | socket.AF_INET6, socket.SOCK_STREAM) server.add_socket(sock) else: 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 topic(self): importer = Importer(None) importer.import_item( config_key='detectors', item_value=('thumbor.detectors.feature_detector', 'thumbor.detectors.feature_detector'), is_multiple=True) return importer.detectors
def topic(self, test_item): test_data, config = test_item importer = Importer(config) importer.import_modules() if hasattr(importer, test_data[0].lower()): return (getattr(importer, test_data[0].lower()), test_data[1]) return (None, None)
def get_importer(config): importer = Importer(config) importer.import_modules() if importer.error_handler_class is not None: importer.error_handler = importer.error_handler_class(config) return importer
def setUp(self, *args, **kwargs): super(FakeRotateEngineRotateFilterTestCase, self).setUp(*args, **kwargs) conf = Config() imp = Importer(conf) imp.filters = [Filter] self.context = Context(None, conf, imp) self.context.request = RequestParameters()
def test_can_create_context_with_importer(self): cfg = Config() importer = Importer(cfg) importer.import_modules() ctx = Context(config=cfg, importer=importer) expect(ctx.modules).not_to_be_null() expect(ctx.modules.importer).to_equal(importer)
def test_single_item_should_equal_file_storage(): importer = Importer(None) importer.import_item( config_key="file_storage", item_value="thumbor.storages.file_storage", class_name="Storage", ) expect(getattr(importer, "file_storage")).to_equal(file_storage)
def get_importer(config): importer = Importer(config) importer.import_modules() if importer.error_handler_class is not None: importer.error_handler = importer.error_handler_class(config) # pylint: disable=not-callable return importer
def get_context(self): cfg = Config() cfg.HEALTHCHECK_ROUTE = '/' importer = Importer(cfg) importer.import_modules() return Context(None, cfg, importer)
def test_single_item_should_equal_file_storage(self): importer = Importer(None) importer.import_item( config_key='file_storage', item_value='thumbor.storages.file_storage', class_name='Storage' ) expect(importer.file_storage).to_equal(file_storage)
def get_context(self): config = Config( FILE_LOADER_ROOT_PATH=STORAGE_PATH, COMPATIBILITY_LEGACY_LOADER= "tests.compatibility.legacy_file_loader", ) importer = Importer(config) importer.import_modules() return Context(config=config, importer=importer)
def setUp(self): self.config = Config() self.config.METRICS = 'tc_prometheus.metrics.prometheus_metrics' self.config.PROMETHEUS_SCRAPE_PORT = '8001' self.importer = Importer(self.config) self.importer.import_modules() self.context = Context(None, self.config, self.importer)
def topic(self): conf = Config() conf.METRICS = 'tc_librato.metrics.librato_metrics' conf.LIBRATO_USER = '******' conf.LIBRATO_TOKEN = 'test' conf.LIBRATO_NAME_PREFIX = 'test' imp = Importer(conf) imp.import_modules() return Context(None, conf, imp)
def test_can_create_context_without_importer_metrics(self): cfg = Config( METRICS='', ) importer = Importer(cfg) ctx = Context(config=cfg, importer=importer) expect(ctx.modules).not_to_be_null() expect(ctx.modules.importer).to_equal(importer)
def test_multiple_items_can_be_imported(self): importer = Importer(None) importer.import_item(config_key='detectors', is_multiple=True, item_value=('thumbor.detectors.feature_detector', 'thumbor.detectors.feature_detector')) expect(importer.detectors).to_length(2) expect(importer.detectors).to_include(feature_detector)
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_context(self): cfg = Config(SECURITY_KEY='ACME-SEC') cfg.LOADER = "thumbor.loaders.file_loader" cfg.FILE_LOADER_ROOT_PATH = self.loader_path 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): def is_multiple(): return False cfg = Config() importer = Importer(cfg) importer.import_modules() context = Context(config=cfg, importer=importer) context.modules.engine.is_multiple = is_multiple return context
def to_context(self, detectors=None, ignore_detector_error=False): if detectors is None: detectors = [] ThreadPool.reset() self.engine = MockEngine((self.source_width, self.source_height)) flip_horizontally = flip_vertically = False if self.target_width != "orig": flip_horizontally = self.target_width < 0 self.target_width = abs(self.target_width) if self.target_height != "orig": flip_vertically = self.target_height < 0 self.target_height = 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", stretch=self.stretch, ) ctx.request.engine = self.engine ctx.request.engine.extension = ".jpeg" return ctx
def get_app(self): server_params = ServerParameters(None, None, None, None, None, None) cfg = self.get_config() importer = Importer(cfg) importer.import_modules() self.ctx = Context(server_params, cfg, importer) application = App(self.ctx) return application
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): config = Config() importer = Importer(config) config.__setitem__('COMMUNITY_EXTENSIONS', ['tc_core']) ext = Extension('tc_core') ext.add_handler('/my_handler', ImagingHandler) Extensions.register(ext) context = Context(None, config, importer) return App(context)
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_context(self): cfg = Config(SECURITY_KEY="ACME-SEC") cfg.LOADER = "thumbor.loaders.http_loader" cfg.STORAGE = "thumbor.storages.file_storage" cfg.FILE_STORAGE_ROOT_PATH = self.root_path 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(server=None, config=None, importer=None): if not server: server = get_server() if not config: config = Config() if not importer: importer = Importer(config) ctx = Context(server=server, config=config, importer=importer) return ctx