From: Vladimír Vondruš Date: Sun, 2 Jan 2022 20:18:34 +0000 (+0100) Subject: m.qr: actually, the difference is *also* due to Python versions. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=3ce9243a40f5dd7747e6862440b80957891a9779;p=blog.git m.qr: actually, the difference is *also* due to Python versions. Somehow the attributes have different order, generating a MONSTROUS difference. Heh! Why! Why do I have to suffer this much all the time. --- diff --git a/plugins/m/qr.py b/plugins/m/qr.py index 137f036e..80225b7e 100644 --- a/plugins/m/qr.py +++ b/plugins/m/qr.py @@ -26,14 +26,23 @@ import io import qrcode import qrcode.image.svg import re +import sys from docutils.parsers import rst from docutils.parsers.rst import directives from docutils.parsers.rst.roles import set_classes from docutils import nodes -_svg_preamble_src = re.compile(r"""<\?xml version='1.0' encoding='UTF-8'\?> +# Not sure why exactly, but since Python 3.8 the order of attributes in the +# is different, with the exact same version of qrcode. So I suppose it's +# due to some differences in Python standard library and not qrcode. +if sys.version_info[0:2] >= (3, 8): + _svg_preamble_src = re.compile(r"""<\?xml version='1.0' encoding='UTF-8'\?> +""") +else: + _svg_preamble_src = re.compile(r"""<\?xml version='1.0' encoding='UTF-8'\?> """) + _svg_preamble_dst = '' def _mm2rem(mm): return mm*9.6/2.54/16.0 diff --git a/plugins/m/test/qr/page-py37.html b/plugins/m/test/qr/page-py37.html new file mode 100644 index 00000000..10a9bd95 --- /dev/null +++ b/plugins/m/test/qr/page-py37.html @@ -0,0 +1,37 @@ + + + + + m.qr | A Pelican Blog + + + + + + +
+
+
+
+
+
+

m.qr

+ +

Default:

+

Large stuff inside:

+

Large stuff inside, scaled down.

+ + +
+
+
+
+
+ + \ No newline at end of file diff --git a/plugins/m/test/qr/page.html b/plugins/m/test/qr/page.html index 10a9bd95..816852b3 100644 --- a/plugins/m/test/qr/page.html +++ b/plugins/m/test/qr/page.html @@ -24,9 +24,9 @@

m.qr

Default:

-

Large stuff inside:

-

Large stuff inside, scaled down.

- +

Large stuff inside:

+

Large stuff inside, scaled down.

+ diff --git a/plugins/m/test/test_qr.py b/plugins/m/test/test_qr.py index f305f1d4..d4970f8d 100644 --- a/plugins/m/test/test_qr.py +++ b/plugins/m/test/test_qr.py @@ -37,4 +37,9 @@ class Qr(PelicanPluginTestCase): 'PLUGINS': ['m.htmlsanity', 'm.qr'] }) - self.assertEqual(*self.actual_expected_contents('page.html', 'page.html' if LooseVersion(sys.version) >= LooseVersion("3.7") else 'page-py36.html')) + if LooseVersion(sys.version) >= LooseVersion("3.8"): + self.assertEqual(*self.actual_expected_contents('page.html', 'page.html')) + elif LooseVersion(sys.version) >= LooseVersion("3.7"): + self.assertEqual(*self.actual_expected_contents('page.html', 'page-py37.html')) + else: + self.assertEqual(*self.actual_expected_contents('page.html', 'page-py36.html'))