Commits

Jun Omae committed e7270ee

1.1.2dev: merge [12054] from 1.0-stable (refs #11272)

  • Participants
  • Parent commits 430c2cf

Comments (0)

Files changed (3)

File trac/util/tests/text.py

 # individuals. For the exact contribution history, see the revision
 # history and logs, available at http://trac.edgewall.org/log/.
 
+import os
 import unittest
 from StringIO import StringIO
 
 class ToUnicodeTestCase(unittest.TestCase):
     def test_explicit_charset(self):
         uc = to_unicode('\xc3\xa7', 'utf-8')
-        assert isinstance(uc, unicode)
+        self.assertTrue(isinstance(uc, unicode))
         self.assertEquals(u'\xe7', uc)
 
     def test_explicit_charset_with_replace(self):
         uc = to_unicode('\xc3', 'utf-8')
-        assert isinstance(uc, unicode)
+        self.assertTrue(isinstance(uc, unicode))
         self.assertEquals(u'\xc3', uc)
 
     def test_implicit_charset(self):
         uc = to_unicode('\xc3\xa7')
-        assert isinstance(uc, unicode)
+        self.assertTrue(isinstance(uc, unicode))
         self.assertEquals(u'\xe7', uc)
 
     def test_from_exception_using_unicode_args(self):
         except ValueError, e:
             self.assertEquals(u, to_unicode(e))
 
+    def test_from_windows_error(self):
+        try:
+            os.stat('non/existent/file.txt')
+        except OSError, e:
+            uc = to_unicode(e)
+            self.assertTrue(isinstance(uc, unicode), uc)
+            self.assertTrue(uc.startswith('[Error '), uc)
+            self.assertTrue(e.strerror.decode('mbcs') in uc, uc)
+
+    if os.name != 'nt':
+        del test_from_windows_error
+
 
 class ExpandtabsTestCase(unittest.TestCase):
     def test_empty(self):

File trac/util/text.py

         except UnicodeDecodeError:
             return unicode(text, 'latin1')
     elif isinstance(text, Exception):
+        from trac.util import WindowsError
+        if isinstance(text, WindowsError):
+            # the exception has a string encoded with ANSI codepage if an
+            # WindowsError
+            try:
+                return unicode(str(text), 'mbcs')
+            except UnicodeError:
+                pass
         # two possibilities for storing unicode strings in exception data:
         try:
             # custom __str__ method on the exception (e.g. PermissionError)

File tracopt/perm/authz_policy.py

             os.stat(authz_file)
         except OSError, e:
             self.log.error("Error parsing authz permission policy file: %s",
-                           to_unicode(e.strerror + ' ' + e.filename))
+                           to_unicode(e))
             raise ConfigurationError()
         return authz_file