Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_closing_context_manager(self) -> None:
with closing(dbus_init()) as connection:
collection = get_any_collection(connection)
self.assertIsNotNone(collection)
label = collection.get_label()
self.assertIsNotNone(label)
def setUp(self) -> None:
self.connection = dbus_init()
#!/usr/bin/env python3
from contextlib import closing
import secretstorage
with closing(secretstorage.dbus_init()) as connection:
items = secretstorage.search_items(connection, {'application': 'secretstorage-test'})
for item in items:
print('Deleting item with label %r.' % item.get_label())
item.delete()
def parse(self, label):
"""Direct import from the Gnome keyring using Dbus.
:param str label: The collection label to import. If empty string
import all collection.
"""
try:
import secretstorage
except ImportError as error:
raise ImportError(error, name='secretstorage')
keys = self._invkeys()
connection = secretstorage.dbus_init()
for collection in secretstorage.get_all_collections(connection):
group = collection.get_label()
if label not in ('', group):
continue
collection.unlock()
for item in collection.get_all_items():
entry = dict()
entry['group'] = group
entry['title'] = item.get_label()
entry['password'] = item.get_secret().decode('utf-8')
entry['modified'] = item.get_modified()
entry['created'] = item.get_created()
for key, value in item.get_attributes().items():
entry[keys.get(key, key)] = value
self.data.append(entry)
def get_default_collection(self):
bus = secretstorage.dbus_init()
try:
collection = secretstorage.get_default_collection(bus)
except exceptions.SecretStorageException as e:
raise InitError("Failed to create the collection: %s." % e)
if collection.is_locked():
collection.unlock()
if collection.is_locked(): # User dismissed the prompt
raise InitError("Failed to unlock the collection!")
return collection
def get_default_collection(self):
bus = secretstorage.dbus_init()
try:
collection = secretstorage.get_default_collection(bus)
except exceptions.SecretStorageException as e:
raise InitError("Failed to create the collection: %s." % e)
if collection.is_locked():
collection.unlock()
if collection.is_locked(): # User dismissed the prompt
raise InitError("Failed to unlock the collection!")
return collection
def __init__(self):
try:
self.bus = secretstorage.dbus_init()
except:
self.bus = None
self.collection = {'application':'pupy'}
def priority(cls):
with ExceptionRaisedContext() as exc:
secretstorage.__name__
if exc:
raise RuntimeError("SecretStorage required")
if not hasattr(secretstorage, 'get_default_collection'):
raise RuntimeError("SecretStorage 1.0 or newer required")
try:
bus = secretstorage.dbus_init()
list(secretstorage.get_all_collections(bus))
except exceptions.SecretServiceNotAvailableException as e:
raise RuntimeError(
"Unable to initialize SecretService: %s" % e)
return 5