From a714c1045d8e5d295bdef67b5ffab8d4cbb9dceb Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 23 Jun 2016 15:04:36 +0300 Subject: [PATCH] profile loading/creation update, bug fixes --- src/callbacks.py | 2 +- src/file_transfers.py | 2 +- src/loginscreen.py | 2 +- src/main.py | 11 +++++------ src/tox_dns.py | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index a1d4a26..484af3c 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -140,7 +140,7 @@ def friend_request(tox, public_key, message, message_size, user_data): key = ''.join(chr(x) for x in public_key[:TOX_PUBLIC_KEY_SIZE]) tox_id = bin_to_string(key, TOX_PUBLIC_KEY_SIZE) if tox_id not in Settings.get_instance()['blocked']: - invoke_in_main_thread(profile.process_friend_request, tox_id, message) + invoke_in_main_thread(profile.process_friend_request, tox_id, str(message, 'utf-8')) def friend_typing(tox, friend_number, typing, user_data): diff --git a/src/file_transfers.py b/src/file_transfers.py index fb64605..2c1f73e 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -121,7 +121,7 @@ class SendTransfer(FileTransfer): super(SendTransfer, self).__init__(path, tox, friend_number, size) self.state = TOX_FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED'] self._file_number = tox.file_send(friend_number, kind, size, file_id, - bytes(basename(path), 'utf-8') if path else '') + bytes(basename(path), 'utf-8') if path else b'') def send_chunk(self, position, size): """ diff --git a/src/loginscreen.py b/src/loginscreen.py index ed0d22a..df51c5b 100644 --- a/src/loginscreen.py +++ b/src/loginscreen.py @@ -83,7 +83,7 @@ class LoginScreen(CenteredWidget): def create_profile(self): self.type = 1 - self.name = self.new_name.toPlainText() + self.name = self.new_name.text() self.close() def load_ex_profile(self): diff --git a/src/main.py b/src/main.py index 7b725cf..297e8c4 100644 --- a/src/main.py +++ b/src/main.py @@ -11,7 +11,6 @@ from profile import tox_factory from callbacks import init_callbacks from util import curr_directory import styles.style -import locale import toxencryptsave from passwordscreen import PasswordScreen import profile @@ -62,8 +61,8 @@ class Toxygen: encrypt_save = toxencryptsave.LibToxEncryptSave() if self.path is not None: - path = os.path.dirname(self.path.encode(locale.getpreferredencoding())) + '/' - name = os.path.basename(self.path.encode(locale.getpreferredencoding()))[:-4] + path = os.path.dirname(self.path) + '/' + name = os.path.basename(self.path)[:-4] data = ProfileHelper(path, name).open_profile() if encrypt_save.is_data_encrypted(data): data = self.enter_pass(data) @@ -94,10 +93,11 @@ class Toxygen: if not _login.t: return elif _login.t == 1: # create new profile + _login.name = _login.name.strip() name = _login.name if _login.name else 'toxygen_user' self.tox = tox_factory() - self.tox.self_set_name(_login.name if _login.name else 'Toxygen User') - self.tox.self_set_status_message('Toxing on Toxygen') + self.tox.self_set_name(bytes(_login.name, 'utf-8') if _login.name else b'Toxygen User') + self.tox.self_set_status_message(b'Toxing on Toxygen') ProfileHelper(Settings.get_default_path(), name).save_profile(self.tox.get_savedata()) path = Settings.get_default_path() settings = Settings(name) @@ -112,7 +112,6 @@ class Toxygen: self.tox = tox_factory(data, settings) else: path, name = auto_profile - path = path.encode(locale.getpreferredencoding()) data = ProfileHelper(path, name).open_profile() if encrypt_save.is_data_encrypted(data): data = self.enter_pass(data) diff --git a/src/tox_dns.py b/src/tox_dns.py index 2f13551..914c827 100644 --- a/src/tox_dns.py +++ b/src/tox_dns.py @@ -22,8 +22,8 @@ def tox_dns(email): def send_request(url, data): req = urllib.request.Request(url) req.add_header('Content-Type', 'application/json') - response = urllib.request.urlopen(req, json.dumps(data)) - res = json.loads(response.read()) + response = urllib.request.urlopen(req, bytes(json.dumps(data), 'utf-8')) + res = json.loads(str(response.read(), 'utf-8')) if not res['c']: return res['tox_id'] else: