Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix key type of Image.metadata to str in Py3

  • Loading branch information...
commit 11235ee204a48e060498e63a9171c55c1ba808d4 1 parent 2855254
@dahlia authored
Showing with 7 additions and 3 deletions.
  1. +2 −0  docs/changes.rst
  2. +3 −1 tests/image_test.py
  3. +2 −2 wand/image.py
View
2  docs/changes.rst
@@ -7,6 +7,8 @@ Version 0.3.2
To be released.
- Fix incorrect encoding of filenames. [:issue:`122`]
+- Fix key type of :attr:`Image.metadata <wand.image.Image.metadata>`
+ dictionary to :class:`str` from :class:`bytes` in Python 3.
Version 0.3.1
View
4 tests/image_test.py
@@ -10,7 +10,7 @@
from wand.image import ClosedImageError, Image
from wand.color import Color
-from wand.compat import PY3, text, text_type
+from wand.compat import PY3, text, text_type, string_type
from wand.exceptions import MissingDelegateError
from wand.font import Font
@@ -923,6 +923,8 @@ def test_metadata(fx_asset):
"""Test metadata api"""
with Image(filename=str(fx_asset.join('beach.jpg'))) as img:
assert 52 <= len(img.metadata) <= 55
+ for key in img.metadata:
+ assert isinstance(key, string_type)
assert 'exif:ApertureValue' in img.metadata
assert 'exif:UnknownValue' not in img.metadata
assert img.metadata['exif:ApertureValue'] == '192/32'
View
4 wand/image.py
@@ -2259,7 +2259,7 @@ def __getitem__(self, k):
"""
image = self.image
if not isinstance(k, string_type):
- raise TypeError('k must be a string, not ' + repr(format))
+ raise TypeError('k must be a string, not ' + repr(k))
v = library.MagickGetImageProperty(image.wand, binary(k))
if bool(v) is False:
raise KeyError(k)
@@ -2270,7 +2270,7 @@ def __iter__(self):
image = self.image
num = ctypes.c_size_t()
props_p = library.MagickGetImageProperties(image.wand, b'', num)
- props = [props_p[i] for i in xrange(num.value)]
+ props = [text(props_p[i]) for i in xrange(num.value)]
library.MagickRelinquishMemory(props_p)
return iter(props)
Please sign in to comment.
Something went wrong with that request. Please try again.