Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_api():
with pytest.raises(pixbuf.ImageLoadingError):
pixbuf.decode_to_image_surface(b'')
with pytest.raises(pixbuf.ImageLoadingError):
pixbuf.decode_to_image_surface(b'Not a valid image.')
with pytest.raises(pixbuf.ImageLoadingError):
pixbuf.decode_to_image_surface(PNG_BYTES[:10])
surface, format_name = pixbuf.decode_to_image_surface(PNG_BYTES)
assert format_name == 'png'
assert_decoded(surface)
def test_api():
with pytest.raises(pixbuf.ImageLoadingError):
pixbuf.decode_to_image_surface(b'')
with pytest.raises(pixbuf.ImageLoadingError):
pixbuf.decode_to_image_surface(b'Not a valid image.')
with pytest.raises(pixbuf.ImageLoadingError):
pixbuf.decode_to_image_surface(PNG_BYTES[:10])
surface, format_name = pixbuf.decode_to_image_surface(PNG_BYTES)
assert format_name == 'png'
assert_decoded(surface)
def test_api():
with pytest.raises(pixbuf.ImageLoadingError):
pixbuf.decode_to_image_surface(b'')
with pytest.raises(pixbuf.ImageLoadingError):
pixbuf.decode_to_image_surface(b'Not a valid image.')
with pytest.raises(pixbuf.ImageLoadingError):
pixbuf.decode_to_image_surface(PNG_BYTES[:10])
surface, format_name = pixbuf.decode_to_image_surface(PNG_BYTES)
assert format_name == 'png'
assert_decoded(surface)
def _decode_to_image_surface(bytes_img, width=None, height=None):
try:
surf, fmt = cairocffi.pixbuf.decode_to_image_surface(bytes_img, width, height)
return _SurfaceInfo(surf, fmt)
except TypeError:
from .log_utils import logger
logger.exception(
"Couldn't load cairo image at specified width and height. "
"Falling back to image scaling using cairo. "
"Need cairocffi > v0.8.0"
)
surf, fmt = cairocffi.pixbuf.decode_to_image_surface(bytes_img)
return _SurfaceInfo(surf, fmt)
def _decode_to_image_surface(bytes_img, width=None, height=None):
try:
surf, fmt = cairocffi.pixbuf.decode_to_image_surface(bytes_img, width, height)
return _SurfaceInfo(surf, fmt)
except TypeError:
from .log_utils import logger
logger.exception(
"Couldn't load cairo image at specified width and height. "
"Falling back to image scaling using cairo. "
"Need cairocffi > v0.8.0"
)
surf, fmt = cairocffi.pixbuf.decode_to_image_surface(bytes_img)
return _SurfaceInfo(surf, fmt)
def load_image(path):
with open(path, 'rb') as f:
surface, mimetype = cairocffi.pixbuf.decode_to_image_surface(f.read())
return surface