From fe8360e25afc60f6288470b88cdbccde61f265f3 Mon Sep 17 00:00:00 2001 From: Sean Brant Date: Sat, 13 Jul 2013 11:00:01 -0500 Subject: Closes #5. Now opens files using utf-8. --- pykss/comment.py | 3 ++- tests/fixtures/comments.txt | 6 ++++++ tests/test_comment.py | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pykss/comment.py b/pykss/comment.py index e416e4b..20d4e63 100644 --- a/pykss/comment.py +++ b/pykss/comment.py @@ -1,3 +1,4 @@ +import codecs import re @@ -63,7 +64,7 @@ class CommentParser(object): inside_single_line_block = False inside_multi_line_block = False - with open(self.filename) as fileobj: + with codecs.open(self.filename, 'r', 'utf-8') as fileobj: for line in fileobj: # Parse single-line style if is_single_line_comment(line): diff --git a/tests/fixtures/comments.txt b/tests/fixtures/comments.txt index 885887c..389ff6d 100644 --- a/tests/fixtures/comments.txt +++ b/tests/fixtures/comments.txt @@ -40,3 +40,9 @@ Comment with example: *
* */ + + +Comment with non ASCII: + +/* Hello, 世界 + */ diff --git a/tests/test_comment.py b/tests/test_comment.py index e1e94c6..81824eb 100644 --- a/tests/test_comment.py +++ b/tests/test_comment.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import os import unittest @@ -73,3 +75,6 @@ This comment has a indented example """ self.assertTrue(expected.strip() in self.comments) + + def test_handles_unicode_in_comments(self): + self.assertTrue(u'Hello, 世界' in self.comments) -- cgit v1.2.3