Bookmark: Change jid property to getter/setter to ensure it stays a JID

It's not like static-type checking was a thing in Python nowadays..
(mypy I'm looking at you)

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-10-26 00:57:20 +02:00
parent ea1ab71f02
commit 4703c8506a
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -49,18 +49,34 @@ class Bookmark:
method='local') -> None:
try:
if isinstance(jid, JID):
self.jid = jid
self._jid = jid
else:
self.jid = JID(jid)
self._jid = JID(jid)
except InvalidJID:
log.debug('Invalid JID %r provided for bookmark %r', jid, name)
log.debug('Invalid JID %r provided for bookmark', jid)
raise
self.name = name or str(jid)
self.name = name or str(self.jid)
self.autojoin = autojoin
self.nick = nick
self.password = password
self._method = method
@property
def jid(self) -> JID:
"""Jid getter"""
return self._jid
@jid.setter
def jid(self, jid: JID) -> None:
try:
if isinstance(jid, JID):
self._jid = jid
else:
self._jid = JID(jid)
except InvalidJID:
log.debug('Invalid JID %r provided for bookmark', jid)
raise
@property
def method(self) -> str:
return self._method