예제 #1
0
	def search_items(self, attributes):
		"""Returns a generator of items with the given attributes.
		`attributes` should be a dictionary."""
		result = self.collection_iface.SearchItems(attributes,
			signature='a{ss}')
		for item_path in result:
			yield Item(self.bus, item_path, self.session)
예제 #2
0
def search_items(connection: DBusConnection,
                 attributes: Dict[str, str]) -> Iterator[Item]:
    """Returns a generator of items in all collections with the given
	attributes. `attributes` should be a dictionary."""
    service = DBusAddressWrapper(SS_PATH, SERVICE_IFACE, connection)
    locked, unlocked = service.call('SearchItems', 'a{ss}', attributes)
    for item_path in locked + unlocked:
        yield Item(connection, item_path)
예제 #3
0
def search_items(bus, attributes):
    """Returns a generator of items in all collections with the given
    attributes. `attributes` should be a dictionary."""
    service_obj = bus_get_object(bus, SS_PATH)
    service_iface = dbus.Interface(service_obj, SERVICE_IFACE)
    locked, unlocked = service_iface.SearchItems(attributes, signature='a{ss}')
    for item_path in locked + unlocked:
        yield Item(bus, item_path)
예제 #4
0
def get_item_object(item_id, unlock=True):
    """Returns the item with given id and unlocks it if `unlock` is
	`True`."""
    bus = dbus_init()
    collection = get_any_collection(bus)
    item = Item(bus, join(collection.collection_path, str(item_id)))
    if unlock and collection.is_locked():
        collection.unlock()
    return item
예제 #5
0
	def search_items(self, attributes):
		"""Returns a generator of items with the given attributes.
		`attributes` should be a dictionary."""
		result = self.collection_iface.SearchItems(attributes,
			signature='a{ss}')
		if isinstance(result, tuple):
			# bug in GNOME Keyring <= 3.7.5
			result = result[0] + result[1]
		for item_path in result:
			yield Item(self.bus, item_path, self.session)
예제 #6
0
def get_item_object(item_id, unlock=True):
    """Returns the item with given id and unlocks it if `unlock` is
	`True`."""
    bus = dbus_init()
    item = Item(bus, item_id)
    collection_path = item.item_path.rsplit('/', 1)[0]
    collection = Collection(bus, collection_path)
    if unlock and collection.is_locked():
        collection.unlock()
    return item
예제 #7
0
	def create_item(self, label, attributes, secret, replace=False,
	content_type='text/plain'):
		"""Creates a new :class:`~secretstorage.item.Item` with given
		`label` (unicode string), `attributes` (dictionary) and `secret`
		(bytestring). If `replace` is :const:`True`, replaces the existing
		item with the same attributes. If `content_type` is given, also
		sets the content type of the secret (``text/plain`` by default).
		Returns the created item."""
		self.ensure_not_locked()
		if not self.session:
			self.session = open_session(self.bus)
		secret = format_secret(self.session, secret, content_type)
		attributes = dbus.Dictionary(attributes, signature='ss')
		properties = {
			SS_PREFIX+'Item.Label': label,
			SS_PREFIX+'Item.Attributes': attributes
		}
		new_item, prompt = self.collection_iface.CreateItem(properties,
			secret, replace, signature='a{sv}(oayays)b')
		return Item(self.bus, new_item, self.session)
예제 #8
0
    def create_item(self,
                    label: str,
                    attributes: Dict[str, str],
                    secret: bytes,
                    replace: bool = False,
                    content_type: str = 'text/plain') -> Item:
        """Creates a new :class:`~secretstorage.item.Item` with given
		`label` (unicode string), `attributes` (dictionary) and `secret`
		(bytestring). If `replace` is :const:`True`, replaces the existing
		item with the same attributes. If `content_type` is given, also
		sets the content type of the secret (``text/plain`` by default).
		Returns the created item."""
        self.ensure_not_locked()
        if not self.session:
            self.session = open_session(self.connection)
        _secret = format_secret(self.session, secret, content_type)
        properties = {
            SS_PREFIX + 'Item.Label': ('s', label),
            SS_PREFIX + 'Item.Attributes': ('a{ss}', attributes),
        }
        new_item, prompt = self._collection.call('CreateItem',
                                                 'a{sv}(oayays)b', properties,
                                                 _secret, replace)
        return Item(self.connection, new_item, self.session)
예제 #9
0
def get_item_attributes(item_id):
	"""Returns item attributes for item with given id."""
	bus = dbus_init()
	collection = get_any_collection(bus)
	item = Item(bus, join(collection.collection_path, str(item_id)))
	return item.get_attributes()
예제 #10
0
	def get_all_items(self):
		"""Returns a generator of all items in the collection."""
		for item_path in self.collection_props_iface.Get(
		COLLECTION_IFACE, 'Items', signature='ss'):
			yield Item(self.bus, item_path, self.session)
예제 #11
0
    def search_items(self, attributes: Dict[str, str]) -> Iterator[Item]:
        """Returns a generator of items with the given attributes.
		`attributes` should be a dictionary."""
        result, = self._collection.call('SearchItems', 'a{ss}', attributes)
        for item_path in result:
            yield Item(self.connection, item_path, self.session)
예제 #12
0
 def get_all_items(self) -> Iterator[Item]:
     """Returns a generator of all items in the collection."""
     for item_path in self._collection.get_property('Items'):
         yield Item(self.connection, item_path, self.session)
예제 #13
0
def get_item_attributes(item_id):
    """Returns item attributes for item with given id."""
    bus = dbus_init()
    item = Item(bus, item_id)
    return item.get_attributes()
예제 #14
0
def get_item_attributes(item_id):
	"""Returns item attributes for item with given id."""
	bus = dbus_init()
	item = Item(bus, item_id)
	return item.get_attributes()
예제 #15
0
def get_item_attributes(item_id):
    """Returns item attributes for item with given id."""
    bus = dbus_init()
    collection = get_any_collection(bus)
    item = Item(bus, join(collection.collection_path, str(item_id)))
    return item.get_attributes()