aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2011-08-01 10:52:30 +0200
committerOlivier Tilloy <olivier@tilloy.net>2011-08-01 10:52:30 +0200
commitb417529c0c977f8b27eb0d2ec4b734514a15eea0 (patch)
tree03189d82ae9ada34656e0b9593d2f488639af74a
parent4daceb8502489a56db1eb8159a88f3f23f33949f (diff)
downloadpyexiv2-b417529c0c977f8b27eb0d2ec4b734514a15eea0.tar.gz
Do not try (and fail!) to encode non-unicode filenames.
More complete unit tests.
-rw-r--r--src/pyexiv2/metadata.py2
-rw-r--r--test/encoding.py14
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')