Pull requests

#6 Declined
Repository
Dolda2000 Dolda2000
Branch
master
Repository
zzzeek zzzeek
Branch
master

Fixed Python3 bug in filters.Decode.

Author
  1. Dolda2000
Reviewers
Description

filters.Decode fails on non-str, non-bytes objects in Python3 because it converts them to str, and then tries to byte-decode them. This patch fixes this, though perhaps there may be some more elegant way of doing it.

  • Learn about pull requests

Comments (4)

  1. Dolda2000 author

    I see. I considered that way but opted against it myself since it does not decode Python2 objects using the intended encoding. For instance:

    >>> class a(object):
    ...     def __init__(self, s):
    ...             self.s = s
    ...     def __str__(self):
    ...             return self.s
    ... 
    >>> unicode(a("å"))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
    

    Whereas previously, decode.utf8(a("å")) would have converted without error when the byte-string is UTF-8 encoded. Maybe that's not actually a problem, but I was thinking it could break something. :)