Commit 87a41f8a authored by Bram Schoenmakers's avatar Bram Schoenmakers

Decode todo items to Unicode internally.

Quite a puzzle to get this right for Python 2 and 3 simultaneously...
parent 5e4c2e48
#-*- coding: utf-8 -*-
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
......@@ -23,7 +25,12 @@ class TodoFileTest(TopydoTest):
def test_empty_file(self):
todofile = load_file('test/data/TodoFileTest1.txt')
self.assertEquals(len(todofile), 0)
self.assertEqual(len(todofile), 0)
def test_utf_8(self):
todofile = load_file('test/data/utf-8.txt')
self.assertEqual(todofile[0].source(), u'(C) ► UTF-8 test ◄' )
if __name__ == '__main__':
unittest.main()
(C) ► UTF-8 test ◄
......@@ -18,6 +18,8 @@
This module deals with todo.txt files.
"""
import codecs
class TodoFile(object):
"""
This class represents a todo.txt file, which can be read from or written
......@@ -31,7 +33,7 @@ class TodoFile(object):
""" Reads the todo.txt file and returns a list of todo items. """
todos = []
try:
todofile = open(self.path, 'r')
todofile = codecs.open(self.path, 'r', encoding="utf-8")
todos = todofile.readlines()
todofile.close()
except IOError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment