File: history.py

package info (click to toggle)
bzr-gtk 0.103.0+bzr792-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,524 kB
  • sloc: python: 9,616; makefile: 16; sh: 10
file content (48 lines) | stat: -rw-r--r-- 1,639 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

delimiter = " "

class UrlHistory:
    """Simple helper class for storing URL history."""

    def __init__(self, config, name):
        """Access URL History in a Config object.

        :param config: Config object to use
        :param name: Name of the history variable.
        """
        self._config = config
        self._name = name

    def add_entry(self, url):
        """Add a new entry to the list.

        :param url: Url to add
        """
        self._config.set_user_option(self._name, delimiter.join(
            self.get_entries() + [url]))

    def get_entries(self):
        """Obtain all URLs currently listed.

        :return list of URLs or empty list if no URLs set yet.
        """
        history = self._config.get_user_option(self._name)
        if history is None:
            return []
        else:
            return history.split(delimiter)