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
Example #2
0
    def import_modules(self):
        self.config.validates_presence_of('ENGINE', 'LOADER', 'STORAGE', 'DETECTORS', 'FILTERS')
        self.import_item('ENGINE', 'Engine')
        self.import_item('LOADER')
        self.import_item('STORAGE', 'Storage')
        self.import_item('DETECTORS', 'Detector', is_multiple=True)
        self.import_item('FILTERS', 'Filter', is_multiple=True)

        if self.config.RESULT_STORAGE:
            self.import_item('RESULT_STORAGE', 'Storage')

        filters.compile_filters(self.filters)
Example #3
0
    def __init__(self, conf_file=None, security_key=None, custom_handlers=None):
        if conf_file is None:
            conf_file = ThumborServiceApp.get_conf_file(conf_file)

        logger.info('Config file: %s' % conf_file)
        parse_config_file(conf_file)

        self.loader = real_import(conf.LOADER)
        self.storage = real_import(conf.STORAGE)
        self.engine = real_import(conf.ENGINE)
        self.detectors = [real_import(detector_name).Detector for detector_name in conf.DETECTORS]
        self.filters = [real_import(filter_name).Filter for filter_name in conf.FILTERS]
        filters.compile_filters(self.filters)

        # run again to overwrite the default settings on the
        # imported modules with the ones defined into the config file
        parse_config_file(conf_file)

        #storage = storage.Storage()
        #self.engine = self.engine.Engine()

        if security_key:
            options.SECURITY_KEY = security_key

        handler_context = {
            'loader': self.loader,
            'storage': self.storage,
            'engine': self.engine,
            'detectors': self.detectors,
            'filters': self.filters
        }

        handlers = [
            (r'/healthcheck', HealthcheckHandler)
        ]

        if conf.ALLOW_UNSAFE_URL:
            handlers.append(
                (Url.regex(), MainHandler, handler_context),
            )

        if custom_handlers:
            for handler in custom_handlers:
                handlers.append((handler[0], handler[1], handler_context))
        else:
            handlers.append(
                (r'/(?P<crypto>[^/]+)/(?P<image>(.+))', CryptoHandler, handler_context)
            )

        super(ThumborServiceApp, self).__init__(handlers)