Example #1
0
    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
Example #2
0
 def topic(self):
     conf = Config()
     conf.ENGINE = 'thumbor.engines.pil'
     imp = Importer(conf)
     imp.import_modules()
     imp.filters = [Filter]
     return Context(None, conf, imp)
Example #3
0
    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
Example #4
0
    def get_context(self):
        cfg = Config(SECURITY_KEY="ACME-SEC", ENGINE="thumbor.engines.pil", IMAGE_METADATA_READ_FORMATS="exif,xmp")
        cfg.LOADER = "thumbor.loaders.file_loader"
        cfg.FILE_LOADER_ROOT_PATH = STORAGE_PATH
        cfg.STORAGE = "thumbor.storages.no_storage"

        return Context(config=cfg)
Example #5
0
 def get_config(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
     return cfg
Example #6
0
 def test_with_aliased_aliases(self):
     Config.alias('STORAGE_ALIAS', 'STORAGE')
     Config.alias('STORAGE_ALIAS_ALIAS', 'STORAGE_ALIAS')
     cfg = Config(STORAGE_ALIAS_ALIAS='z')
     expect(cfg.STORAGE).to_equal('z')
     expect(cfg.STORAGE_ALIAS).to_equal('z')
     expect(cfg.STORAGE_ALIAS_ALIAS).to_equal('z')
def get_context():
    conf = Config()
    conf.ENGINE = "thumbor.engines.pil"
    imp = Importer(conf)
    imp.import_modules()
    imp.filters = [Filter]
    return Context(None, conf, imp)
Example #8
0
 def test_with_allowed_sources(self):
     config = Config()
     config.ALLOWED_SOURCES = [
         's.glbimg.com',
         re.compile(r'https://www\.google\.com/img/.*')
     ]
     ctx = Context(None, config, None)
     expect(
         loader.validate(
             ctx,
             'http://www.google.com/logo.jpg'
         )
     ).to_be_false()
     expect(
         loader.validate(
             ctx,
             'http://s2.glbimg.com/logo.jpg'
         )
     ).to_be_false()
     expect(
         loader.validate(
             ctx,
             '/glob=:sfoir%20%20%3Co-pmb%20%20%20%20_%20%20%20%200%20%20g.-%3E%3Ca%20hplass='
         )
     ).to_be_false()
     expect(
         loader.validate(
             ctx,
             'https://www.google.com/img/logo.jpg'
         )
     ).to_be_true()
     expect(
         loader.validate(ctx, 'http://s.glbimg.com/logo.jpg')).to_be_true()
Example #9
0
            def topic(self):
                conf = Config(MONGO_STORAGE_SERVER_PORT=7777, STORES_CRYPTO_KEY_FOR_EACH_IMAGE=False)
                server = get_server('')
                storage = MongoStorage(Context(config=conf, server=server))
                storage.put(IMAGE_URL % 13, IMAGE_BYTES)

                conf.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True
                storage.put_crypto(IMAGE_URL % 13)
Example #10
0
    def get_optimizer(self):
        conf = Config()
        conf.STATSD_HOST = ''
        conf.JPEGTRAN_PATH = which('jpegtran')
        ctx = Context(config=conf)
        optimizer = Optimizer(ctx)

        return optimizer
    def get_config(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')

        cfg.COMMUNITY_EXTENSIONS = [
            'wikimedia_thumbor.handler.healthcheck'
        ]

        return cfg
Example #12
0
    def get_context(self):
        cfg = Config(
            SECURITY_KEY='ACME-SEC',
            ENGINE='thumbor.engines',
        )
        cfg.STORAGE = 'thumbor.storages.no_storage'

        return Context(config=cfg)
Example #13
0
    def get_context(self):
        cfg = Config()
        cfg.HEALTHCHECK_ROUTE = '/'

        importer = Importer(cfg)
        importer.import_modules()

        return Context(None, cfg, importer)
Example #14
0
 def test_with_aliased_aliases_with_default_values(self):
     Config.alias('STORAGE_ALIAS', 'STORAGE')
     Config.alias('STORAGE_ALIAS_ALIAS', 'STORAGE_ALIAS')
     cfg = Config()
     expect(cfg.STORAGE).to_equal(self.get_default_storage())
     expect(cfg.STORAGE_ALIAS).to_equal(self.get_default_storage())
     expect(cfg.STORAGE_ALIAS_ALIAS).to_equal(self.get_default_storage())
     expect(cfg.__class__.__module__).to_equal('derpconf.config')
Example #15
0
        def topic(self, callback):
            url = self.get_url('/')
            loader.http_client = self._http_client

            config = Config()
            config.HTTP_LOADER_FORWARD_USER_AGENT = True
            ctx = Context(None, config, None, HandlerMock({"User-Agent": "test-user-agent"}))

            loader.load(ctx, url, callback)
Example #16
0
    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 test_without_allowed_sources(self):
        config = Config()
        config.ALLOWED_SOURCES = []
        ctx = Context(None, config, None)
        is_valid = loader.validate(ctx, 'https://www.google.com/logo.jpg')
        expect(is_valid).to_be_true()

        is_valid = loader.validate(ctx, 'http://www.google.com/logo.jpg')
        expect(is_valid).to_be_false()
Example #18
0
            def topic(self):
                url = self.get_url('/')
                loader.http_client = self._http_client

                config = Config()
                config.ALLOWED_SOURCES = ['s.glbimg.com']
                ctx = Context(None, config, None)

                return loader.load, ctx, url
Example #19
0
 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)
Example #20
0
def get_config(config_path, use_environment=False):
    if use_environment:
        Config.allow_environment_variables()

    lookup_paths = [os.curdir,
                    expanduser('~'),
                    '/etc/',
                    dirname(__file__)]

    return Config.load(config_path, conf_name='thumbor.conf', lookup_paths=lookup_paths)
Example #21
0
    def test_load_with_user_agent(self):
        url = self.get_url('/')
        config = Config()
        config.HTTP_LOADER_FORWARD_USER_AGENT = True
        ctx = Context(None, config, None, HandlerMock({"User-Agent": "test-user-agent"}))

        loader.load(ctx, url, self.stop)
        result = self.wait()
        expect(result).to_be_instance_of(LoaderResult)
        expect(result.buffer).to_equal('test-user-agent')
Example #22
0
        def topic(self, callback):
            url = self.get_url('/')
            loader.http_client = self._http_client

            config = Config()
            config.HTTP_LOADER_FORWARD_USER_AGENT = True
            config.HTTP_LOADER_DEFAULT_USER_AGENT = "DEFAULT_USER_AGENT"
            ctx = Context(None, config, None, HandlerMock({}))

            loader.load(ctx, url, callback)
Example #23
0
    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)
