commit 94ead41b4c7e683d3e4d52c5feab410c9c21d06b
parent 9581a7f57e7bd20274d262f0c27fd4273888f729
Author: Eric Davis <edavis@insanum.com>
Date: Wed, 2 Jul 2014 14:03:47 -0700
don't unicode something that is already unicode, yeah unicode is a verb
Diffstat:
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/simplenote.py b/simplenote.py
@@ -131,9 +131,16 @@ def update_note(self, note):
"""
# use UTF-8 encoding
- note["content"] = unicode(note["content"], 'utf-8')
- if "tags" in note:
- note["tags"] = [unicode(t, 'utf-8') for t in note["tags"]]
+ # cpbotha: in both cases check if it's not unicode already
+ # otherwise you get "TypeError: decoding Unicode is not supported"
+ if isinstance(note["content"], str):
+ note["content"] = unicode(note["content"], 'utf-8')
+
+ if note.has_key("tags"):
+ # if a tag is a string, unicode it, otherwise pass it through
+ # unchanged (it's unicode already)
+ # using the ternary operator, because I like it: a if test else b
+ note["tags"] = [unicode(t, 'utf-8') if isinstance(t, str) else t for t in note["tags"]]
# determine whether to create a new note or updated an existing one
if "key" in note: