-
Notifications
You must be signed in to change notification settings - Fork 21
Adds option to override the theme's icons through monochrome icons and fixes string encoding issues #25
Adds option to override the theme's icons through monochrome icons and fixes string encoding issues #25
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,33 @@ | |
import time | ||
from libzotero.zotero_item import zoteroItem as zotero_item | ||
|
||
def decode_zotero_str(raw, max_iters=3): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me, this completely breaks the PDF attachments. This appears to be due to my own weird way of trying to fix the encoding. If I comment the line below out (from
However, the fact that a patch that for you seems to fix things, breaks things for me makes me a bit worried. On what operating system do you work? It's not unthinkable that the encoding differs between operating systems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm on Linux. I have that fork running on 3 different systems,
What operating system are you on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm on Ubuntu 16.04.
What makes you think this? Is this a conclusion based on the fact the decoding multiple times resolves the encoding issues, at least in some cases? Or is it a known bug in the Zotero code? I'll think about this. The combination of my odd hack (clearly dating from before understood how encoding really works) and your fix is nonsensical; but it may be that your fix on its own is correct. But I'd like to do some more tests before I push another fix that actually doesn't fix things. (As you may have noticed, I don't have that much time to work Qnotero anymore. But I'll get to it!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds very reasonable! To answer your question: My fix was based on the observation that Zotero encoded In [14]: '\xc3\x83\xc2\x96\x66'.decode('utf-8')
Out[14]: u'\xc3\x96f' Turns out, that Update: In an earlier version of this, I miscounted the number of bytes in the exemplary sequence and wrote that it were 4, although it are 5. |
||
|
||
""" | ||
Decodes a string from the Zotero database. | ||
|
||
There seems to be an issue with the way, Zotero encodes | ||
strings in its database: For some reason, Zotero encodes | ||
them *twice* with UTF-8, at least sometimes. This | ||
functions aims to decode such strings, even if they were | ||
encoded more than twice. | ||
|
||
For example, Zotero was observed to encode | ||
|
||
u'Öf' as b'\xc3\x83\xc2\x96\x66', | ||
|
||
which is the UTF-8 encoding for u'\xC3\x96f', where | ||
u'\xC3\x96' is *in turn* an UTF-8 representation of u'Ö'. | ||
""" | ||
|
||
result = str(raw, 'utf-8') | ||
for iter in range(max_iters): | ||
try: | ||
result = str(bytes([ord(c) for c in result]), 'utf-8') | ||
except: | ||
break | ||
return result | ||
|
||
class LibZotero(object): | ||
|
||
""" | ||
|
@@ -170,6 +197,7 @@ def update(self, force=False): | |
# Copy the zotero database to the gnotero copy | ||
shutil.copyfile(self.zotero_database, self.gnotero_database) | ||
self.conn = sqlite3.connect(self.gnotero_database) | ||
self.conn.text_factory = decode_zotero_str | ||
self.cur = self.conn.cursor() | ||
# First create a list of deleted items, so we can ignore those later | ||
deleted = [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other themes should be updated as well. Right now this breaks the chameleon theme.