Oct-14-2018, 12:28 AM
So I wanted to convert bk-chem-0.13.0 source code from Python 2 to Python 3 using 2to3. So in cmd, I ran this command so that it will convert all the files in the directory:
2to3 C:\User\Admin\Downloads\bkchem\. -wSo far, so good: here's some output dump sample from just before the error:
Output:RefactoringTool: Refactored C:\Users\Admin\Downloads\bkchem\.\bkchem\plugins\piddle\PixMapWrapper.py
--- C:\Users\Admin\Downloads\bkchem\.\bkchem\plugins\piddle\PixMapWrapper.py (original)
+++ C:\Users\Admin\Downloads\bkchem\.\bkchem\plugins\piddle\PixMapWrapper.py (refactored)
@@ -109,7 +109,7 @@
elif attr == 'hRes' or attr == 'vRes':
# 16.16 fixed format, so just shift 16 bits
self._stuff(attr, int(val) << 16)
- elif attr in _pmElemFormat.keys():
+ elif attr in list(_pmElemFormat.keys()):
# any other pm attribute -- just stuff
self._stuff(attr, val)
else:
@@ -129,7 +129,7 @@
elif attr == 'hRes' or attr == 'vRes':
# 16.16 fixed format, so just shift 16 bits
return self._unstuff(attr) >> 16
- elif attr in _pmElemFormat.keys():
+ elif attr in list(_pmElemFormat.keys()):
# any other pm attribute -- just unstuff
return self._unstuff(attr)
else:
@@ -151,7 +151,7 @@
if y2 == None:
dest[3] = y1 + src[3]-src[1]
if not port: port = Qd.GetPort()
- print "blit port:", port
+ print("blit port:", port)
Qd.CopyBits(self.PixMap(), port.portBits, src, tuple(dest),
QuickDraw.srcCopy, None)
And here, the error comes:Error:Traceback (most recent call last):
File "c:\users\admin\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\admin\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python37\Scripts\2to3.exe\__main__.py", line 9, in <module>
File "c:\users\admin\appdata\local\programs\python\python37\lib\site-packages\cmd_2to3\__main__.py", line 6, in main
sys.exit(l2to3_main("lib2to3.fixes"))
File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\main.py", line 259, in main
options.processes)
File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 687, in refactor
items, write, doctests_only)
File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 280, in refactor
self.refactor_dir(dir_or_file, write, doctests_only)
File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 300, in refactor_dir
self.refactor_file(fullname, write, doctests_only)
File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 728, in refactor_file
*args, **kwargs)
File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 322, in refactor_file
input, encoding = self._read_python_source(filename)
File "c:\users\admin\appdata\local\programs\python\python37\lib\lib2to3\refactor.py", line 318, in _read_python_source
return f.read(), encoding
File "c:\users\admin\appdata\local\programs\python\python37\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 18708: invalid start byte
Based on my understanding, I think that the error is not with the bkchem code (since there was no mention of it in the traceback), but with 2to3. What's happening and how to fix it?