Navigation Menu

Skip to content

Commit

Permalink
Add new class PromptDismissedException
Browse files Browse the repository at this point in the history
  • Loading branch information
mitya57 committed Aug 26, 2018
1 parent 58c99b9 commit 8aae806
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 7 additions & 4 deletions secretstorage/collection.py
Expand Up @@ -19,7 +19,8 @@
from jeepney.integrate.blocking import DBusConnection
from secretstorage.defines import SS_PREFIX, SS_PATH
from secretstorage.dhcrypto import Session
from secretstorage.exceptions import LockedException, ItemNotFoundException
from secretstorage.exceptions import LockedException, ItemNotFoundException, \
PromptDismissedException
from secretstorage.item import Item
from secretstorage.util import DBusAddressWrapper, exec_prompt, \
format_secret, open_session, unlock_objects
Expand Down Expand Up @@ -122,8 +123,10 @@ def create_item(self, label: str, attributes: Dict[str, str],
def create_collection(connection: DBusConnection, label: str, alias: str = '',
session: Optional[Session] = None) -> Collection:
"""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`.
and returns it. This action requires prompting.
:raises: :exc:`~secretstorage.exceptions.PromptDismissedException`
if the prompt is dismissed.
"""
if not session:
session = open_session(connection)
Expand All @@ -135,7 +138,7 @@ def create_collection(connection: DBusConnection, label: str, alias: str = '',
return Collection(connection, collection_path, session=session)
dismissed, result = exec_prompt(connection, prompt)
if dismissed:
raise ItemNotFoundException('Prompt dismissed.')
raise PromptDismissedException('Prompt dismissed.')
signature, collection_path = result
assert signature == 'o'
return Collection(connection, collection_path, session=session)
Expand Down
8 changes: 5 additions & 3 deletions secretstorage/exceptions.py
Expand Up @@ -36,8 +36,10 @@ class ItemNotFoundException(SecretStorageException):
... print('Item not found!')
...
Item not found!
"""

class PromptDismissedException(ItemNotFoundException):
"""Raised when a prompt was dismissed by the user.
Also, :func:`~secretstorage.collection.create_collection` may raise
this exception when a prompt was dismissed during creating the
collection.
.. versionadded:: 3.1
"""

0 comments on commit 8aae806

Please sign in to comment.