本文整理汇总了Python中thumbor.context.Context类的典型用法代码示例。如果您正苦于以下问题:Python Context类的具体用法?Python Context怎么用?Python Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
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)
开发者ID:filippog,项目名称:thumbor-debian-dependencies,代码行数:34,代码来源:context.py
示例2: get_filter
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)
开发者ID:GDxU,项目名称:thumbor,代码行数:26,代码来源:base.py
示例3: get_context
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
开发者ID:thumbor,项目名称:thumbor,代码行数:7,代码来源:test_file_storage.py
示例4: to_context
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
开发者ID:brunomvsouza,项目名称:thumbor,代码行数:34,代码来源:transformer_test_data.py
示例5: get_context
def get_context(self):
conf = Config()
conf.STATSD_HOST = ''
ctx = Context(config=conf)
ctx.request = RequestParameters()
return ctx
开发者ID:PopSugar,项目名称:thumbor-plugins,代码行数:7,代码来源:test_optimizers.py
示例6: topic
def topic(self):
config = Config()
context = Context(None, config, Importer(config))
context.request = RequestParameters()
engine = MockInvalidResultEngine(context=context)
return engine.read()
开发者ID:5um1th,项目名称:thumbor,代码行数:7,代码来源:gif_engine_vows.py
示例7: topic
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)
开发者ID:5um1th,项目名称:thumbor,代码行数:7,代码来源:result_storages_file_storage_vows.py
示例8: get_context
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
开发者ID:gi11es,项目名称:thumbor-debian,代码行数:9,代码来源:test_gifv.py
示例9: topic
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()
开发者ID:Hazer,项目名称:thumbor,代码行数:10,代码来源:format_filter_vows.py
示例10: get_optimizer
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
开发者ID:gi11es,项目名称:thumbor-debian,代码行数:11,代码来源:test_jpegtran.py
示例11: topic
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()
开发者ID:APSL,项目名称:thumbor,代码行数:11,代码来源:format_filter_vows.py
示例12: topic
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)
开发者ID:NZME,项目名称:aws,代码行数:12,代码来源:result_storage_vows.py
示例13: topic
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
开发者ID:MechanisM,项目名称:thumbor,代码行数:12,代码来源:quality_filter_vows.py
示例14: topic
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
开发者ID:guilhermef,项目名称:aws,代码行数:13,代码来源:result_storage_vows.py
示例15: topic
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
开发者ID:APSL,项目名称:thumbor,代码行数:14,代码来源:rotate_filter_vows.py
示例16: get_context
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
开发者ID:scorphus,项目名称:thumbor,代码行数:17,代码来源:test_base_handler.py
示例17: topic
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])
开发者ID:amumu,项目名称:thumbor,代码行数:17,代码来源:fill_filter_vows.py
示例18: to_context
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
开发者ID:dannyeuu,项目名称:thumbor,代码行数:46,代码来源:transformer_test_data.py
示例19: get_filter
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)
开发者ID:expertise-com,项目名称:thumbor,代码行数:22,代码来源:base.py
示例20: topic
def topic(self):
config = Config()
context = Context(config=config)
context.request = RequestParameters(url="image.jpg")
fs = NoStorage(context)
return fs.put(100)
开发者ID:abaldwin1,项目名称:thumbor,代码行数:6,代码来源:result_storages_no_storage_vows.py
注:本文中的thumbor.context.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论