[py-svn] commit/py: hpk42: default to utf8 when writing to terminal/file and no encoding can be determined
Bitbucket
commits-noreply at bitbucket.org
Thu Sep 20 10:56:50 CEST 2012
1 new commit in py:
https://bitbucket.org/hpk42/py/changeset/f60c108f78fd/
changeset: f60c108f78fd
user: hpk42
date: 2012-09-20 10:56:42
summary: default to utf8 when writing to terminal/file and no encoding can be determined
affected #: 5 files
diff -r 0fca612a4bbdb14513a2b014c8459e7859f2fbc7 -r f60c108f78fd973eb08e1933ff2130f339ea0dcf CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,9 @@
+Changes between 1.4.9 and 1.4.10.dev
+==================================================
+
+- terminalwriter: default to encode to UTF8 if no encoding is defined
+ on the output stream
+
Changes between 1.4.8 and 1.4.9
==================================================
diff -r 0fca612a4bbdb14513a2b014c8459e7859f2fbc7 -r f60c108f78fd973eb08e1933ff2130f339ea0dcf py/__init__.py
--- a/py/__init__.py
+++ b/py/__init__.py
@@ -8,7 +8,7 @@
(c) Holger Krekel and others, 2004-2010
"""
-__version__ = '1.4.10.dev1'
+__version__ = '1.4.10.dev2'
from py import _apipkg
diff -r 0fca612a4bbdb14513a2b014c8459e7859f2fbc7 -r f60c108f78fd973eb08e1933ff2130f339ea0dcf py/_io/terminalwriter.py
--- a/py/_io/terminalwriter.py
+++ b/py/_io/terminalwriter.py
@@ -171,8 +171,8 @@
def _getbytestring(self, s):
# XXX review this and the whole logic
- if self.encoding and sys.version_info[0] < 3 and isinstance(s, unicode):
- return s.encode(self.encoding)
+ if sys.version_info[0] < 3 and isinstance(s, unicode):
+ return s.encode(self.encoding or "utf8")
elif not isinstance(s, str):
try:
return str(s)
diff -r 0fca612a4bbdb14513a2b014c8459e7859f2fbc7 -r f60c108f78fd973eb08e1933ff2130f339ea0dcf setup.py
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@
name='py',
description='library with cross-python path, ini-parsing, io, code, log facilities',
long_description = open('README.txt').read(),
- version='1.4.10.dev1',
+ version='1.4.10.dev2',
url='http://pylib.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
diff -r 0fca612a4bbdb14513a2b014c8459e7859f2fbc7 -r f60c108f78fd973eb08e1933ff2130f339ea0dcf testing/io_/test_terminalwriter.py
--- a/testing/io_/test_terminalwriter.py
+++ b/testing/io_/test_terminalwriter.py
@@ -1,3 +1,5 @@
+# coding=utf8
+
import py
import os, sys
from py._io import terminalwriter
@@ -76,6 +78,21 @@
tw.line(msg)
assert l[0].strip() == msg.encode(encoding)
+def test_unicode_on_file_with_no_encoding(tmpdir, monkeypatch):
+ try:
+ bytes
+ except NameError:
+ bytes = str
+ msg = py.builtin._totext('öl', "utf8")
+ #pytest.raises(UnicodeEncodeError, lambda: bytes(msg))
+ f = py.std.codecs.open(str(tmpdir.join("x")), "w", None)
+ tw = py.io.TerminalWriter(f, encoding=None)
+ tw.encoding = None
+ tw.line(msg)
+ f.close()
+ s = tmpdir.join("x").open("rb").read().strip()
+ assert s == msg.encode("utf8")
+
class TestTerminalWriter:
def pytest_generate_tests(self, metafunc):
if "tw" in metafunc.funcargnames:
Repository URL: https://bitbucket.org/hpk42/py/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the pytest-commit
mailing list