Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_collection(bus, label, alias='', session=None):
"""Creates a new :class:`Collection` with the given `label` and `alias`
and returns it. This action requires prompting. If prompt is dismissed,
raises :exc:`~secretstorage.exceptions.ItemNotFoundException`. This is
synchronous function, uses loop from GLib API."""
if not session:
session = open_session(bus)
properties = {SS_PREFIX+'Collection.Label': label}
service_obj = bus_get_object(bus, SS_PATH)
service_iface = dbus.Interface(service_obj, SERVICE_IFACE)
collection_path, prompt = service_iface.CreateCollection(properties,
alias, signature='a{sv}s')
if len(collection_path) > 1:
return Collection(bus, collection_path, session=session)
dismissed, unlocked = exec_prompt_glib(bus, prompt)
if dismissed:
raise ItemNotFoundException('Prompt dismissed.')
return Collection(bus, unlocked, session=session)
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)
def get_collection_by_alias(bus, alias):
"""Returns the collection with the given `alias`. If there is no
such collection, raises
:exc:`~secretstorage.exceptions.ItemNotFoundException`."""
service_obj = bus_get_object(bus, SS_PATH)
service_iface = dbus.Interface(service_obj, SERVICE_IFACE)
collection_path = service_iface.ReadAlias(alias, signature='s')
if len(collection_path) <= 1:
raise ItemNotFoundException('No collection with such alias.')
return Collection(bus, collection_path)
def __init__(self, bus, collection_path=DEFAULT_COLLECTION, session=None):
collection_obj = bus_get_object(bus, collection_path)
self.bus = bus
self.session = session
self.collection_path = collection_path
self.collection_iface = InterfaceWrapper(collection_obj,
COLLECTION_IFACE)
self.collection_props_iface = InterfaceWrapper(collection_obj,
dbus.PROPERTIES_IFACE)
self.collection_props_iface.Get(COLLECTION_IFACE, 'Label',
signature='ss')
def __init__(self, bus, item_path, session=None):
self.item_path = item_path
item_obj = bus_get_object(bus, item_path)
self.session = session
self.bus = bus
self.item_iface = InterfaceWrapper(item_obj, ITEM_IFACE)
self.item_props_iface = InterfaceWrapper(item_obj,
dbus.PROPERTIES_IFACE)
self.item_props_iface.Get(ITEM_IFACE, 'Label', signature='ss')