New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode filenames #122

Closed
sindikat opened this Issue Jun 26, 2013 · 1 comment

Comments

2 participants
@sindikat

sindikat commented Jun 26, 2013

Image(filename='Барлық және тең.jpg') works as intended - it operates on file with Unicode characters in their filenames cleanly. Image(filename=u'Барлық және тең.jpg') throws the following error:

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sindikat/dev/misc/a.py", line 3, in <module>
    with Image(filename=u'Барлық және тең.jpg') as img:
  File "/usr/local/lib/python2.7/dist-packages/wand/image.py", line 1699, in __init__
    self.read(filename=filename, resolution=resolution)
  File "/usr/local/lib/python2.7/dist-packages/wand/image.py", line 1752, in read
    r = library.MagickReadImage(self.wand, binary(filename))
  File "/usr/local/lib/python2.7/dist-packages/wand/compat.py", line 44, in binary
    return string.encode()
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-11: ordinal not in range(128)

Should the string return string.encode() be replaced with something like return string.encode(sys.getfilesystemencoding()), so that the constructor Image could support Unicode filenames?

Also save() method of class Image throw the same error:

>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sindikat/dev/misc/a.py", line 4, in <module>
    img.save(filename=u'Барлық және тең2.jpg')
  File "/usr/local/lib/python2.7/dist-packages/wand/image.py", line 1926, in save
    filename = binary(filename)
  File "/usr/local/lib/python2.7/dist-packages/wand/compat.py", line 44, in binary
    return string.encode()
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-11: ordinal not in range(128)
@dahlia

This comment has been minimized.

Collaborator

dahlia commented Jun 26, 2013

You are right, though it seems to have to be fixed in Image.read() method instead of binary() function.

@ghost ghost assigned dahlia Jun 26, 2013

@dahlia dahlia closed this in 2855254 Jul 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment