Package gen :: Package lib :: Module urlbase
[frames] | no frames]

Source Code for Module gen.lib.urlbase

  1  # 
  2  # Gramps - a GTK+/GNOME based genealogy program 
  3  # 
  4  # Copyright (C) 2000-2006  Donald N. Allingham 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the Free Software 
 18  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 19  # 
 20   
 21  # $Id: urlbase.py 10103 2008-02-24 13:55:55Z acraphae $ 
 22   
 23  """ 
 24  UrlBase class for GRAMPS. 
 25  """ 
 26   
 27  #------------------------------------------------------------------------- 
 28  # 
 29  # GRAMPS modules 
 30  # 
 31  #------------------------------------------------------------------------- 
 32  from gen.lib.url import Url 
 33   
 34  #------------------------------------------------------------------------- 
 35  # 
 36  # UrlBase classes 
 37  # 
 38  #------------------------------------------------------------------------- 
39 -class UrlBase:
40 """ 41 Base class for url-aware objects. 42 """ 43
44 - def __init__(self, source=None):
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
60 - def serialize(self):
61 """ 62 Convert the object to a serialized tuple of data 63 """ 64 return [url.serialize() for url in self.urls]
65
66 - def unserialize(self, data):
67 """ 68 Convert a serialized tuple of data to an object. 69 """ 70 self.urls = [Url().unserialize(item) for item in data]
71
72 - def get_url_list(self):
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
81 - def set_url_list(self, url_list):
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
90 - def add_url(self, url):
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
100 - def remove_url(self, url):
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