<div dir="ltr">Hi,<div><br></div><div>We have run across an older deb file:</div><div><br></div><div><a href="http://ubuntu-master.mirror.tudos.de/ubuntu/pool/universe/a/aspell-is/aspell-is_0.51-0-4_all.deb">http://ubuntu-master.mirror.tudos.de/ubuntu/pool/universe/a/aspell-is/aspell-is_0.51-0-4_all.deb</a><br></div><div><br></div><div>One of its files, usr/lib/aspell/íslenska.alias, is not utf8-encoded in the control file.</div><div><br></div><div>This exposed what I think is a bug in deb822.Deb822: in python 2, I cannot load a sequence (dictionary) in one encoding and dump it into a different encoding. This works fine in python3. The difference is that keys are internally stored as text both in PY2 and PY3, but they mean different things. In PY3, text means unicode, so the original encoding is irrelevant. In PY2, text means binary (in PY3 parlance), and the original encoding is relevant.</div><div><br></div><div>To simplify the problem, I will only use the first offending letter of the file that has problems, <span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">í (\xed in iso-8859-1). Here is my test script:</span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><div>from debian import deb822</div><div><br></div><div>obj = deb822.Deb822({'\xed': 'i'}, encoding='iso-8859-1')</div><div>print(obj.dump(encoding='utf-8'))</div><div><br></div><div><br></div><div>Running it in python3:</div><div><br></div><div><div>python3.6 test.py </div><div>í: i</div></div><div><br></div></span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Running it in python 2.7:</span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">python2.7 test.py<br></span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">...</span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><div>UnicodeDecodeError: 'ascii' codec can't decode byte 0xed in position 0: ordinal not in range(128)</div><div><br></div><div>Another bug in PY2 is related to the implementation of __str__: it should return a string object, but self.dump() returns Unicode.</div><div><br></div><div>The attached patch fixes both of those problems.</div><div><br></div><div>I will be happy to write a test but I wanted to get some feedback about the correctness of the patch first.</div><div><br></div><div>There are also a lot of unreleased patches in git, and it would be nice if they were tagged as a release.</div><div><br></div><div>If there is a process I need to follow in order to submit the patch (i.e. for a repo, sign a contributor agreement etc) please let me know and I will do that too.</div><div><br></div><div>Thanks!</div><div>Mihai</div></span></div></div>