diff options
author | mathieui <mathieui@mathieui.net> | 2018-08-17 02:16:03 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2018-08-17 02:16:03 +0200 |
commit | b4d3b93da2e23cefb85dd98f1f7f9706aa0402d4 (patch) | |
tree | f8c489bbf65a9a4a24d268281d3da798bbfe3ba2 /poezio/bookmarks.py | |
parent | 6ccf7ea71d5e5194dd036a90e36c0db6a0ec757a (diff) | |
download | poezio-b4d3b93da2e23cefb85dd98f1f7f9706aa0402d4.tar.gz poezio-b4d3b93da2e23cefb85dd98f1f7f9706aa0402d4.tar.bz2 poezio-b4d3b93da2e23cefb85dd98f1f7f9706aa0402d4.tar.xz poezio-b4d3b93da2e23cefb85dd98f1f7f9706aa0402d4.zip |
Add typing information and reformat stuff
Diffstat (limited to 'poezio/bookmarks.py')
-rw-r--r-- | poezio/bookmarks.py | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/poezio/bookmarks.py b/poezio/bookmarks.py index f6f22363..0406de94 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 +from typing import Optional, List, Union from slixmpp import JID from slixmpp.plugins.xep_0048 import Bookmarks, Conference, URL @@ -130,7 +130,7 @@ class Bookmark: class BookmarkList: def __init__(self): - self.bookmarks = [] + self.bookmarks = [] # type: List[Bookmark] preferred = config.get('use_bookmarks_method').lower() if preferred not in ('pep', 'privatexml'): preferred = 'privatexml' @@ -140,15 +140,16 @@ class BookmarkList: 'pep': False, } - def __getitem__(self, key): + def __getitem__(self, key: Union[str, JID, int]) -> Optional[Bookmark]: if isinstance(key, (str, JID)): for i in self.bookmarks: if key == i.jid: return i - else: + elif isinstance(key, int): return self.bookmarks[key] + return None - def __in__(self, key): + def __in__(self, key) -> bool: if isinstance(key, (str, JID)): for bookmark in self.bookmarks: if bookmark.jid == key: @@ -168,16 +169,16 @@ class BookmarkList: def __iter__(self): return iter(self.bookmarks) - def local(self): + def local(self) -> List[Bookmark]: return [bm for bm in self.bookmarks if bm.method == 'local'] - def remote(self): + def remote(self) -> List[Bookmark]: return [bm for bm in self.bookmarks if bm.method == 'remote'] - def set(self, new): + def set(self, new: List[Bookmark]): self.bookmarks = new - def append(self, bookmark): + def append(self, bookmark: Bookmark): bookmark_exists = self[bookmark.jid] if not bookmark_exists: self.bookmarks.append(bookmark) @@ -185,7 +186,7 @@ class BookmarkList: self.bookmarks.remove(bookmark_exists) self.bookmarks.append(bookmark) - def set_bookmarks_method(self, value): + def set_bookmarks_method(self, value: str): if self.available_storage.get(value): self.preferred = value config.set_and_save('use_bookmarks_method', value) @@ -306,7 +307,7 @@ class BookmarkList: self.append(b) -def stanza_storage(bookmarks): +def stanza_storage(bookmarks: BookmarkList) -> Bookmarks: """Generate a <storage/> stanza with the conference elements.""" storage = Bookmarks() for b in (b for b in bookmarks if b.method == 'remote'): |