ChatTab: Oops. prevent recursion when using setters

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2019-04-08 16:11:23 +01:00
parent 8d53ff71d1
commit db2a22d099
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -464,6 +464,8 @@ class ChatTab(Tab):
def __init__(self, core, jid: Union[JID, str]): def __init__(self, core, jid: Union[JID, str]):
Tab.__init__(self, core) Tab.__init__(self, core)
self._jid = None
self._name = ''
self.name = jid self.name = jid
self.text_win = None self.text_win = None
self.directed_presence = None self.directed_presence = None
@ -511,39 +513,39 @@ class ChatTab(Tab):
@property @property
def name(self) -> str: def name(self) -> str:
if self.jid is not None: if self._jid is not None:
return self.jid.full return self._jid.full
return self.name return self._name
@name.setter @name.setter
def name(self, value: Union[JID, str]) -> None: def name(self, value: Union[JID, str]) -> None:
if isinstance(value, JID): if isinstance(value, JID):
self.jid = value self._jid = value
elif isinstance(value, str): elif isinstance(value, str):
try: try:
value = JID(value) value = JID(value)
if value.domain: if value.domain:
self.jid = value self._jid = value
self.name = value.full self._name = value.full
except InvalidJID: except InvalidJID:
self.name = value self._name = value
else: else:
raise TypeError("Name must be of type JID or str.") raise TypeError("Name must be of type JID or str.")
@property @property
def jid(self) -> Optional[JID]: def jid(self) -> Optional[JID]:
return self.jid return self._jid
@jid.setter @jid.setter
def jid(self, value: Optional[JID]) -> None: def jid(self, value: Optional[JID]) -> None:
if value is None: if value is None:
self.jid = None self._jid = None
return None return None
if not isinstance(value, JID): if not isinstance(value, JID):
raise TypeError("Jid must be of type Optional[JID].") raise TypeError("Jid must be of type Optional[JID].")
if not value.domain: if not value.domain:
raise ValueError("Jid must contain at least a domain.") raise ValueError("Jid must contain at least a domain.")
self.jid = value self._jid = value
@property @property
def general_jid(self) -> JID: def general_jid(self) -> JID: