[Vobject] difference between handling of 2.1 and 3.0
Jonathan Kaczynski
jmkacz at gmail.com
Fri Jan 9 13:25:54 CST 2009
I don't have a patch, but I do have some analysis. The following refers to
vobject/base.py.
def setBehaviorFromVersionLine(self, versionLine):
v=getBehavior(self.name, versionLine.value)
if v: self.setBehavior(v)
For a vcard that contains "VERSION:3.0", this sets the behavior to an
instance of vobject.vcard.VCard3_0.
For a vcard that contains "VERSION:2.1", this does not set the behavior
since, v is None.
Later, valueRepr (not used in v.n.family, for example, but it illustrates
the point) is called by prettyPrint:
def valueRepr( self ):
v = self.value
if self.behavior:
v = self.behavior.valueRepr( self )
return ascii( v )
For a vcard that contains "VERSION:3.0", and the content line name is FN,
behavior is an instance of vobject.vcard.FN.
For a vcard that contains "VERSION:3.0", and the content line name is N,
behavior is an instance of vobject.vcard.NameBehavior.
For a vcard that contains "VERSION:2.1", and the content line name is FN,
behavior is None.
For a vcard that contains "VERSION:2.1", and the content line name is N,
behavior is None.
Looking at how we retrieve a behavior:
def getBehavior(name, id=None):
name=name.upper()
if name in __behaviorRegistry:
if id:
for n, behavior in __behaviorRegistry[name]:
if n==id:
return behavior
else:
return __behaviorRegistry[name][0][1]
return None
'VCARD' is in the registry. The only entry in the list is for 3.0: [('3.0',
<class 'vobject.vcard.VCard3_0'>)]. The id that comes in, for a name of
VCARD, is the version; either 2.1 or 3.0. It then tries to match that
version in the list, but 2.1 does not exist in the list, so it returns None
in the end. So, it seems like the fallback behavior doesn't exist in this
method. Since this method is used for all behaviors (VCARD, N, FN, etc.), I
would be hesistant to make a blanket rule of picking the first one in the
list, if a match was not found.
What do you think?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.skyhouseconsulting.com/pipermail/vobject/attachments/20090109/71d594b6/attachment.htm
More information about the VObject
mailing list