本文整理汇总了Python中thumbor.utils.logger.exception函数的典型用法代码示例。如果您正苦于以下问题:Python exception函数的具体用法?Python exception怎么用?Python exception使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exception函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request
def request(self):
try:
self.thumbor_filter.context.modules.loader.load(
self.thumbor_filter.context, self.url, self.on_fetch_done)
except Exception as err:
self.failed = True
logger.exception(err)
示例2: put_detector_data
def put_detector_data(self, path, data):
key = self.detector_key_for(path)
try:
self.storage.set(key, dumps(data))
except:
logger.exception("[MEMCACHED] failed to set key '{0}'".format(key));
return key
示例3: 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 as e:
logger.exception(e)
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 point in points:
x, y = point.ravel()
self.context.request.focal_points.append(FocalPoint(x.item(), y.item(), 1))
callback()
else:
self.next(callback)
示例4: 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)
示例5: put
def put(self, path, contents):
key = self.key_for(path)
try:
self.storage.set(key, contents, time=self.context.config.STORAGE_EXPIRATION_SECONDS)
except:
logger.exception("[MEMCACHED] failed to set key '{0}'".format(key));
return path
示例6: smart_detect
def smart_detect(self):
if not (self.context.modules.detectors and self.context.request.smart):
self.do_image_operations()
return
try:
# Beware! Boolean hell ahead.
#
# The `running_smart_detection` flag is needed so we can know
# whether `after_smart_detect()` is running synchronously or not.
#
# If we're running it in a sync fashion it will set
# `should_run_image_operations` to True so we can avoid running
# image operation inside the try block.
self.should_run_image_operations = False
self.running_smart_detection = True
self.do_smart_detection()
self.running_smart_detection = False
except Exception:
if not self.context.config.IGNORE_SMART_ERRORS:
raise
logger.exception("Ignored error during smart detection")
if self.context.config.USE_CUSTOM_ERROR_HANDLING:
self.context.modules.importer.error_handler.handle_error(context=self.context, handler=self.context.request_handler, exception=sys.exc_info())
self.context.request.prevent_result_storage = True
self.context.request.detection_error = True
self.do_image_operations()
if self.should_run_image_operations:
self.do_image_operations()
示例7: _get_exif_segment
def _get_exif_segment(self):
try:
segment = ExifSegment(None, None, self.exif, 'ro')
except Exception:
logger.exception('Ignored error handling exif for reorientation')
else:
return segment
return None
示例8: read
def read(self, extension=None, quality=None):
#returns image buffer in byte format.
img_buffer = BytesIO()
ext = extension or self.extension
options = {
'quality': quality
}
if ext == '.jpg' or ext == '.jpeg':
options['optimize'] = True
options['progressive'] = True
if quality is None:
options['quality'] = 'keep'
if options['quality'] is None:
options['quality'] = self.context.config.QUALITY
if self.icc_profile is not None:
options['icc_profile'] = self.icc_profile
if self.context.config.PRESERVE_EXIF_INFO:
exif = self.image.info.get('exif', None)
if exif is not None:
options['exif'] = exif
if self.image.mode == 'P' and self.transparency:
options['transparency'] = self.transparency
try:
if ext == '.webp':
if self.image.mode not in ['RGB', 'RGBA']:
mode = None
if self.image.mode != 'P':
mode = 'RGBA' if self.image.mode[-1] == 'A' else 'RGB'
self.image = self.image.convert(mode)
self.image.save(img_buffer, FORMATS[ext], **options)
except IOError:
logger.exception('Could not save as improved image, consider to increase ImageFile.MAXBLOCK')
self.image.save(img_buffer, FORMATS[ext])
except KeyError:
logger.exception('Image format not found in PIL: %s' % ext)
#extension is not present or could not help determine format => force JPEG
if self.image.mode in ['P', 'RGBA', 'LA']:
self.image.format = FORMATS['.png']
self.image.save(img_buffer, FORMATS['.png'])
else:
self.image.format = FORMATS['.jpg']
self.image.save(img_buffer, FORMATS['.jpg'])
results = img_buffer.getvalue()
img_buffer.close()
return results
示例9: _load_results
def _load_results(self, context):
try:
results, content_type = BaseHandler._load_results(self, context)
except Exception:
logger.exception('[ImagesHandler] Exception during _load_results', extra=log_extra(context))
self._error(500)
return None, None
return results, content_type
示例10: _execute_in_foreground
def _execute_in_foreground(self, operation, callback):
result = Future()
returned = None
try:
returned = operation()
except Exception as e:
# just log exception and release ioloop
returned = e
logger.exception(e)
result.set_result(returned)
callback(result)
示例11: _get_exif_segment
def _get_exif_segment(self):
if (not hasattr(self, 'exif')) or self.exif is None:
return None
try:
segment = ExifSegment(None, None, self.exif, 'ro')
except Exception:
logger.exception('Ignored error handling exif for reorientation')
else:
return segment
return None
示例12: _execute_in_foreground
def _execute_in_foreground(self, operation, callback):
result = Future()
try:
returned = operation()
except Exception as e:
logger.exception('[ThreadPool] %s', e)
result.set_exception(e)
else:
result.set_result(returned)
callback(result)
示例13: put_crypto
def put_crypto(self, path):
if not self.context.config.STORES_CRYPTO_KEY_FOR_EACH_IMAGE:
return
if not self.context.server.security_key:
raise RuntimeError("STORES_CRYPTO_KEY_FOR_EACH_IMAGE can't be True if no SECURITY_KEY specified")
key = self.crypto_key_for(path)
try:
self.storage.set(key, self.context.server.security_key)
except:
logger.exception("[MEMCACHED] failed to set key '{0}'".format(key));
return key
示例14: inner
def inner(future):
try:
future_result = future.result()
except Exception as e:
logger.exception('[BaseHander.finish_request] %s', e)
self._error(500, 'Error while trying to fetch the image: {}'.format(e))
return
results, content_type = future_result
self._write_results_to_client(results, content_type)
if should_store:
tornado.ioloop.IOLoop.instance().add_callback(self._store_results, result_storage, metrics, results)
示例15: icc_profile_apply
def icc_profile_apply(self, profile=None):
# Check whether input image has color management.
if not self.engine.icc_profile:
logger.info('ICC: Image has no embedded profile. Skipping this image.')
return
# Sanitize profile parameter.
if profile != None:
profile = os.path.basename(profile).lstrip('.')
if len(profile) == 0:
logger.warning('ICC: Invalid profile name.')
return
# Find output profile.
outprofile = self._find_profile(profile)
if not outprofile:
logger.warning('ICC: Failed to load profile: {:s}'.format(profile))
return
try:
ext = self.engine.extension
fmt = Image.EXTENSION[ext.lower()]
except:
logger.exception('ICC: Failed to determine image format and extension before attempting to apply profile: {:s}'.format(profile))
return
try:
inmode = self.engine.get_image_mode()
insize = self.engine.size
inimg = Image.frombytes(inmode, insize, self.engine.get_image_data())
# In PIL>=3.0.0 / Thumbor 6, icc_profile is sometimes a tuple :/
# https://github.com/python-pillow/Pillow/issues/1462
profile_data = self.engine.icc_profile
if type(profile_data) == tuple:
profile_data = profile_data[0]
inprofile = StringIO(profile_data)
outmode = 'RGBA' if 'A' in inmode else 'RGB'
except:
logger.exception('ICC: Failed to determine image properties before attempting to apply profile: {:s}'.format(profile))
return
logger.info('ICC: Attempting to apply profile: {:s}, inmode: {:s}, outmode: {:s}'.format(profile, inmode, outmode))
try:
outimg = ImageCms.profileToProfile(inimg, inprofile, outprofile, outputMode=outmode)
except:
logger.exception('ICC: Failed to apply profile: {:s}, inmode: {:s}, outmode: {:s}'.format(profile, inmode, outmode))
return
# Reload the image into the engine.
outbuf = StringIO()
try:
outimg.save(outbuf, fmt)
self.engine.load(outbuf.getvalue(), ext)
except:
logger.exception('ICC: Failed load the image with an applied profile: {:s}, inmode: {:s}, outmode: {:s}'.format(profile, inmode, outmode))
return
finally:
outbuf.close()