diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2007-03-27 20:20:42 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2007-03-27 20:20:42 +0200 |
commit | f3bbb762f758aa21f0bb2d321e4d26de064068e0 (patch) | |
tree | 67a78c425f73a03cd3141cb2dd8efb77ad3342cf | |
parent | bbe0a2e95843cd223abb5811bb1232aaf6074479 (diff) | |
download | pyexiv2-f3bbb762f758aa21f0bb2d321e4d26de064068e0.tar.gz |
Internal accessor __setitem__ now handles tuples to be consistent with __getitem__ when dealing with repeatable IPTC tags (but passing it a list of values will also work, the list being internally converted into a tuple).
-rw-r--r-- | src/pyexiv2.py | 21 | ||||
-rw-r--r-- | todo | 1 |
2 files changed, 13 insertions, 9 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py index b1dd88f..5d04524 100644 --- a/src/pyexiv2.py +++ b/src/pyexiv2.py @@ -493,25 +493,30 @@ class Image(libpyexiv2.Image): elif tagFamily == 'Iptc': # The case of IPTC tags is a bit trickier since some tags are # repeatable. To simplify the process, parameter 'value' is - # transformed into a list if it is not already one and then each of + # transformed into a tuple if it is not already one and then each of # its values is processed (set, that is) in a loop. newValues = value if newValues is None: # Setting the value to None does not really make sense, but can # in a way be seen as equivalent to deleting it, so this # behaviour is simulated by providing an empty list for 'value'. - newValues = [] - if newValues.__class__ is not list: - newValues = [newValues] + newValues = () + if newValues.__class__ is not tuple: + if newValues.__class__ is list: + # For flexibility, passing a list instead of a tuple works + newValues = tuple(newValues) + else: + # Interpret the value as a single element + newValues = (newValues,) try: oldValues = self.__iptcTagsDict[key] - if oldValues.__class__ is not list: - oldValues = [oldValues] + if oldValues.__class__ is not tuple: + oldValues = (oldValues,) except KeyError: # The tag is not set yet - oldValues = [] + oldValues = () # This loop processes the values one by one. There are n cases: - # * if the two lists are of the exact same size, each item in + # * if the two tuples are of the exact same size, each item in # oldValues is replaced by its new value in newValues; # * if newValues is longer than oldValues, each item in oldValues # is replaced by its new value in newValues and the new items @@ -1,6 +1,5 @@ todo list -- Fix the issue when changing one value inside a list returned by image[key]: the value is changed in the internal dictionnary but no call to setIptcTagValue() is performed -> use tuples instead of lists, tuples are immutables - Disable the get...() and set...() methods (by making them private) -> metadata is accessible only through the dictionnary metaphor - Write methods cacheAllExifTags() and cacheAllIptcTags() that will read and cache all the tag values (to be used in a separate threads, for applications that need to access all the tags anyway) - Rewrite the exiv2 command-line tool and the test binaries in Python and (Python) scripts to run the same tests that are run to test exiv2 |