pyexiv2-developers team mailing list archive
-
pyexiv2-developers team
-
Mailing list archive
-
Message #00019
Re: pyexiv2 0.2 testing
Sorry for all of the questions. As you've probably gathered I'm a
little clueless about the XMP spec...
> meta[key] always returns a {Exif,Iptc,Xmp}Tag object. That's a bit more code
> to write for application developers, but that's also much more flexible: a
> tag object contains more information than just a value.
I understand that evaluating meta[key] (i.e. using __getitem__),
should return a *Tag object. But...
(thinking out loud) I'm not sure why meta[key]=value (i.e.
__setitem__) shouldn't be interpretable as
meta[key]=*Tag(key,value). For example:
def __setitem__(self,key,value):
try:
#try setting the key assuming that value is a *Tag type
except TypeError:
tag_class=lookup_tag_type(key)
if value.__class__ != tag_class:
value=tag_class(key,value)
#try setting again
Is the issue that lookup_tag_type is expensive?
I agree that direct support for this is probably no big deal because I
can do what I need in helper functions.
> should I assume that the user wants
> to set the value, or the raw_value?
I guess always assume a value because that is how the *Tag __init__
call works right?
If someone wants to do something more complicated they can use the full idiom.
> if key in meta.xmp_keys:
> meta[key].value = value
> else:
> meta[key] = XmpTag(key, value)
I gather this is also true for exif and iptc keys? This is a break
from dictionary syntax, but I guess it makes sense that the user needs
to be explicit about adding new keys. (Again, not a big deal, but
something that wasn't immediately obvious). I guess I don't like the
redundancy of having to refer to the key twice when adding it (invites
someone to try: meta[key1]=XmpTag(key2,value)). A simple alternative
would be:
meta.add(XmpTag(key,value))
btw, setting the value property will update raw_value and vice versa right?
>> {'x-default': ['test2', 'test3']}
>> #works as expected
>
> Actually, it shouldn't. According to the XMP specification, the type of
> Xmp.dc.subject is "bag Text", meaning it expects a list of values, not a
> dictionary (it's not a LangAlt).
So for key=="Xmp.dc.subject" this should work:
meta[key]=XmpTag(key,['test2','test3'])
Please don't interpret these comments/questions as a request to change
anything. It's just taking a little bit to get my head around the new
API.
cheers,
Damien
Follow ups
References