本文整理汇总了Python中PIL.Image.DecompressionBombWarning方法的典型用法代码示例。如果您正苦于以下问题:Python Image.DecompressionBombWarning方法的具体用法?Python Image.DecompressionBombWarning怎么用?Python Image.DecompressionBombWarning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PIL.Image
的用法示例。
在下文中一共展示了Image.DecompressionBombWarning方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_crop_decompression_checks
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import DecompressionBombWarning [as 别名]
def test_crop_decompression_checks(self):
im = Image.new("RGB", (100, 100))
good_values = ((-9999, -9999, -9990, -9990),
(-999, -999, -990, -990))
warning_values = ((-160, -160, 99, 99),
(160, 160, -99, -99))
error_values = ((-99909, -99990, 99999, 99999),
(99909, 99990, -99999, -99999))
for value in good_values:
self.assertEqual(im.crop(value).size, (9, 9))
for value in warning_values:
self.assert_warning(Image.DecompressionBombWarning, im.crop, value)
for value in error_values:
with self.assertRaises(Image.DecompressionBombError):
im.crop(value)
示例2: test_warning
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import DecompressionBombWarning [as 别名]
def test_warning(self):
# Set limit to trigger warning on the test file
Image.MAX_IMAGE_PIXELS = 128 * 128 - 1
self.assertEqual(Image.MAX_IMAGE_PIXELS, 128 * 128 - 1)
self.assert_warning(Image.DecompressionBombWarning,
Image.open, TEST_FILE)
示例3: testEnlargeCrop
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import DecompressionBombWarning [as 别名]
def testEnlargeCrop(self):
# Crops can extend the extents, therefore we should have the
# same decompression bomb warnings on them.
box = (0, 0, self.src.width * 2, self.src.height * 2)
self.assert_warning(Image.DecompressionBombWarning,
self.src.crop, box)
示例4: ignore_warnings
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import DecompressionBombWarning [as 别名]
def ignore_warnings():
"""Sets a warning filter for pillow's annoying ``DecompressionBombWarning``
"""
import warnings
from PIL import Image
warnings.simplefilter(action='ignore', category=Image.DecompressionBombWarning)