1 new commit in py:

https://bitbucket.org/hpk42/py/changeset/4316a23e130d/
changeset:   4316a23e130d
user:        hpk42
date:        2012-10-22 11:52:09
summary:     try to make terminalwriter printing more robust against ascii files
affected #:  5 files

diff -r 7577a2cb47851104ce3400b639c4e6dbb6036e5d -r 
4316a23e130da1edcd9fd7c422030fd6e237a486 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,8 @@
 
 - fix an internal test to not use class-denoted pytest_funcarg__
 - fix a link to bug tracker
+- try to make terminal.write() printing more robust against
+  unicodeencode/decode problems, amend according test
 
 
 Changes between 1.4.9 and 1.4.10


diff -r 7577a2cb47851104ce3400b639c4e6dbb6036e5d -r 
4316a23e130da1edcd9fd7c422030fd6e237a486 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'
+__version__ = '1.4.11.dev1'
 
 from py import _apipkg
 


diff -r 7577a2cb47851104ce3400b639c4e6dbb6036e5d -r 
4316a23e130da1edcd9fd7c422030fd6e237a486 py/_io/terminalwriter.py
--- a/py/_io/terminalwriter.py
+++ b/py/_io/terminalwriter.py
@@ -162,7 +162,7 @@
 
     def write(self, s, **kw):
         if s:
-            if not isinstance(self._file, WriteFile):
+            if not isinstance(self._file, WriteFile) and not 
getattr(self._file, "encoding", None):
                 s = self._getbytestring(s)
                 if self.hasmarkup and kw:
                     s = self.markup(s, **kw)
@@ -172,7 +172,7 @@
     def _getbytestring(self, s):
         # XXX review this and the whole logic
         if sys.version_info[0] < 3 and isinstance(s, unicode):
-            return s.encode(self.encoding or "utf8")
+            return s.encode(self.encoding or "utf8", "replace")
         elif not isinstance(s, str):
             try:
                 return str(s)
@@ -236,7 +236,7 @@
 
     def write(self, data):
         if self.encoding:
-            data = data.encode(self.encoding)
+            data = data.encode(self.encoding, "replace")
         self._writemethod(data)
 
     def flush(self):


diff -r 7577a2cb47851104ce3400b639c4e6dbb6036e5d -r 
4316a23e130da1edcd9fd7c422030fd6e237a486 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',
+        version='1.4.11.dev1',
         url='http://pylib.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],


diff -r 7577a2cb47851104ce3400b639c4e6dbb6036e5d -r 
4316a23e130da1edcd9fd7c422030fd6e237a486 testing/io_/test_terminalwriter.py
--- a/testing/io_/test_terminalwriter.py
+++ b/testing/io_/test_terminalwriter.py
@@ -78,20 +78,24 @@
         tw.line(msg)
         assert l[0].strip() == msg.encode(encoding)
 
-def test_unicode_on_file_with_no_encoding(tmpdir, monkeypatch):
[email protected]("encoding", [None, "ascii"])
+def test_unicode_on_file_with_no_encoding(tmpdir, monkeypatch, encoding):
     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)
+    f = py.std.codecs.open(str(tmpdir.join("x")), "w", encoding, 
errors="replace")
     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")
+    if encoding is None:
+        assert s == msg.encode(f.encoding or "utf-8")
+    else:
+        assert s.decode(encoding) == '?l'
 
 class TestTerminalWriter:
     def pytest_generate_tests(self, metafunc):

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.
_______________________________________________
py-svn mailing list
[email protected]
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to