nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit d1f99547946833e5a1849e8dfb39b7604803e2c7
parent 01994ae17547b579b6265184462ce042bf87c6e1
Author: Shawn Axsom <shawn.axsom@rooksecurity.com>
Date:   Sat, 25 Apr 2015 17:54:38 -0400

Encode unicode characters as UTF-8, since tempfile library doesn't support standard unicode characters

Diffstat:
M.gitignore | 1+
Msimplenote_cli/sncli.py | 8++++++--
Msimplenote_cli/temp.py | 7++++++-
3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,2 +1,3 @@ *.pyc .ropeproject +env diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -639,8 +639,8 @@ def gui_frame_keypress(self, size, key): if not content: return None - md5_old = md5.new(note['content']).digest() - md5_new = md5.new(content).digest() + md5_old = md5.new(self.encode_utf_8(note['content'])).digest() + md5_new = md5.new(self.encode_utf_8(content)).digest() if md5_old != md5_new: self.log(u'Note updated') @@ -852,6 +852,10 @@ def gui_frame_keypress(self, size, key): self.gui_update_status_bar() return None + def encode_utf_8(self, string): + # This code also exists in temp.py. Move into an encoding or utility class if other areas need encoding. + return string.encode("utf-8") if isinstance(string, unicode) else string + def gui_init_view(self, loop, view_note): self.master_frame.keypress = self.gui_frame_keypress self.gui_body_set(self.view_titles) diff --git a/simplenote_cli/temp.py b/simplenote_cli/temp.py @@ -18,10 +18,15 @@ def tempfile_create(note, raw=False): ext = '.mkd' tf = tempfile.NamedTemporaryFile(suffix=ext, delete=False) if note: - tf.write(note['content']) + contents = note['content'] + tf.write(encode_utf_8(contents)) tf.flush() return tf +def encode_utf_8(string): + # This code also exists in sncli.py. Move into an encoding or utility class if other areas need encoding. + return string.encode("utf-8") if isinstance(string, unicode) else string + def tempfile_delete(tf): if tf: os.unlink(tf.name)