Example #24
0
 def test_with_allowed_sources(self):
     config = Config()
     config.ALLOWED_SOURCES = ["s.glbimg.com"]
     ctx = Context(None, config, None)
     expect(loader.validate(ctx, "http://www.google.com/logo.jpg")).to_be_false()
     expect(loader.validate(ctx, "http://s2.glbimg.com/logo.jpg")).to_be_false()
     expect(
         loader.validate(ctx, "/glob=:sfoir%20%20%3Co-pmb%20%20%20%20_%20%20%20%200%20%20g.-%3E%3Ca%20hplass=")
     ).to_be_false()
     expect(loader.validate(ctx, "http://s.glbimg.com/logo.jpg")).to_be_true()
Example #25
0
    def test_load_with_curl(self):
        url = self.get_url('/')
        config = Config()
        config.HTTP_LOADER_CURL_ASYNC_HTTP_CLIENT = True
        ctx = Context(None, config, None)

        loader.load(ctx, url, self.stop)
        result = self.wait()
        expect(result).to_be_instance_of(LoaderResult)
        expect(result.buffer).to_equal('Hello')
        expect(result.successful).to_be_true()
Example #26
0
        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)
Example #27
0
    def test_load_with_default_user_agent(self):
        url = self.get_url("/")
        config = Config()
        config.HTTP_LOADER_FORWARD_USER_AGENT = True
        config.HTTP_LOADER_DEFAULT_USER_AGENT = "DEFAULT_USER_AGENT"
        ctx = Context(None, config, None, HandlerMock({}))

        loader.load(ctx, url, self.stop)
        result = self.wait()
        expect(result).to_be_instance_of(LoaderResult)
        expect(result.buffer).to_equal("DEFAULT_USER_AGENT")
Example #28
0
    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.ENABLE_ETAGS = False

        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)
