diff options
author | Magnus Hagander | 2019-11-05 18:59:35 +0000 |
---|---|---|
committer | Magnus Hagander | 2019-11-05 19:05:36 +0000 |
commit | 0ef3b472aae2ed693b16d3da95b1562fefa1e6cd (patch) | |
tree | 82db6192b0248ddd46aba8ccd340f073358d27a7 /postgresqleu/util/qr.py | |
parent | 67ee0f4eeced616c195b6d13b4d018e5b072c2f5 (diff) |
Make loading of qrencode and cairosvg optional
In particular, cairosvg is only used for the PNG format twitter cards,
so most functionality exists without it.
Make sure we import those modules conditionally only when needed and
handle the import exception. Also add an explicit attempt to load them
during system startup and write to the log if it fails, so it doesn't do
so silently.
Diffstat (limited to 'postgresqleu/util/qr.py')
-rw-r--r-- | postgresqleu/util/qr.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/postgresqleu/util/qr.py b/postgresqleu/util/qr.py index a1600826..4a346684 100644 --- a/postgresqleu/util/qr.py +++ b/postgresqleu/util/qr.py @@ -1,10 +1,14 @@ -import qrencode from PIL import Image import base64 from io import BytesIO def generate_base64_qr(s, version, requested_size): + try: + import qrencode + except ImportError: + return "" + (ver, size, qrimage) = qrencode.encode(s, version=5, level=qrencode.QR_ECLEVEL_M) if size < requested_size: size = (requested_size // size) * size |