Philipp Hörist pushed to branch master at gajim / gajim
Commits: 5fe921af by lovetox at 2020-04-18T12:45:16+02:00 Refactor get_os_info()
- - - - - 03a482f1 by lovetox at 2020-04-18T16:28:10+02:00 EntityCaps: Add None check
- - - - -
3 changed files:
- gajim/common/app.py - gajim/common/helpers.py - gajim/common/modules/caps.py
Changes:
===================================== gajim/common/app.py ===================================== @@ -71,8 +71,6 @@ logger = cast(LoggerT, None)
css_config = None
-os_info = None # used to cache os information - transport_type = {} # type: Dict[str, str]
# dict of time of the latest incoming message per jid
===================================== gajim/common/helpers.py ===================================== @@ -45,6 +45,8 @@ import logging import json import copy import collections +import platform +import functools from collections import defaultdict import random import weakref @@ -702,21 +704,19 @@ def get_random_string(count=16): allowed = string.ascii_uppercase + string.digits return ''.join(random.choice(allowed) for char in range(count))
+@functools.lru_cache(maxsize=1) def get_os_info(): - if app.os_info: - return app.os_info - app.os_info = 'N/A' - if os.name == 'nt' or sys.platform == 'darwin': - import platform - app.os_info = platform.system() + " " + platform.release() - elif os.name == 'posix': + info = 'N/A' + if sys.platform in ('win32', 'darwin'): + info = f'{platform.system()} {platform.release()}' + + elif sys.platform == 'linux': try: import distro - app.os_info = distro.name(pretty=True) + info = distro.name(pretty=True) except ImportError: - import platform - app.os_info = platform.system() - return app.os_info + info = platform.system() + return info
def allow_showing_notification(account, type_='notify_on_new_message', is_first_message=True):
===================================== gajim/common/modules/caps.py ===================================== @@ -59,6 +59,9 @@ class Caps(BaseModule): if properties.is_self_presence: return
+ if properties.entity_caps is None: + return + jid = str(properties.jid)
hash_method = properties.entity_caps.hash
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/53af6559ca4374a08ba8e45fb2c5f966...