Example #29
0
            def topic(self):
                conf = Config(MONGO_STORAGE_SERVER_PORT=7777, STORES_CRYPTO_KEY_FOR_EACH_IMAGE=False)
                server = get_server('ACME-SEC')
                storage = MongoStorage(Context(config=conf, server=server))
                storage.put(IMAGE_URL % 11, IMAGE_BYTES)

                conf.STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True
                storage.put_crypto(IMAGE_URL % 11)

                item = storage.get_crypto(IMAGE_URL % 11)
                return item.result()
Example #30
0
    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
Example #31
0
    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.RESPECT_ORIENTATION = True

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(8889, 'localhost', 'thumbor.conf', None,
                                  'info', None)
        server.security_key = 'ACME-SEC'
        self.context = Context(server, cfg, importer)
        self.context.server.gifsicle_path = which('gifsicle')
        return self.context
Example #32
0
    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.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
Example #33
0
    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_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.MAX_PIXELS = 1000

        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_get_image_with_metadata(self):
        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)
        yield storage.put(IMAGE_BYTES)

        file_abspath = storage._normalize_path(ctx.request.url)
        topic = yield storage.get(file_abspath)

        self.assertIn('Some-Other-Header', topic.metadata['Metadata'])
        self.assertEqual(topic.metadata['Metadata']['Content-Type'],
                         'image/webp')
        self.assertEqual(topic.buffer, IMAGE_BYTES)
Example #36
0
    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
Example #37
0
        def topic(self):
            port = 8890
            # use temporary file to store logs
            tmp = tempfile.NamedTemporaryFile(prefix='thumborTest.%i.' % port)

            cfg = Config(
                SECURITY_KEY='ACME-SEC',
                ERROR_FILE_LOGGER=tmp.name.replace('thumborTest.%i.' % port, 'thumborTest.%i.'),
                ERROR_FILE_NAME_USE_CONTEXT='server.port'
            )
            server = ServerParameters(port, 'localhost', 'thumbor.conf', None, 'info', None)
            server.security_key = 'ACME-SEC'
            ctx = Context(server, cfg, None)

            handler = ErrorHandler(cfg)
            http_handler = FakeHandler()

            handler.handle_error(ctx, http_handler, RuntimeError("Test"))

            # return content of file
            return tmp.read()
Example #38
0
    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
Example #39
0
    async def test_should_raise_for_invalid_compatibility_storage(self):
        config = Config(
            FILE_LOADER_ROOT_PATH=STORAGE_PATH,
            STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True,
        )
        importer = Importer(config)
        importer.import_modules()
        server = ServerParameters(8889, "localhost", "thumbor.conf", None,
                                  "info", None)
        server.security_key = "ACME-SEC"
        ctx = Context(server, config=config, importer=importer)
        storage = Storage(ctx)

        with expect.error_to_happen(
                RuntimeError,
                message=(
                    "The 'COMPATIBILITY_LEGACY_STORAGE' configuration should "
                    "point to a valid storage when using compatibility storage."
                ),
        ):
            await storage.get("invalid-path")
Example #40
0
    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
Example #41
0
    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=self.meta,
                                        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
Example #42
0
        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
Example #43
0
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()))

    lookup_paths = [os.curdir, expanduser('~'), '/etc/', dirname(__file__)]

    config = Config.load(server_parameters.config_path,
                         conf_name='thumbor.conf',
                         lookup_paths=lookup_paths)
    importer = Importer(config)
    importer.import_modules()

    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 --"
Example #44
0
    def regex(cls, has_unsafe_or_hash=True, context=None):
        reg = ['/?']

        if has_unsafe_or_hash:
            if context:
                config = context.config
            else:
                config = Config.load(None)
            reg.append(cls.unsafe_or_hash % config.UNSAFE_URL_KEYWORD)
        reg.append(cls.debug)
        reg.append(cls.meta)
        reg.append(cls.trim)
        reg.append(cls.crop)
        reg.append(cls.fit_in)
        reg.append(cls.dimensions)
        reg.append(cls.halign)
        reg.append(cls.valign)
        reg.append(cls.smart)
        reg.append(cls.filters)
        reg.append(cls.image)

        return ''.join(reg)
