Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit a7fd421

Browse files
committed
Fixed broken encoding of non-latin characters. Fixes #32
The server incorrectly encodes unicode characters in its responses, causing mojibake when we try to output them. This may happen with folder names or hostnames, so we need to fix the encoding on those before continuing.
1 parent e529ee0 commit a7fd421

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

btsyncindicator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ def check_status(self):
310310

311311
status = response.json()
312312

313+
for folder in status['folders']:
314+
folder['name'] = self.fix_encoding(folder['name'])
315+
for peer in folder['peers']:
316+
peer['status'] = self.fix_encoding(peer['status'])
317+
313318
self.check_activity(status['folders'])
314319

315320
curfoldernames = [ folder['name'] for folder in self.status['folders'] ]
@@ -635,6 +640,9 @@ def get_response_text(self, response):
635640
"""
636641
return response.text if hasattr(response, "text") else response.content
637642

643+
def fix_encoding(self, text):
644+
return text.encode('latin-1').decode('utf-8')
645+
638646
def main(self):
639647
gtk.timeout_add(TIMEOUT * 1000, self.setup_session)
640648
gtk.main()

0 commit comments

Comments
 (0)