pyfilesystem icon indicating copy to clipboard operation
pyfilesystem copied to clipboard

fs.errors.FSError(u'a unicode message').__unicode__() raises an exception

Open GoogleCodeExporter opened this issue 10 years ago • 0 comments

What steps will reproduce the problem?
Instantiate FSError with a unicode value for msg. Cause __unicode__() to be 
called on the instance.

What is the expected output? What do you see instead?
Expect to see the unicode representation of the error. Instead, it raises 
TypeError for trying to decode Unicode.

What version of the product are you using? On what operating system?
Mac OSX fs==0.5.0

Please provide any additional information below.

Fix is simple:

    def __unicode__(self):
        keys = {}
        for k,v in self.__dict__.iteritems():
            if isinstance(v, six.binary_type):
                v = v.decode(sys.getfilesystemencoding(), 'replace')
            keys[k] = v
        msg = self.msg
        # The next two lines fix the issue
        if isinstance(msg,unicode):
            msg = msg.encode(sys.getfilesystemencoding())
        return unicode(msg, encoding=sys.getfilesystemencoding(), errors='replace') % keys


Original issue reported on code.google.com by [email protected] on 12 Sep 2014 at 11:11

GoogleCodeExporter avatar Apr 11 '15 10:04 GoogleCodeExporter