summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-02-18 00:28:03 +0100
committerGeorg Brandl <georg@python.org>2010-02-18 00:28:03 +0100
commit1d11ec72ea2dcb59204c7190544bf9071b4d03be (patch)
treee2ff9c76aa58811d289a9005fdcbff39b9e508a7
parent8c8a5ba6269e3f9c9cf535d87611d8b71d6e6658 (diff)
downloadpygments-1d11ec72ea2dcb59204c7190544bf9071b4d03be.tar.gz
Fix opening unicode file under Py3k.
-rw-r--r--pygments/util.py4
-rw-r--r--tests/test_html_formatter.py6
2 files changed, 8 insertions, 2 deletions
diff --git a/pygments/util.py b/pygments/util.py
index fc65b676..1bd1455f 100644
--- a/pygments/util.py
+++ b/pygments/util.py
@@ -8,8 +8,10 @@
:copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
+
import re
import sys
+import codecs
split_path_re = re.compile(r'[/\\ ]')
@@ -206,6 +208,7 @@ if sys.version_info < (3,0):
import StringIO, cStringIO
BytesIO = cStringIO.StringIO
StringIO = StringIO.StringIO
+ uni_open = codecs.open
else:
import builtins
bytes = builtins.bytes
@@ -220,3 +223,4 @@ else:
import io
BytesIO = io.BytesIO
StringIO = io.StringIO
+ uni_open = builtins.open
diff --git a/tests/test_html_formatter.py b/tests/test_html_formatter.py
index 9ff593f9..ae54b919 100644
--- a/tests/test_html_formatter.py
+++ b/tests/test_html_formatter.py
@@ -12,17 +12,19 @@ import re
import unittest
import StringIO
import tempfile
-from os.path import join, dirname, isfile, abspath
+from os.path import join, dirname, isfile
from pygments.lexers import PythonLexer
from pygments.formatters import HtmlFormatter, NullFormatter
from pygments.formatters.html import escape_html
+from pygments.util import uni_open
import support
TESTFILE, TESTDIR = support.location(__file__)
-tokensource = list(PythonLexer(encoding='utf-8').get_tokens(open(TESTFILE).read()))
+tokensource = list(PythonLexer().get_tokens(
+ uni_open(TESTFILE, encoding='utf-8').read()))
class HtmlFormatterTest(unittest.TestCase):