Python 3 port:

/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time

This patch port backend, bridge and frontends to Python 3.

Roughly this has been done this way:

- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
  to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
This commit is contained in:
Goffi 2019-08-13 19:08:41 +02:00
commit fbfe96c505

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT: a jabber client
@ -50,7 +50,7 @@ def dict2iter(name, dict_, pop=False):
idx = 1
while True:
try:
yield get(dict_, u"{}#{}".format(name, idx))
yield get(dict_, "{}#{}".format(name, idx))
except KeyError:
return
else:
@ -73,7 +73,7 @@ def dict2iterdict(name, dict_, extra_keys, pop=False):
ret = {name: main_value}
for k in extra_keys:
ret[k] = get(
dict_, u"{}{}_{}".format(name, (u"#" + unicode(idx)) if idx else u"", k)
dict_, "{}{}_{}".format(name, ("#" + str(idx)) if idx else "", k)
)
yield ret
@ -98,14 +98,14 @@ def iter2dict(name, iter_, dict_=None, check_conflict=True):
if idx == 0:
key = name
else:
key = u"{}#{}".format(name, idx)
key = "{}#{}".format(name, idx)
if check_conflict and key in dict_:
raise exceptions.ConflictError
dict_[key] = value
return dict
def getSubDict(name, dict_, sep=u"_"):
def getSubDict(name, dict_, sep="_"):
"""get a sub dictionary from a serialised dictionary
look for keys starting with name, and create a dict with it
@ -116,7 +116,7 @@ def getSubDict(name, dict_, sep=u"_"):
@param sep(unicode): separator used between name and subkey
@return iter: iterate through the deserialised items
"""
for k, v in dict_.iteritems():
for k, v in dict_.items():
if k.startswith(name):
if k == name:
yield None, v
@ -131,7 +131,7 @@ def serialise(data):
@return(unicode): serialised data, can be transmitted as string to the bridge
"""
return json.dumps(data, ensure_ascii=False, default=unicode)
return json.dumps(data, ensure_ascii=False, default=str)
def deserialise(serialised_data, default=None, type_check=dict):
"""Deserialize data from bridge
@ -142,10 +142,10 @@ def deserialise(serialised_data, default=None, type_check=dict):
@return(object): deserialised data
@raise ValueError: serialised_data is of wrong type
"""
if serialised_data == u"":
if serialised_data == "":
return default
ret = json.loads(serialised_data)
if type_check is not None and not isinstance(ret, type_check):
raise ValueError(u"Bad data type, was expecting {type_check}, got {real_type}"
raise ValueError("Bad data type, was expecting {type_check}, got {real_type}"
.format(type_check=type_check, real_type=type(ret)))
return ret