From 91831e7903bac287be9e5403e56b07691151f1ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 31 May 2020 01:20:41 +0200 Subject: [PATCH 1/2] Bookmarks: type bookmark method (local/remote) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/bookmarks.py | 8 +++++--- poezio/core/commands.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/poezio/bookmarks.py b/poezio/bookmarks.py index d842d2dd..46f6dfab 100644 --- a/poezio/bookmarks.py +++ b/poezio/bookmarks.py @@ -30,7 +30,7 @@ Adding a remote bookmark: import functools import logging -from typing import Optional, List, Union +from typing import Optional, List, Literal, Union from slixmpp import InvalidJID, JID from slixmpp.plugins.xep_0048 import Bookmarks, Conference, URL @@ -39,6 +39,8 @@ from poezio.config import config log = logging.getLogger(__name__) +Method = Union[Literal['local'], Literal['remote']] + class Bookmark: def __init__(self, jid: Union[JID, str], @@ -46,7 +48,7 @@ class Bookmark: autojoin=False, nick: Optional[str] = None, password: Optional[str] = None, - method='local') -> None: + method: Method = 'local') -> None: try: if isinstance(jid, JID): self._jid = jid @@ -82,7 +84,7 @@ class Bookmark: return self._method @method.setter - def method(self, value: str): + def method(self, value: Method): if value not in ('local', 'remote'): log.debug('Could not set bookmark storing method: %s', value) return diff --git a/poezio/core/commands.py b/poezio/core/commands.py index 6fc800ae..98acef32 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -18,7 +18,7 @@ from poezio import common from poezio import pep from poezio import tabs from poezio import multiuserchat as muc -from poezio.bookmarks import Bookmark +from poezio.bookmarks import Bookmark, Method as BookmarkMethod from poezio.common import safeJID from poezio.config import config, DEFAULT_CONFIG, options as config_opts from poezio.contact import Contact, Resource @@ -444,7 +444,7 @@ class CommandCore: self._add_bookmark(jid, autojoin, password, 'remote') - def _add_bookmark(self, jid, autojoin, password, method): + def _add_bookmark(self, jid: str, autojoin: bool, password: str, method: BookmarkMethod) -> None: nick = None if not jid: tab = self.core.tabs.current_tab @@ -478,7 +478,7 @@ class CommandCore: self.core.bookmarks.save_remote(self.core.xmpp, self.core.handler.on_bookmark_result) - def _add_wildcard_bookmarks(self, method): + def _add_wildcard_bookmarks(self, method: BookmarkMethod): new_bookmarks = [] for tab in self.core.get_tabs(tabs.MucTab): bookmark = self.core.bookmarks[tab.jid.bare] From 21c45ff72e23b66c04d56a6ac5d832dd564baf65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 31 May 2020 01:33:54 +0200 Subject: [PATCH 2/2] BookmarksTab: harmonize Info message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/tabs/bookmarkstab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poezio/tabs/bookmarkstab.py b/poezio/tabs/bookmarkstab.py index cb3a4d0c..eb390bd3 100644 --- a/poezio/tabs/bookmarkstab.py +++ b/poezio/tabs/bookmarkstab.py @@ -95,7 +95,7 @@ class BookmarksTab(Tab): def send_cb(success): if success: - self.core.information('Bookmarks saved.', 'Info') + self.core.information('Bookmarks saved', 'Info') else: self.core.information('Remote bookmarks not saved.', 'Error')