3 def __init__(self, name):
4 self._attributes = { "fn": name }
5 self._multi_attributes = {}
11 return "Friend %s" % self._attributes['fn']
13 # public accessors -----------------
15 def add_url(self, url):
19 for a in self._attributes:
21 for a in self._multi_attributes:
25 def has_birthday_date(self):
26 return self._has('bday')
28 def set_name(self, name):
31 def set_nickname(self, nickname):
32 self._set('nickname', nickname)
34 def set_birthday_date(self, date):
35 self._set('bday', date)
37 def set_photo_url(self, url):
38 self._set('photo-url', url)
40 def update(self, other_friend):
42 Overwrites any attributes in this friend, with attributes from other_friend
45 self._attributes.update(other_friend._attributes)
47 for key in other_friend._multi_attributes.keys():
48 for value in other_friend._multi_attributes[key]:
51 def update_contact(self, contact, overwrite=False):
53 Updates the contact with information from this object,
54 without overwriting unless overwrite is set to True.
57 # FIXME: currently we overwrite everything
58 self._if_defined('photo-url', contact.set_photo)
59 self._if_defined('nickname', contact.set_nickname)
60 if self._multi_attributes.has_key('url'):
61 for url in self._multi_attributes['url']:
66 #print "FIXME - birthday date needs to be parsed/fixed %s before calling contact.set_birthday" % arg
67 self._if_defined('bday', fixme)
69 # private helpers -----------------------
71 def _if_defined(self, key, callback):
72 if self._attributes.has_key(key):
73 callback(self._attributes[key])
75 def _set(self, key, value):
77 # print "%s SET %s to %s" % (self, key, value)
78 self._attributes[key] = value
80 def _add(self, key, value):
82 if not self._multi_attributes.has_key(key):
83 self._multi_attributes[key] = []
84 # print "%s ADD %s to %s" % (self, key, value)
85 self._multi_attributes[key].append(value)
88 return self._attributes.has_key(key) or self._multi_attributes.has_key(key)