Example #45
0
    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)

        fltr = importer.filters[0]
        fltr.pre_compile()

        context.transformer = Transformer(context)

        return fltr(params_string, context=context)
Example #46
0
    def test_can_create_context_importer(self):
        cfg = Config(RESULT_STORAGE='thumbor.result_storages.file_storage', )
        importer = Importer(cfg)
        importer.import_modules()
        ctx = Context(config=cfg, importer=importer)

        ctx_importer = ContextImporter(ctx, importer)
        expect(ctx_importer.context).to_equal(ctx)
        expect(ctx_importer.importer).to_equal(importer)
        expect(ctx_importer.engine).to_be_instance_of(importer.engine)
        expect(ctx_importer.gif_engine).to_be_instance_of(importer.gif_engine)

        expect(ctx_importer.storage).to_be_instance_of(importer.storage)
        expect(ctx_importer.result_storage).to_be_instance_of(
            importer.result_storage)
        expect(ctx_importer.upload_photo_storage).to_be_instance_of(
            importer.upload_photo_storage)

        expect(ctx_importer.loader).to_equal(importer.loader)
        expect(ctx_importer.detectors).to_equal(importer.detectors)
        expect(ctx_importer.filters).to_equal(importer.filters)
        expect(ctx_importer.optimizers).to_equal(importer.optimizers)
        expect(ctx_importer.url_signer).to_equal(importer.url_signer)
Example #47
0
    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_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
Example #49
0
    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_context(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        cfg.LOADER = "tests.stub_file_loader"
        cfg.STORAGE = "thumbor.storages.file_storage"
        cfg.FILE_STORAGE_ROOT_PATH = self.root_path
        cfg.QUALITY = 'keep'
        cfg.SVG_DPI = 200

        self.image = 'http://test.domain/image.jpg'
        self.quoted_image = quote(self.image, safe='')
        self.transform = '400x400/smart'
        self.signature = UrlSigner(security_key="ACME-SEC").signature(
            '%s/%s' % (self.transform, self.quoted_image))
        self.signed_prefix = "/%s/%s" % (self.signature, self.transform)
        self.full_image = "/%s/%s/%s" % (self.signature, self.transform,
                                         self.quoted_image)

        importer = Importer(cfg)
        importer.import_modules()
        server = ServerParameters(
            8889, 'localhost', 'thumbor.conf', None, 'info',
            'thumbor_flexible_validation.app.ThumborServiceProxy')
        server.security_key = 'ACME-SEC'
        return Context(server, cfg, importer)
Example #51
0
    def get_app(self):
        cfg = Config(SECURITY_KEY='ACME-SEC')
        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',
        ]
        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)
        if not cfg.ENGINE:
            return None

        importer = Importer(cfg)
        importer.import_modules()
        ctx = Context(server_params, cfg, importer)
        application = ThumborServiceApp(ctx)

        return application
Example #52
0
    if os.path.isfile(cachefile):
        os.unlink(cachefile)
        print "\tRemoved"
    else:
        print "\tNot in cache"


if (len(sys.argv) != 2):
    print 'Usage: ' + sys.argv[0] + ' url/file'
    exit(1)

server_parameters = get_server_parameters()
lookup_paths = ['/etc/']
config = Config.load(server_parameters.config_path,
                     conf_name='thumbor.conf',
                     lookup_paths=lookup_paths)
importer = None

context = Context(server=server_parameters, config=config, importer=importer)

storage = Storage(context)

if os.path.exists(sys.argv[1]):
    with open(sys.argv[1]) as f:
        for url in f:
            flush(url.rstrip())

else:
    flush(sys.argv[1])
Example #53
0
 def get_config(self):
     self.tmp = tempfile.NamedTemporaryFile(prefix='thumborTest.')
     return Config(SECURITY_KEY='ACME-SEC', ERROR_FILE_LOGGER=self.tmp.name)
Example #54
0
 def test_WhenInvalidConfigurationOfFileNameWithContext_should_be_error(
         self):
     cfg = Config(ERROR_FILE_NAME_USE_CONTEXT='server..port',
                  ERROR_FILE_LOGGER='toto')
     with expect.error_to_happen(RuntimeError):
         ErrorHandler(cfg)
Example #55
0
 def topic(self):
     cfg = Config()
     ErrorHandler(cfg)
