1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """
24 UrlBase class for GRAMPS.
25 """
26
27
28
29
30
31
32 from gen.lib.url import Url
33
34
35
36
37
38
40 """
41 Base class for url-aware objects.
42 """
43
45 """
46 Initialize an UrlBase.
47
48 If the source is not None, then object is initialized from values of
49 the source object.
50
51 @param source: Object used to initialize the new object
52 @type source: UrlBase
53 """
54
55 if source:
56 self.urls = [ Url(url) for url in source.urls ]
57 else:
58 self.urls = []
59
61 """
62 Convert the object to a serialized tuple of data
63 """
64 return [url.serialize() for url in self.urls]
65
67 """
68 Convert a serialized tuple of data to an object.
69 """
70 self.urls = [Url().unserialize(item) for item in data]
71
73 """
74 Return the list of L{Url} instances associated with the object.
75
76 @returns: List of L{Url} instances
77 @rtype: list
78 """
79 return self.urls
80
82 """
83 Set the list of L{Url} instances to passed the list.
84
85 @param url_list: List of L{Url} instances
86 @type url_list: list
87 """
88 self.urls = url_list
89
91 """
92 Add a L{Url} instance to the object's list of L{Url} instances.
93
94 @param url: L{Url} instance to be added to the Person's list of
95 related web sites.
96 @type url: L{Url}
97 """
98 self.urls.append(url)
99
101 """
102 Remove the specified L{Url} instance from the url list.
103
104 If the instance does not exist in the list, the operation has no effect.
105
106 @param url: L{Url} instance to remove from the list
107 @type url: L{Url}
108
109 @return: True if the url was removed, False if it was not in the list.
110 @rtype: bool
111 """
112 if url in self.urls:
113 self.urls.remove(url)
114 return True
115 else:
116 return False
117