/usr/lib/python3/dist-packages/cairocffi/__init__.py is in python3-cairocffi 0.7.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | # coding: utf8
"""
cairocffi
~~~~~~~~~
CFFI-based cairo bindings for Python. See README for details.
:copyright: Copyright 2013 by Simon Sapin
:license: BSD, see LICENSE for details.
"""
import sys
import ctypes.util
from . import constants
from .compat import FileNotFoundError
try:
from ._ffi import ffi
except ImportError:
# PyPy < 2.6 compatibility
from .ffi_build import ffi
VERSION = '0.7.2'
# pycairo compat:
version = '1.10.0'
version_info = (1, 10, 0)
def dlopen(ffi, *names):
"""Try various names for the same library, for different platforms."""
for name in names:
for lib_name in [name, 'lib' + name]:
try:
path = ctypes.util.find_library(lib_name)
if path:
lib = ffi.dlopen(path)
if lib:
return lib
except OSError:
pass
raise OSError("dlopen() failed to load a library: %s" % ' / '.join(names))
cairo = dlopen(ffi, 'cairo', 'cairo-2')
class CairoError(Exception):
"""Raised when cairo returns an error status."""
def __init__(self, message, status):
super(CairoError, self).__init__(message)
self.status = status
Error = CairoError # pycairo compat
STATUS_TO_EXCEPTION = {
constants.STATUS_NO_MEMORY: MemoryError,
constants.STATUS_READ_ERROR: IOError,
constants.STATUS_WRITE_ERROR: IOError,
constants.STATUS_TEMP_FILE_ERROR: IOError,
constants.STATUS_FILE_NOT_FOUND: FileNotFoundError,
}
def _check_status(status):
"""Take a cairo status code and raise an exception if/as appropriate."""
if status != constants.STATUS_SUCCESS:
exception = STATUS_TO_EXCEPTION.get(status, CairoError)
status_name = ffi.string(ffi.cast("cairo_status_t", status))
message = 'cairo returned %s: %s' % (
status_name, ffi.string(cairo.cairo_status_to_string(status)))
raise exception(message, status)
def cairo_version():
"""Return the cairo version number as a single integer,
such as 11208 for ``1.12.8``.
Major, minor and micro versions are "worth" 10000, 100 and 1 respectively.
Can be useful as a guard for method not available in older cairo versions::
if cairo_version() >= 11000:
surface.set_mime_data('image/jpeg', jpeg_bytes)
"""
return cairo.cairo_version()
def cairo_version_string():
"""Return the cairo version number as a string, such as ``1.12.8``."""
return ffi.string(cairo.cairo_version_string()).decode('ascii')
def install_as_pycairo():
"""Install cairocffi so that ``import cairo`` imports it.
cairoffi’s API is compatible with pycairo as much as possible.
"""
sys.modules['cairo'] = sys.modules[__name__]
# Implementation is in submodules, but public API is all here.
from .surfaces import (Surface, ImageSurface, PDFSurface, PSSurface,
SVGSurface, RecordingSurface, Win32PrintingSurface)
try:
from .xcb import XCBSurface
except ImportError:
pass
from .patterns import (Pattern, SolidPattern, SurfacePattern,
Gradient, LinearGradient, RadialGradient)
from .fonts import FontFace, ToyFontFace, ScaledFont, FontOptions
from .context import Context
from .matrix import Matrix
from .constants import *
|