pysqlite do not accept "strings" from GnuPG
Few days ago Gajim started to drop some messages from my friend. What was really strange was that only his messages have been dropped. It's happened so because he was the only who wrote me in Polish (using some diacritics) and encrypted it with GnuPG. Tracebacks lookt like this like this:
Traceback (most recent call last): File "gajim.py", line 449, in _process_events return self.process_events(fd, flags) File "/usr/lib64/python2.6/site-packages/gajim/common/xmpp/idlequeue.py", line 132, in process_event s obj.pollin() File "/usr/lib64/python2.6/site-packages/gajim/common/xmpp/transports_nb.py", line 352, in pollin self._do_receive() File "/usr/lib64/python2.6/site-packages/gajim/common/xmpp/transports_nb.py", line 502, in _do_recei ve self.on_receive(received) File "/usr/lib64/python2.6/site-packages/gajim/common/xmpp/dispatcher_nb.py", line 359, in dispatch handler['func'](session,stanza) File "/usr/lib64/python2.6/site-packages/gajim/common/connection_handlers.py", line 1825, in _messag eCB session.received(frm, msgtxt, tim, encrypted, msg) File "/usr/lib64/python2.6/site-packages/gajim/session.py", line 121, in received msgtxt, tim=tim, subject=subject) File "/usr/lib64/python2.6/site-packages/gajim/common/logger.py", line 476, in write return self.commit_to_db(values, write_unread) File "/usr/lib64/python2.6/site-packages/gajim/common/logger.py", line 342, in commit_to_db raise exceptions.DatabaseMalformed common.exceptions.DatabaseMalformed: Baza danych nie może zostać odczytana. (pol. Database cannot be read)
After I've had removed except/raise I received a bit more verbose message at the bottom:
sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can in terpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just sw itch your application to Unicode strings.
This originated at pysqlite_statement_bind_parameter where a type of a parameter is checked. pysqlite rises exception when the parameter is a string and contains bytes >= 0x80. This occurs when Gajim tries to log a decrypted message that contains unicode charaters and came from GnuPG because GnuPG.decrypt returns a string not a unicode.
The most obvious solution is to call unicode() before returning the decrypted message. However, I am not sure about the encodig. On the other hand it SHOULD or even MUST be UTF-8 since it is XMPP. So my guess is to change gnupg.py:127 to
return unicode(output, "UTF-8")
It worked for me.
PS. Let the above be my patch and let me refrain from installing yet another VC toolbox ;-)