Example #56
0
 def topic(self):
     config = Config(FILE_LOADER_ROOT_PATH=STORAGE_PATH)
     return Context(config=config)
Example #57
0
 def test_without_allowed_sources(self):
     config = Config()
     config.ALLOWED_SOURCES = []
     ctx = Context(None, config, None)
     is_valid = loader.validate(ctx, 'http://www.google.com/logo.jpg')
     expect(is_valid).to_be_true()
Example #58
0
def main(arguments=None):
    '''Converts a given url with the specified arguments.'''
    if arguments is None:
        arguments = sys.argv[1:]

    parser = optparse.OptionParser(usage='thumbor-url [options] imageurl or type thumbor-url -h (--help) for help', description=__doc__, version=__version__)

    parser.add_option('-l', '--key_file', dest='key_file', default=None, help='The file to read the security key from [default: %default].')
    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('-n', '--fitin', dest='fitin', action='store_true', default=False, help='Indicates that fit-in resizing should be performed.')
    parser.add_option('-m', '--meta', dest='meta', action='store_true', default=False, help='Indicates that meta information should be retrieved.')
    parser.add_option('', '--adaptive', action='store_true', dest='adaptive', default=False, help='Indicates that adaptive fit-in cropping should be used.')
    parser.add_option('', '--full', action='store_true', dest='full', default=False, help='Indicates that fit-full cropping should be used.')
    parser.add_option('-s', '--smart', action='store_true', dest='smart', default=False, help='Indicates that smart cropping should be used.')
    parser.add_option('-t', '--trim', action='store_true', default=False, help='Indicate that surrounding whitespace should be trimmed.')
    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('', '--filters', dest='filters', default='', help='Filters to be applied to the image, e.g. brightness(10) [default: %default].')
    parser.add_option('-o', '--old-format', dest='old', action='store_true', default=False, help='Indicates that thumbor should generate old-format urls [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(arguments)

    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:]

    try:
        config = Config.load(None)
    except:
        config = None

    if not parsed_options.key and not config:
        print 'Error: The -k or --key argument is mandatory. For more information type thumbor-url -h'
        return

    if parsed_options.key_file:
        f = open(parsed_options.key_file)
        security_key = f.read().strip()
        f.close()
    else:
        security_key = config.SECURITY_KEY if not parsed_options.key else parsed_options.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')

    crypto = CryptoURL(key=security_key)
    url = crypto.generate(
        old=parsed_options.old,
        width=parsed_options.width,
        height=parsed_options.height,
        smart=parsed_options.smart,
        meta=parsed_options.meta,
        adaptive=parsed_options.adaptive,
        full=parsed_options.full,
        fit_in=parsed_options.fitin,
        horizontal_flip=parsed_options.horizontal_flip,
        vertical_flip=parsed_options.vertical_flip,
        halign=parsed_options.halign,
        valign=parsed_options.valign,
        trim=parsed_options.trim,
        crop_left=crop_left,
        crop_top=crop_top,
        crop_right=crop_right,
        crop_bottom=crop_bottom,
        filters=parsed_options.filters,
        image_url=image_url,
    )
    print 'URL:'

    print url
    return url
Example #59
0
 def topic(self):
     conf = Config()
     conf.METRICS = 'thumbor.metrics.statsd_metrics'
     imp = Importer(conf)
     imp.import_modules()
     return Context(None, conf, imp)
Example #60
0
            'size': total_bytes,
            # 'updated_at': datetime.datetime.utcnow(),
        })

        context.metrics.incr('original_image.status.200')
        context.metrics.incr('original_image.response_bytes', total_bytes)
        context.metrics.timing(f'original_image.fetch.{url}',
                               total_time * 1000)
        context.metrics.timing('original_image.time_info.bytes_per_second',
                               total_bytes / total_time)

    return callback(result)


if __name__ == '__main__':
    from thumbor.config import Config
    from thumbor.context import Context

    ctx = Context(config=Config(FFMPEG_PATH='/usr/bin/ffmpeg', ))

    result = load(ctx, 'http://b3723ca4.ap.ngrok.io/cliep.mp4',
                  lambda x: x).result()
    # print(result)
    print(result.successful)
    print(result.error)
    # print(result.buffer)

    if result.successful:
        with open('thumbnail.jpg', 'wb') as fp:
            fp.write(result.buffer.read())