screenlets.plugins.keyring

Package screenlets :: Package plugins :: Module keyring |
[hide private]
[frames] | no frames]

# Source Code for Module screenlets.plugins.keyring

     1  # pavpanchekha
     2  #
     3  # This program is free software: you can redistribute it and/or modify
     4  # it under the terms of the GNU General Public License as published by
     5  # the Free Software Foundation, either version 3 of the License, or
     6  # (at your option) any later version.
     7  #
     8  # This program is distributed in the hope that it will be useful,
     9  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  # GNU General Public License for more details.
    12  #
    13  # You should have received a copy of the GNU General Public License
    14  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15
    16 -class KeyRing(object):
    17 -    def __init__(self):
    18          import keyring
    19          self.keyring = keyring
    20          if not self.keyring.is_available():
    21              raise KeyRingError
    22          keyring_list = self.keyring.list_keyring_names_sync()
    23          if len(keyring_list) == 0:
    24              raise KeyRingError
    25          self.ring = self.keyring.get_default_keyring_sync()
    26
    27 -    def new(self, name=None, pwd=None, attrs={}, type="generic"):
    28          k = self.Key(self.keyring)
    29          if name and pwd:
    30              k.set(name, pwd, attrs, type)
    31          return k
    32
    33 -    class Key(object):
    34 -        def __init__(self, keyring, token=0):
    35              self.keyring = keyring
    36              self.token = token
    37
    38 -        def set(self, name, pwd, attrs={}, type="generic"):
    39              if type == "network":
    40                  type = self.keyring.ITEM_NETWORK_PASSWORD
    41              elif type == "note":
    42                  type = self.keyring.ITEM_NOTE
    43              else: # Generic included
    44                  type = self.keyring.ITEM_GENERIC_SECRET
    45
    46              self.token = self.keyring.item_create_sync(None, type, name, attrs, pwd, True)
    47
    48 -        def get(self):
    49              return self.keyring.item_get_info_sync(None, self.token)
    50
    51 -        def getAttrs(self):
    52              return keyring.item_get_attributes_sync(None, self.token)
    53
    54 -        def setAttrs(self, a):
    55              return keyring.item_set_attributes_sync(None, self.token, a)
    56
    57 -        def getName(self):
    58              return self.get().get_display_name()
    59
    60 -        def setName(self, name):
    61              self.get().set_display_name(name)
    62
    63 -        def getPass(self):
    64              return self.get().get_secret()
    65
    66 -        def setPass(self, passwd):
    67              self.get().set_secret(passwd)
    68
    69 -        def delete(self):
    70              self.keyring.item_delete_sync(None, self.token)
    71
    72          attrs = property(getAttrs, setAttrs)
    73          name = property(getName, setName)
    74          password = property(getPass, setPass)
    75