diff options
author | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2013-09-10 08:50:01 +0000 |
---|---|---|
committer | willmcgugan@gmail.com <willmcgugan@gmail.com@67cdc799-7952-0410-af00-57a81ceafa0f> | 2013-09-10 08:50:01 +0000 |
commit | 0aff6f126334f26423502977f9a70d008c14828a (patch) | |
tree | 3cdf09dd742bb4a11077b15589937236713fe265 | |
parent | 9274820511013c48b45a6654f76c5360f72f3551 (diff) | |
download | pyfilesystem-0aff6f126334f26423502977f9a70d008c14828a.tar.gz |
Allow unicode conversion for errors containing non-ascii strings.
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@877 67cdc799-7952-0410-af00-57a81ceafa0f
-rw-r--r-- | fs/errors.py | 8 | ||||
-rw-r--r-- | fs/tests/test_errors.py | 6 |
2 files changed, 13 insertions, 1 deletions
diff --git a/fs/errors.py b/fs/errors.py index 076de4b..3528e2f 100644 --- a/fs/errors.py +++ b/fs/errors.py @@ -39,6 +39,7 @@ __all__ = ['FSError', import sys import errno +import six from fs.path import * from fs.local_functools import wraps @@ -63,7 +64,12 @@ class FSError(Exception): return str(self.msg % keys) def __unicode__(self): - return unicode(self.msg) % self.__dict__ + keys = {} + for k,v in self.__dict__.iteritems(): + if isinstance(v, six.binary_type): + v = v.decode(sys.getfilesystemencoding(), errors='replace') + keys[k] = v + return unicode(self.msg, encoding=sys.getfilesystemencoding(), errors='replace') % keys def __reduce__(self): return (self.__class__,(),self.__dict__.copy(),) diff --git a/fs/tests/test_errors.py b/fs/tests/test_errors.py index 2b2fa64..51d0262 100644 --- a/fs/tests/test_errors.py +++ b/fs/tests/test_errors.py @@ -1,3 +1,4 @@ +# -*- encoding: utf-8 -*- """ fs.tests.test_errors: testcases for the fs error classes functions @@ -24,3 +25,8 @@ class TestErrorPickling(unittest.TestCase): assert_dump_load(UnsupportedError("makepony")) +class TestFSError(unittest.TestCase): + + def test_unicode_representation_of_error_with_non_ascii_characters(self): + path_error = PathError('/Shïrê/Frødø') + _ = unicode(path_error)
\ No newline at end of file |