Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 4a430196a5
Fetching contributors…

Cannot retrieve contributors at this time

60 lines (42 sloc) 1.54 KB
# -*- coding: utf-8 -*-
"""This module provides classes for the tasks available to use kwallet."""
import pykwallet
from kwerrors import ValueNotSpecifiedError
TASKS = ['get', 'set']
AVAIL_TASKS = '[' + ', '.join(TASKS) + ']'
class KwTask(object):
"""Base class for the available tasks."""
def __call__(self, folder, entry, key, value=None):
self.entry = entry
self.key = key
self.value = value
res =
return res
def call(self):
"""Abstract function to actuall execute the task.
Override this to provide a new task.
the result or None for error."""
def open_wallet(self, wallet):
"""Open the specified wallet."""
self.wallet = wallet
app_name = u'kw' = pykwallet.KWallet(app_name, wallet=self.wallet)
class GetKwTask(KwTask):
"""Class to get values from KWallet."""
def call(self):
return, self.key)
class SetKwTask(KwTask):
"""Class to set values to KWallet."""
def call(self):
if not self.value:
raise ValueNotSpecifiedError(u'No value has been specified.')
return, self.value, self.key)
def get_kwtask(task):
"""Return the correct object for the specified task."""
task_classes = {TASKS[0]: GetKwTask,
TASKS[1]: SetKwTask}
return task in task_classes and task_classes[task]()
Jump to Line
Something went wrong with that request. Please try again.