Decode retrieved files as UTF-8 even on Python 2
authorJeremy Stanley <fungi@yuggoth.org>
Sun, 31 May 2020 00:17:36 +0000 (00:17 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Sun, 31 May 2020 00:17:36 +0000 (00:17 +0000)
Python 2.7 is likely the only Python 2 anyone is using any longer
(even that's well past EOL upstream now), and reasonably recent
versions of 2.7 it need the same decode hack as Python 3 anyway when
dealing with some retrieved content. Just get rid of the version
detection and do it under any version.

weather.py

index 369ce99..fa94727 100644 (file)
@@ -222,8 +222,7 @@ def get_uri(
         dcache_fd.close()
     else:
         try:
-            if pyversion("3"): data = urlopen(uri).read().decode("utf-8")
-            else: data = urlopen(uri).read()
+            data = urlopen(uri).read().decode("utf-8")
         except URLError:
             if ignore_fail: return ""
             else: