本文整理汇总了Python中thumbor.context.Context类的典型用法代码示例。如果您正苦于以下问题:Python Context类的具体用法?Python Context怎么用?Python Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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
示例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
示例5: get_context
def get_context(self):
conf = Config()
conf.STATSD_HOST = ''
ctx = Context(config=conf)
ctx.request = RequestParameters()
return ctx
示例6: topic
def topic(self):
config = Config()
context = Context(None, config, Importer(config))
context.request = RequestParameters()
engine = MockInvalidResultEngine(context=context)
return engine.read()
示例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)
示例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
示例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()
示例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
示例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()
示例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)
示例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
示例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
示例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