[Vobject] commas in structured fields
Bob Kline
bkline at rksystems.com
Fri Jan 28 12:38:28 CST 2011
I've stumbled on a problem with commas in structured vcard fields. If I
supply a comma to an unstructured field's value (for example, FN), the
module escapes the comma as expected when serializing the card object:
>>> card = vobject.vCard()
>>> card.add('fn').value = 'Larry, Moe, and Curly Stooge'
>>> card.add('n').value = vobject.vcard.Name('Stooge', 'Larry Moe and
Curly')
>>> print card.serialize()
BEGIN:VCARD
VERSION:3.0
FN:Larry\, Moe\, and Curly Stooge
N:Stooge;Larry Moe and Curly;;;
END:VCARD
However, if I do the same thing in one of the strings for the Name
constructor, a ParseError exception is thrown when I try to serialize
the card object. Continuing with the example above:
>>> card.n.value = vobject.vcard.Name('Stooge', 'Larry, Moe, and Curly')
>>> card.serialize()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/vobject/base.py", line 186, in
serialize
return behavior.serialize(self, buf, lineLength, validate)
File "/usr/lib/pymodules/python2.6/vobject/behavior.py", line 157, in
serialize
out = base.defaultSerialize(transformed, buf, lineLength)
File "/usr/lib/pymodules/python2.6/vobject/base.py", line 947, in
defaultSerialize
child.serialize(outbuf, lineLength, validate=False)
File "/usr/lib/pymodules/python2.6/vobject/base.py", line 186, in
serialize
return behavior.serialize(self, buf, lineLength, validate)
File "/usr/lib/pymodules/python2.6/vobject/behavior.py", line 158, in
serialize
if undoTransform: obj.transformToNative()
File "/usr/lib/pymodules/python2.6/vobject/base.py", line 122, in
transformToNative
return self.behavior.transformToNative(self)
File "/usr/lib/pymodules/python2.6/vobject/vcard.py", line 247, in
transformToNative
obj.value = Name(**dict(zip(NAME_ORDER, splitFields(obj.value))))
File "/usr/lib/pymodules/python2.6/vobject/vcard.py", line 213, in
splitFields
stringToTextValues(string, listSeparator=';', charList=';')]
File "/usr/lib/pymodules/python2.6/vobject/icalendar.py", line 1681,
in stringToTextValues
raise ParseError("error: illegal escape sequence: '\\%s'" % (char,))
vobject.base.ParseError: "error: illegal escape sequence: '\\,'"
Escaping the commas myself doesn't help: then I get a ParseError
complaining about the escape sequence '\\\\':
>>> card.n.value = vobject.vcard.Name('Stooge', 'Larry\, Moe\, and Curly')
>>> card.serialize()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/vobject/base.py", line 186, in
serialize
return behavior.serialize(self, buf, lineLength, validate)
File "/usr/lib/pymodules/python2.6/vobject/behavior.py", line 157, in
serialize
out = base.defaultSerialize(transformed, buf, lineLength)
File "/usr/lib/pymodules/python2.6/vobject/base.py", line 947, in
defaultSerialize
child.serialize(outbuf, lineLength, validate=False)
File "/usr/lib/pymodules/python2.6/vobject/base.py", line 186, in
serialize
return behavior.serialize(self, buf, lineLength, validate)
File "/usr/lib/pymodules/python2.6/vobject/behavior.py", line 158, in
serialize
if undoTransform: obj.transformToNative()
File "/usr/lib/pymodules/python2.6/vobject/base.py", line 122, in
transformToNative
return self.behavior.transformToNative(self)
File "/usr/lib/pymodules/python2.6/vobject/vcard.py", line 247, in
transformToNative
obj.value = Name(**dict(zip(NAME_ORDER, splitFields(obj.value))))
File "/usr/lib/pymodules/python2.6/vobject/vcard.py", line 213, in
splitFields
stringToTextValues(string, listSeparator=';', charList=';')]
File "/usr/lib/pymodules/python2.6/vobject/icalendar.py", line 1681,
in stringToTextValues
raise ParseError("error: illegal escape sequence: '\\%s'" % (char,))
vobject.base.ParseError: "error: illegal escape sequence: '\\\\'"
Why aren't the two types of string values treated the same way?
--
Bob Kline
http://www.rksystems.com
mailto:bkline at rksystems.com
More information about the VObject
mailing list