本文整理汇总了Python中thumbor.utils.logger.warn函数的典型用法代码示例。如果您正苦于以下问题:Python warn函数的具体用法?Python warn怎么用?Python warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]
示例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)
示例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)
示例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."
)
示例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
示例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)
示例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)
示例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))
示例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)
示例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
示例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)
示例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
示例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)
示例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
示例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)