| ... |
... |
@@ -29,10 +29,7 @@ |
|
29
|
29
|
|
|
30
|
30
|
from typing import Any
|
|
31
|
31
|
from typing import Callable
|
|
32
|
|
-from typing import Dict
|
|
33
|
32
|
from typing import Optional
|
|
34
|
|
-from typing import List
|
|
35
|
|
-from typing import Tuple
|
|
36
|
33
|
from typing import Union
|
|
37
|
34
|
|
|
38
|
35
|
import sys
|
| ... |
... |
@@ -74,10 +71,14 @@ |
|
74
|
71
|
from nbxmpp.structs import ProxyData
|
|
75
|
72
|
from nbxmpp.protocol import JID
|
|
76
|
73
|
from nbxmpp.protocol import InvalidJid
|
|
|
74
|
+from nbxmpp.protocol import Iq
|
|
|
75
|
+
|
|
77
|
76
|
from OpenSSL.crypto import X509, load_certificate
|
|
78
|
77
|
from OpenSSL.crypto import FILETYPE_PEM
|
|
|
78
|
+
|
|
79
|
79
|
from gi.repository import Gio
|
|
80
|
80
|
from gi.repository import GLib
|
|
|
81
|
+
|
|
81
|
82
|
import precis_i18n.codec # pylint: disable=unused-import
|
|
82
|
83
|
|
|
83
|
84
|
from gajim.common import app
|
| ... |
... |
@@ -318,8 +319,8 @@ def get_uf_relative_time(timestamp: float) -> str: |
|
318
|
319
|
return ngettext('%i min ago',
|
|
319
|
320
|
'%i mins ago',
|
|
320
|
321
|
minutes,
|
|
321
|
|
- minutes,
|
|
322
|
|
- minutes)
|
|
|
322
|
+ str(minutes),
|
|
|
323
|
+ str(minutes))
|
|
323
|
324
|
return _('Just now')
|
|
324
|
325
|
|
|
325
|
326
|
def get_sorted_keys(adict):
|
| ... |
... |
@@ -478,7 +479,9 @@ def play_sound(sound_event: str, |
|
478
|
479
|
app.settings.get_soundevent_settings(sound_event)['path'], loop)
|
|
479
|
480
|
|
|
480
|
481
|
|
|
481
|
|
-def check_soundfile_path(file_, dirs=None):
|
|
|
482
|
+def check_soundfile_path(file_: str,
|
|
|
483
|
+ dirs: Optional[list[Path]] = None
|
|
|
484
|
+ ) -> Optional[Path]:
|
|
482
|
485
|
"""
|
|
483
|
486
|
Check if the sound file exists
|
|
484
|
487
|
|
| ... |
... |
@@ -532,8 +535,8 @@ def strip_soundfile_path(file_, dirs=None, abs_=True): |
|
532
|
535
|
return name
|
|
533
|
536
|
return file_
|
|
534
|
537
|
|
|
535
|
|
-def play_sound_file(path_to_soundfile: str, loop: bool = False) -> None:
|
|
536
|
|
- path_to_soundfile = check_soundfile_path(path_to_soundfile)
|
|
|
538
|
+def play_sound_file(str_path_to_soundfile: str, loop: bool = False) -> None:
|
|
|
539
|
+ path_to_soundfile = check_soundfile_path(str_path_to_soundfile)
|
|
537
|
540
|
if path_to_soundfile is None:
|
|
538
|
541
|
return
|
|
539
|
542
|
|
| ... |
... |
@@ -595,7 +598,7 @@ def statuses_unified() -> bool: |
|
595
|
598
|
return True
|
|
596
|
599
|
|
|
597
|
600
|
|
|
598
|
|
-def get_full_jid_from_iq(iq_obj):
|
|
|
601
|
+def get_full_jid_from_iq(iq_obj: Iq) -> Optional[str]:
|
|
599
|
602
|
"""
|
|
600
|
603
|
Return the full jid (with resource) from an iq
|
|
601
|
604
|
"""
|
| ... |
... |
@@ -604,11 +607,13 @@ def get_full_jid_from_iq(iq_obj): |
|
604
|
607
|
return None
|
|
605
|
608
|
return parse_jid(str(iq_obj.getFrom()))
|
|
606
|
609
|
|
|
607
|
|
-def get_jid_from_iq(iq_obj):
|
|
|
610
|
+def get_jid_from_iq(iq_obj: Iq) -> Optional[str]:
|
|
608
|
611
|
"""
|
|
609
|
612
|
Return the jid (without resource) from an iq
|
|
610
|
613
|
"""
|
|
611
|
614
|
jid = get_full_jid_from_iq(iq_obj)
|
|
|
615
|
+ if jid is None:
|
|
|
616
|
+ return None
|
|
612
|
617
|
return app.get_jid_without_resource(jid)
|
|
613
|
618
|
|
|
614
|
619
|
def get_auth_sha(sid: str, initiator: str, target: str) -> str:
|
| ... |
... |
@@ -697,8 +702,8 @@ def allow_sound_notification(account: str, sound_event: str) -> bool: |
|
697
|
702
|
return False
|
|
698
|
703
|
|
|
699
|
704
|
|
|
700
|
|
-def get_optional_features(account: str) -> List[Namespace]:
|
|
701
|
|
- features = []
|
|
|
705
|
+def get_optional_features(account: str) -> list[Namespace]:
|
|
|
706
|
+ features: list[str] = []
|
|
702
|
707
|
|
|
703
|
708
|
if app.settings.get_account_setting(account, 'request_user_data'):
|
|
704
|
709
|
features.append(Namespace.TUNE + '+notify')
|
| ... |
... |
@@ -764,7 +769,7 @@ def get_proxy(proxy_name: str) -> Optional[ProxyData]: |
|
764
|
769
|
username, password = settings['user'], settings['pass']
|
|
765
|
770
|
|
|
766
|
771
|
return ProxyData(type=settings['type'],
|
|
767
|
|
- host='%s:%s' % (settings['host'], settings['port']),
|
|
|
772
|
+ host=f"{settings['host']}:{settings['port']}",
|
|
768
|
773
|
username=username,
|
|
769
|
774
|
password=password)
|
|
770
|
775
|
|
| ... |
... |
@@ -773,8 +778,8 @@ def version_condition(current_version: str, required_version: str) -> bool: |
|
773
|
778
|
return False
|
|
774
|
779
|
return True
|
|
775
|
780
|
|
|
776
|
|
-def get_available_emoticon_themes() -> List[str]:
|
|
777
|
|
- files = []
|
|
|
781
|
+def get_available_emoticon_themes() -> list[str]:
|
|
|
782
|
+ files: list[Path] = []
|
|
778
|
783
|
for folder in configpaths.get('EMOTICONS').iterdir():
|
|
779
|
784
|
if not folder.is_dir():
|
|
780
|
785
|
continue
|
| ... |
... |
@@ -879,8 +884,10 @@ def copy(self) -> AdditionalDataDict: |
|
879
|
884
|
|
|
880
|
885
|
|
|
881
|
886
|
class Singleton(type):
|
|
882
|
|
- _instances = {} # type: Dict[Any, Any]
|
|
883
|
|
- def __call__(cls, *args, **kwargs):
|
|
|
887
|
+
|
|
|
888
|
+ _instances: dict[Any, Any] = {}
|
|
|
889
|
+
|
|
|
890
|
+ def __call__(cls, *args: Any, **kwargs: Any):
|
|
884
|
891
|
if cls not in cls._instances:
|
|
885
|
892
|
cls._instances[cls] = super(Singleton, cls).__call__(
|
|
886
|
893
|
*args, **kwargs)
|
| ... |
... |
@@ -938,7 +945,7 @@ def func_wrapper(self, *args, **kwargs): |
|
938
|
945
|
return func_wrapper
|
|
939
|
946
|
|
|
940
|
947
|
|
|
941
|
|
-def parse_uri_actions(uri: str) -> Tuple[str, Dict[str, str]]:
|
|
|
948
|
+def parse_uri_actions(uri: str) -> tuple[str, dict[str, str]]:
|
|
942
|
949
|
uri = uri[5:]
|
|
943
|
950
|
if '?' not in uri:
|
|
944
|
951
|
return 'message', {'jid': uri}
|
| ... |
... |
@@ -1065,7 +1072,7 @@ def open_file(path: Union[str, Path]) -> None: |
|
1065
|
1072
|
Gio.AppInfo.launch_default_for_uri(path)
|
|
1066
|
1073
|
|
|
1067
|
1074
|
|
|
1068
|
|
-def file_is_locked(path_to_file):
|
|
|
1075
|
+def file_is_locked(path_to_file: str) -> bool:
|
|
1069
|
1076
|
"""
|
|
1070
|
1077
|
Return True if file is locked
|
|
1071
|
1078
|
NOTE: Windows only.
|
| ... |
... |
@@ -1112,7 +1119,7 @@ def get_resource(account: str) -> Optional[str]: |
|
1112
|
1119
|
return resource
|
|
1113
|
1120
|
|
|
1114
|
1121
|
|
|
1115
|
|
-def get_default_muc_config() -> Dict[str, Union[bool, str]]:
|
|
|
1122
|
+def get_default_muc_config() -> dict[str, Union[bool, str]]:
|
|
1116
|
1123
|
return {
|
|
1117
|
1124
|
# XEP-0045 options
|
|
1118
|
1125
|
'muc#roomconfig_allowinvites': True,
|
| ... |
... |
@@ -1147,7 +1154,7 @@ def validate_jid(jid: Union[str, JID], type_: Optional[str] = None) -> JID: |
|
1147
|
1154
|
if type_ == 'domain' and jid.is_domain:
|
|
1148
|
1155
|
return jid
|
|
1149
|
1156
|
|
|
1150
|
|
- raise ValueError('Not a %s JID' % type_)
|
|
|
1157
|
+ raise ValueError(f'Not a {type_} JID')
|
|
1151
|
1158
|
|
|
1152
|
1159
|
|
|
1153
|
1160
|
def to_user_string(error: StanzaError) -> str:
|
| ... |
... |
@@ -1161,7 +1168,7 @@ def to_user_string(error: StanzaError) -> str: |
|
1161
|
1168
|
return condition
|
|
1162
|
1169
|
|
|
1163
|
1170
|
|
|
1164
|
|
-def get_groupchat_name(client: types.Client, jid: Union[str, JID]) -> str:
|
|
|
1171
|
+def get_groupchat_name(client: types.Client, jid: JID) -> str:
|
|
1165
|
1172
|
name = client.get_module('Bookmarks').get_name_from_bookmark(jid)
|
|
1166
|
1173
|
if name:
|
|
1167
|
1174
|
return name
|
| ... |
... |
@@ -1336,7 +1343,7 @@ def convert_gio_to_openssl_cert(cert: Gio.TlsCertificate) -> X509: |
|
1336
|
1343
|
return load_certificate(FILETYPE_PEM, cert.props.certificate_pem.encode())
|
|
1337
|
1344
|
|
|
1338
|
1345
|
|
|
1339
|
|
-def get_custom_host(account: str) -> Optional[Tuple[str,
|
|
|
1346
|
+def get_custom_host(account: str) -> Optional[tuple[str,
|
|
1340
|
1347
|
ConnectionProtocol,
|
|
1341
|
1348
|
ConnectionType]]:
|
|
1342
|
1349
|
if not app.settings.get_account_setting(account, 'use_custom_host'):
|
| ... |
... |
@@ -1355,7 +1362,7 @@ def get_custom_host(account: str) -> Optional[Tuple[str, |
|
1355
|
1362
|
|
|
1356
|
1363
|
|
|
1357
|
1364
|
def warn_about_plain_connection(account: str,
|
|
1358
|
|
- connection_types: List[ConnectionType]
|
|
|
1365
|
+ connection_types: list[ConnectionType]
|
|
1359
|
1366
|
) -> bool:
|
|
1360
|
1367
|
warn = app.settings.get_account_setting(
|
|
1361
|
1368
|
account, 'confirm_unencrypted_connection')
|