diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2011-08-01 21:15:41 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2011-08-01 21:15:41 +0200 |
commit | f8122b779610113b3c568ca9320dedf682c109a6 (patch) | |
tree | 03189d82ae9ada34656e0b9593d2f488639af74a | |
parent | 4daceb8502489a56db1eb8159a88f3f23f33949f (diff) | |
parent | b417529c0c977f8b27eb0d2ec4b734514a15eea0 (diff) | |
download | pyexiv2-f8122b779610113b3c568ca9320dedf682c109a6.tar.gz |
Do not try (and fail!) to encode non-unicode filenames.
-rw-r--r-- | src/pyexiv2/metadata.py | 2 | ||||
-rw-r--r-- | test/encoding.py | 14 |
2 files changed, 11 insertions, 5 deletions
diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py index 8a76381..57c0263 100644 --- a/src/pyexiv2/metadata.py +++ b/src/pyexiv2/metadata.py @@ -60,7 +60,7 @@ class ImageMetadata(MutableMapping): :type filename: string """ self.filename = filename - if filename is not None: + if filename is not None and isinstance(filename, unicode): self.filename = filename.encode(sys.getfilesystemencoding()) self.__image = None self._keys = {'exif': None, 'iptc': None, 'xmp': None} diff --git a/test/encoding.py b/test/encoding.py index 9cc251f..f82d3ac 100644 --- a/test/encoding.py +++ b/test/encoding.py @@ -91,18 +91,24 @@ class TestEncodings(unittest.TestCase): m.read() os.remove(filename) - def test_ascii_str(self): + def test_ascii(self): self._test_filename('test.jpg') - def test_ascii_unicode(self): + def test_latin1(self): + self._test_filename('tést.jpg') + + def test_latin1_escaped(self): + self._test_filename('t\xc3\xa9st.jpg') + + def test_unicode_ascii(self): if self.encoding is not None: self._test_filename(u'test.jpg') - def test_nonascii_unicode(self): + def test_unicode_latin1(self): if self.encoding is not None: self._test_filename(u'tést.jpg') - def test_nonascii_unicode_escaped(self): + def test_unicode_latin1_escaped(self): if self.encoding is not None: self._test_filename(u't\xe9st.jpg') |