summaryrefslogtreecommitdiff
path: root/postgresqleu/util/qr.py
diff options
context:
space:
mode:
authorMagnus Hagander2019-11-05 18:59:35 +0000
committerMagnus Hagander2019-11-05 19:05:36 +0000
commit0ef3b472aae2ed693b16d3da95b1562fefa1e6cd (patch)
tree82db6192b0248ddd46aba8ccd340f073358d27a7 /postgresqleu/util/qr.py
parent67ee0f4eeced616c195b6d13b4d018e5b072c2f5 (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.py6
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