本文整理汇总了Python中thumbor.utils.logger.warn函数的典型用法代码示例。如果您正苦于以下问题:Python warn函数的具体用法?Python warn怎么用?Python warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warn函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: trim
def trim(self):
is_gifsicle = (self.context.request.engine.extension == '.gif' and self.context.config.USE_GIFSICLE_ENGINE)
if self.context.request.trim is None or not trim_enabled or is_gifsicle:
return
mode, data = self.engine.image_data_as_rgb()
box = _bounding_box.apply(
mode,
self.engine.size[0],
self.engine.size[1],
self.context.request.trim_pos,
self.context.request.trim_tolerance,
data
)
if box[2] < box[0] or box[3] < box[1]:
logger.warn("Ignoring trim, there wouldn't be any image left, check the tolerance.")
return
self.engine.crop(box[0], box[1], box[2] + 1, box[3] + 1)
if self.context.request.should_crop:
self.context.request.crop['left'] -= box[0]
self.context.request.crop['top'] -= box[1]
self.context.request.crop['right'] -= box[0]
self.context.request.crop['bottom'] -= box[1]
开发者ID:caeugusmao,项目名称:thumbor,代码行数:25,代码来源:transformer.py
示例2: return_contents
def return_contents(response, url, callback, context, req_start=None):
if req_start:
finish = datetime.datetime.now()
res = urlparse(url)
context.metrics.timing(
'original_image.fetch.{0}.{1}'.format(response.code, res.netloc),
(finish - req_start).total_seconds() * 1000
)
result = LoaderResult()
context.metrics.incr('original_image.status.' + str(response.code))
if response.error:
result.successful = False
if response.code == 599:
# Return a Gateway Timeout status downstream if upstream times out
result.error = LoaderResult.ERROR_TIMEOUT
else:
result.error = LoaderResult.ERROR_NOT_FOUND
logger.warn(u"ERROR retrieving image {0}: {1}".format(url, str(response.error)))
elif response.body is None or len(response.body) == 0:
result.successful = False
result.error = LoaderResult.ERROR_UPSTREAM
logger.warn(u"ERROR retrieving image {0}: Empty response.".format(url))
else:
if response.time_info:
for x in response.time_info:
context.metrics.timing('original_image.time_info.' + x, response.time_info[x] * 1000)
context.metrics.timing('original_image.time_info.bytes_per_second', len(response.body) / response.time_info['total'])
result.buffer = response.body
context.metrics.incr('original_image.response_bytes', len(response.body))
callback(result)
开发者ID:gi11es,项目名称:thumbor-debian,代码行数:35,代码来源:http_loader.py
示例3: return_contents
def return_contents(response, url, callback, context):
result = LoaderResult()
context.metrics.incr('original_image.status.' + str(response.code))
if response.error:
result.successful = False
if response.code == 599:
# Return a Gateway Timeout status downstream if upstream times out
result.error = LoaderResult.ERROR_TIMEOUT
else:
result.error = LoaderResult.ERROR_NOT_FOUND
logger.warn(u"ERROR retrieving image {0}: {1}".format(url, str(response.error)))
elif response.body is None or len(response.body) == 0:
result.successful = False
result.error = LoaderResult.ERROR_UPSTREAM
logger.warn(u"ERROR retrieving image {0}: Empty response.".format(url))
else:
if response.time_info:
for x in response.time_info:
context.metrics.timing('original_image.time_info.' + x, response.time_info[x] * 1000)
context.metrics.timing('original_image.time_info.bytes_per_second', len(response.body) / response.time_info['total'])
result.buffer = response.body
callback(result)
开发者ID:5um1th,项目名称:thumbor,代码行数:27,代码来源:http_loader.py
示例4: _process_result_from_storage
def _process_result_from_storage(self, result):
if self.context.config.SEND_IF_MODIFIED_LAST_MODIFIED_HEADERS:
# Handle If-Modified-Since & Last-Modified header
try:
if isinstance(result, ResultStorageResult):
result_last_modified = result.last_modified
else:
result_last_modified = yield gen.maybe_future(self.context.modules.result_storage.last_updated())
if result_last_modified:
if "If-Modified-Since" in self.request.headers:
date_modified_since = datetime.datetime.strptime(
self.request.headers["If-Modified-Since"], HTTP_DATE_FMT
)
if result_last_modified <= date_modified_since:
self.set_status(304)
self.finish()
return
self.set_header("Last-Modified", result_last_modified.strftime(HTTP_DATE_FMT))
except NotImplementedError:
logger.warn(
"last_updated method is not supported by your result storage service, hence If-Modified-Since & "
"Last-Updated headers support is disabled."
)
开发者ID:nyimbi,项目名称:thumbor,代码行数:26,代码来源:__init__.py
示例5: load
def load(context, url, callback):
enable_http_loader = context.config.get('AWS_ENABLE_HTTP_LOADER', default=False)
if enable_http_loader and url.startswith('http'):
return http_loader.load_sync(context, url, callback, normalize_url_func=_normalize_url)
url = urllib2.unquote(url)
bucket = context.config.get('S3_LOADER_BUCKET', default=None)
if not bucket:
bucket, url = _get_bucket(url)
if _validate_bucket(context, bucket):
bucket_loader = Bucket(
connection=thumbor_aws.connection.get_connection(context),
name=bucket
)
file_key = None
try:
file_key = bucket_loader.get_key(url)
except Exception, e:
logger.warn("ERROR retrieving image from S3 {0}: {1}".format(url, str(e)))
if file_key:
callback(file_key.read())
return
开发者ID:Bladrak,项目名称:aws,代码行数:27,代码来源:s3_loader.py
示例6: srgb
def srgb(self):
try:
if not isinstance(self.engine, PILEngine):
logger.warn('Could not perform profileToProfile conversion: engine is not PIL engine')
return
if (ImageCms is None):
logger.warn('ImageCms is not installed. Could not perform profileToProfile conversion')
return
image = self.engine.image
embedded_profile = image.info.get('icc_profile')
if not embedded_profile:
logger.debug('Image does not have embedded profile. Assuming already in sRGB')
return
embedded_profile = BytesIO(embedded_profile)
srgb_profile = BytesIO(tiny_srgb)
output_mode = 'RGBA' if 'A' in image.mode else 'RGB'
image = ImageCms.profileToProfile(image, embedded_profile, srgb_profile, renderingIntent=0,
outputMode=output_mode)
self.engine.image = image
self.engine.icc_profile = image.info.get('icc_profile')
except Exception as err:
logger.exception(err)
开发者ID:PopSugar,项目名称:thumbor-plugins,代码行数:29,代码来源:srgb.py
示例7: import_item
def import_item(self, config_key=None, class_name=None, is_multiple=False, item_value=None, ignore_errors=False):
if item_value is None:
conf_value = getattr(self.config, config_key)
else:
conf_value = item_value
if is_multiple:
modules = []
if conf_value:
for module_name in conf_value:
try:
if class_name is not None:
module = self.import_class('%s.%s' % (module_name, class_name))
else:
module = self.import_class(module_name, get_module=True)
modules.append(module)
except ImportError:
if ignore_errors:
logger.warn('Module %s could not be imported.' % module_name)
else:
raise
setattr(self, config_key.lower(), tuple(modules))
else:
if class_name is not None:
module = self.import_class('%s.%s' % (conf_value, class_name))
else:
module = self.import_class(conf_value, get_module=True)
setattr(self, config_key.lower(), module)
开发者ID:dotscreen,项目名称:thumbor,代码行数:28,代码来源:importer.py
示例8: _handle_error
def _handle_error(self, response):
"""
Logs error if necessary
:param dict response: AWS Response
"""
if self._get_error(response):
logger.warn("[STORAGE] error occured while storing data: %s" % self._get_error(response))
开发者ID:eduherraiz,项目名称:aws,代码行数:7,代码来源:storage.py
示例9: detect
def detect(self, callback):
engine = self.context.modules.engine
try:
img = np.array(
engine.convert_to_grayscale(
update_image=False,
with_alpha=False
)
)
except Exception:
logger.warn('Error during feature detection; skipping to next detector')
self.next(callback)
return
points = cv2.goodFeaturesToTrack(
img,
maxCorners=20,
qualityLevel=0.04,
minDistance=1.0,
useHarrisDetector=False,
)
if points is not None:
for x, y in points.squeeze():
self.context.request.focal_points.append(FocalPoint(x.item(), y.item(), 1))
callback()
else:
self.next(callback)
开发者ID:gi11es,项目名称:thumbor-debian,代码行数:27,代码来源:__init__.py
示例10: run_optimizer
def run_optimizer(self, image_extension, buffer):
if not self.should_run(image_extension, buffer):
return buffer
command = [
self.context.config.JPEGTRAN_PATH,
'-copy',
'comments',
'-optimize',
]
if self.context.config.PROGRESSIVE_JPEG:
command += [
'-progressive'
]
jpg_process = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
output_stdout, output_stderr = jpg_process.communicate(buffer)
if jpg_process.returncode != 0:
logger.warn('jpegtran finished with non-zero return code (%d): %s'
% (jpg_process.returncode, output_stderr))
return buffer
return output_stdout
开发者ID:Bladrak,项目名称:thumbor,代码行数:25,代码来源:jpegtran.py
示例11: get
def get(self, callback):
path = self.context.request.url
file_abspath = self.normalize_path(path)
if not self.validate_path(file_abspath):
logger.warn("[RESULT_STORAGE] unable to read from outside root path: %s" % file_abspath)
return None
logger.debug("[RESULT_STORAGE] getting from %s" % file_abspath)
if not exists(file_abspath) or self.is_expired(file_abspath):
logger.debug("[RESULT_STORAGE] image not found at %s" % file_abspath)
callback(None)
else:
with open(file_abspath, 'r') as f:
buffer = f.read()
result = ResultStorageResult(
buffer=buffer,
metadata={
'LastModified': datetime.fromtimestamp(getmtime(file_abspath)).replace(tzinfo=pytz.utc),
'ContentLength': len(buffer),
'ContentType': BaseEngine.get_mimetype(buffer)
}
)
callback(result)
开发者ID:RealGeeks,项目名称:thumbor,代码行数:25,代码来源:file_storage.py
示例12: should_run
def should_run(self, image_extension, buffer):
if 'gif' in image_extension and 'gifv' in self.context.request.filters:
if not exists(self.context.config.FFMPEG_PATH):
logger.warn(
'gifv optimizer enabled but binary FFMPEG_PATH does not exist')
return False
return True
return False
开发者ID:caeugusmao,项目名称:thumbor,代码行数:8,代码来源:gifv.py
示例13: __setattr__
def __setattr__(self, name, value):
if name in Config.class_aliased_items:
logger.warn(
"Option %s is marked as deprecated please use %s instead." % (name, Config.class_aliased_items[name])
)
self.__setattr__(Config.class_aliased_items[name], value)
else:
super(Config, self).__setattr__(name, value)
开发者ID:bguided,项目名称:thumbor,代码行数:8,代码来源:config.py
示例14: should_run
def should_run(self, image_extension, buffer):
if image_extension in ['.jpg', '.jpeg']:
if not exists(self.context.config.JPEGTRAN_PATH):
logger.warn(
'jpegtran optimizer enabled but binary JPEGTRAN_PATH does not exist')
return False
return True
return False
开发者ID:caeugusmao,项目名称:thumbor,代码行数:8,代码来源:jpegtran.py
示例15: return_contents
def return_contents(response, url, callback):
if response.error:
logger.warn("ERROR retrieving image {0}: {1}".format(url, str(response.error)))
callback(None)
elif response.body is None or len(response.body) == 0:
logger.warn("ERROR retrieving image {0}: Empty response.".format(url))
callback(None)
else:
callback(response.body)
开发者ID:joevandyk,项目名称:thumbor,代码行数:9,代码来源:http_loader.py
示例16: validate
def validate(self, path):
if not hasattr(self.context.modules.loader, 'validate'):
return True
is_valid = self.context.modules.loader.validate(self.context, path)
if not is_valid:
logger.warn('Request denied because the specified path "%s" was not identified by the loader as a valid path' % path)
return is_valid
开发者ID:caeugusmao,项目名称:thumbor,代码行数:10,代码来源:__init__.py
示例17: get
def get(self):
path = self.context.request.url
file_abspath = self.normalize_path(path)
if not self.validate_path(file_abspath):
logger.warn("[RESULT_STORAGE] unable to read from outside root path: %s" % file_abspath)
return None
logger.debug("[RESULT_STORAGE] getting from %s" % file_abspath)
if not exists(file_abspath) or self.is_expired(file_abspath):
logger.debug("[RESULT_STORAGE] image not found at %s" % file_abspath)
return None
with open(file_abspath, 'r') as f:
return f.read()
开发者ID:HyperionGG,项目名称:thumbor,代码行数:13,代码来源:file_storage.py
示例18: last_updated
def last_updated(self):
path = self.context.request.url
file_abspath = self.normalize_path(path)
if not self.validate_path(file_abspath):
logger.warn("[RESULT_STORAGE] unable to read from outside root path: %s" % file_abspath)
return True
logger.debug("[RESULT_STORAGE] getting from %s" % file_abspath)
if not exists(file_abspath) or self.is_expired(file_abspath):
logger.debug("[RESULT_STORAGE] image not found at %s" % file_abspath)
return True
return datetime.fromtimestamp(getmtime(file_abspath)).replace(tzinfo=pytz.utc)
开发者ID:RealGeeks,项目名称:thumbor,代码行数:13,代码来源:file_storage.py
示例19: handle_data
def handle_data(file_key):
if not file_key or 'Error' in file_key or 'Body' not in file_key:
logger.warn("ERROR retrieving image from S3 {0}: {1}".format(key, str(file_key)))
# If we got here, there was a failure. We will return 404 if S3 returned a 404, otherwise 502.
result = LoaderResult()
result.successful = False
if file_key and file_key.get('ResponseMetadata', {}).get('HTTPStatusCode') == 404:
result.error = LoaderResult.ERROR_NOT_FOUND
else:
result.error = LoaderResult.ERROR_UPSTREAM
callback(result)
else:
callback(file_key['Body'].read())
开发者ID:sayeghr,项目名称:aws,代码行数:13,代码来源:s3_loader.py
示例20: return_contents
def return_contents(response, url, callback, context):
context.statsd_client.incr('original_image.status.' + str(response.code))
if response.error:
logger.warn("ERROR retrieving image {0}: {1}".format(url, str(response.error)))
callback(None)
elif response.body is None or len(response.body) == 0:
logger.warn("ERROR retrieving image {0}: Empty response.".format(url))
callback(None)
else:
if response.time_info:
for x in response.time_info:
context.statsd_client.timing('original_image.time_info.' + x, response.time_info[x] * 1000)
context.statsd_client.timing('original_image.time_info.bytes_per_second', len(response.body) / response.time_info['total'])
callback(response.body)
开发者ID:dhardy92,项目名称:thumbor,代码行数:14,代码来源:http_loader.py
注:本文中的thumbor.utils.logger.warn函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论