Package screenlets :: Package plugins :: Module keyring

[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.keyring

     1  # This application is released under the GNU General Public License
     2  # v3 (or, at your option, any later version). You can find the full
     3  # text of the license under http://www.gnu.org/licenses/gpl.txt.
     4  # By using, editing and/or distributing this software you agree to
     5  # the terms and conditions of this license.
     6  # Thank you for using free softwa
     7
     8  # pavpanchekha
     9
    10 -class KeyRing:
    11 -    def __init__(self):
    12          import keyring
    13          self.keyring = keyring
    14          if not self.keyring.is_available():
    15              raise KeyRingError
    16          keyring_list = self.keyring.list_keyring_names_sync()
    17          if len(keyring_list) == 0:
    18              raise KeyRingError
    19          self.ring = self.keyring.get_default_keyring_sync()
    20
    21 -    def new(self, name=None, pwd=None, attrs={}, type="generic"):
    22          k = self.Key(self.keyring)
    23          if name and pwd:
    24              k.set(name, pwd, attrs, type)
    25          return k
    26
    27 -    class Key(object):
    28 -        def __init__(self, keyring, token=0):
    29              self.keyring = keyring
    30              self.token = token
    31
    32 -        def set(self, name, pwd, attrs={}, type="generic"):
    33              if type == "network":
    34                  type = self.keyring.ITEM_NETWORK_PASSWORD
    35              elif type == "note":
    36                  type = self.keyring.ITEM_NOTE
    37              else: # Generic included
    38                  type = self.keyring.ITEM_GENERIC_SECRET
    39
    40              self.token = self.keyring.item_create_sync(None, type, name, attrs, pwd, True)
    41
    42 -        def get(self):
    43              return self.keyring.item_get_info_sync(None, self.token)
    44
    45 -        def getAttrs(self):
    46              return keyring.item_get_attributes_sync(None, self.token)
    47
    48 -        def setAttrs(self, a):
    49              return keyring.item_set_attributes_sync(None, self.token, a)
    50
    51 -        def getName(self):
    52              return self.get().get_display_name()
    53
    54 -        def setName(self, name):
    55              self.get().set_display_name(name)
    56
    57 -        def getPass(self):
    58              return self.get().get_secret()
    59
    60 -        def setPass(self, passwd):
    61              self.get().set_secret(passwd)
    62
    63 -        def delete(self):
    64              self.keyring.item_delete_sync(None, self.token)
    65
    66          attrs = property(getAttrs, setAttrs)
    67          name = property(getName, setName)
    68          password = property(getPass, setPass)
    69