Python error
Enrico Forestieri
forenr at lyx.org
Sat Mar 14 15:22:02 UTC 2020
On Fri, Mar 13, 2020 at 10:06:48AM +0100, Jürgen Spitzmüller wrote:
> I get the following python traceback in master:
>
> Traceback (most recent call last):
> File "/home/juergen/lyx/lyx-devel/lib/scripts/lyxpreview2bitmap.py",
> line 594, in <module>
> sys.exit(main(sys.argv)[0])
> File "/home/juergen/lyx/lyx-devel/lib/scripts/lyxpreview2bitmap.py",
> line 472, in main
> latex_status, latex_stdout = run_latex(latex, latex_file, bibtex)
> File "/home/juergen/lyx/lyx-devel/lib/scripts/lyxpreview_tools.py",
> line 297, in run_latex
> if string_in_file("Warning: Citation", log_file):
> File "/home/juergen/lyx/lyx-devel/lib/scripts/lyxpreview_tools.py",
> line 317, in string_in_file
> for line in f.readlines():
> File "/usr/lib64/python3.8/codecs.py", line 322, in decode
> (result, consumed) = self._buffer_decode(data, self.errors, final)
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position
> 4180: invalid start byte
Please, try the attached patch.
--
Enrico
-------------- next part --------------
diff --git a/lib/scripts/legacy_lyxpreview2ppm.py b/lib/scripts/legacy_lyxpreview2ppm.py
index a5eb05a129..6e3c349f35 100644
--- a/lib/scripts/legacy_lyxpreview2ppm.py
+++ b/lib/scripts/legacy_lyxpreview2ppm.py
@@ -154,10 +154,10 @@ def legacy_extract_metrics_info(log_file):
return results
def extract_resolution(log_file, dpi):
- fontsize_re = re.compile("Preview: Fontsize")
- magnification_re = re.compile("Preview: Magnification")
- extract_decimal_re = re.compile("([0-9\.]+)")
- extract_integer_re = re.compile("([0-9]+)")
+ fontsize_re = re.compile(b"Preview: Fontsize")
+ magnification_re = re.compile(b"Preview: Magnification")
+ extract_decimal_re = re.compile(b"([0-9\.]+)")
+ extract_integer_re = re.compile(b"([0-9]+)")
found_fontsize = 0
found_magnification = 0
@@ -167,7 +167,7 @@ def extract_resolution(log_file, dpi):
fontsize = 10.0
try:
- for line in open(log_file, 'r').readlines():
+ for line in open(log_file, 'rb').readlines():
if found_fontsize and found_magnification:
break
diff --git a/lib/scripts/lyxpreview_tools.py b/lib/scripts/lyxpreview_tools.py
index 93964083a5..51917b8cdf 100644
--- a/lib/scripts/lyxpreview_tools.py
+++ b/lib/scripts/lyxpreview_tools.py
@@ -313,9 +313,9 @@ def run_tex(tex, tex_file):
def string_in_file(string, infile):
if not os.path.isfile(infile):
return False
- f = open(infile, 'r')
+ f = open(infile, 'rb')
for line in f.readlines():
- if string in line:
+ if string.encode() in line:
f.close()
return True
f.close()
More information about the lyx-devel
mailing list