Commits

Anonymous committed 3b6e15c

* HachoirError: use makePrintable() to convert 'str' to 'unicode' (instead of unicode() function)
* Fix ReadStreamError and NullStreamError: call parent constructor

  • Participants
  • Parent commits a43d05a

Comments (0)

Files changed (2)

File hachoir-core/hachoir_core/error.py

     """
     def __init__(self, message):
         if not isinstance(message, unicode):
-            message = unicode(message)
+            message = makePrintable(message, "ISO-8859-1", to_unicode=True)
         self.message = message
 
     def __str__(self):

File hachoir-core/hachoir_core/stream/input.py

         self.size = size
         self.address = address
         self.got = got
-
-    def __str__(self):
-        msg = "Can't read %u bits at address %u" % (self.size, self.address)
         if self.got is not None:
-            msg += " (got %u bits)" % self.got
-        return msg
+            msg = _("Can't read %u bits at address %u (got %u bits)") % (self.size, self.address, self.got)
+        else:
+            msg = _("Can't read %u bits at address %u") % (self.size, self.address)
+        InputStreamError.__init__(self, msg)
 
 class NullStreamError(InputStreamError):
     def __init__(self, source):
         self.source = source
-
-    def __str__(self):
-        return "Input size is nul (source='%s')!" % self.source
-
-
+        msg = _("Input size is nul (source='%s')!") % self.source
+        InputStreamError.__init__(self, msg)
 
 class FileFromInputStream:
     _offset = 0