From 1aafb0777c7b1678d46e471ee48b12c733ce34f0 Mon Sep 17 00:00:00 2001 From: Erich Seifert Date: Tue, 7 Jun 2016 17:12:28 +0200 Subject: [PATCH] Fix storing changes in WikiPage for Python3 WikiPage.store() method should call str.encode() after replacing newline characters. Otherwise, under Python 3 it will fail with TypeError: 'str' does not support the buffer interface --- markwiki/wiki.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/markwiki/wiki.py b/markwiki/wiki.py index 6424cea..d14e291 100644 --- a/markwiki/wiki.py +++ b/markwiki/wiki.py @@ -77,8 +77,10 @@ def store(self, content): try: with open(self.wiki_path, 'wb') as wiki: - # get rid of any Windows-like ending - wiki.write(content.encode('utf-8').replace('\r\n', '\n')) + # get rid of any Windows-like or MacOS-like line breaks + normalized_content = content.replace('\r\n', '\n') + normalized_content = normalized_content.replace('\r', '\n') + wiki.write(normalized_content.encode('utf-8')) except IOError: # Something bad happened while writing so report failure. return False