From e15620c3ad763b33659d5fa659cac6d007a3dc83 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 21 Jul 2018 20:43:16 +0300 Subject: [PATCH] str to bytes convert moved to wrapper --- tests/tests.py | 8 ++++---- toxygen/app.py | 4 ++-- toxygen/contacts/profile.py | 4 ++-- toxygen/wrapper/tox.py | 2 ++ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index 54e374e..e3c9b6b 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -6,13 +6,13 @@ from toxygen.middleware.tox_factory import * class TestTox: def test_creation(self): - name = b'Toxygen User' - status_message = b'Toxing on Toxygen' + name = 'Toxygen User' + status_message = 'Toxing on Toxygen' tox = tox_factory() tox.self_set_name(name) tox.self_set_status_message(status_message) data = tox.get_savedata() del tox tox = tox_factory(data) - assert tox.self_get_name() == str(name, 'utf-8') - assert tox.self_get_status_message() == str(status_message, 'utf-8') + assert tox.self_get_name() == name + assert tox.self_get_status_message() == status_message diff --git a/toxygen/app.py b/toxygen/app.py index 62025d9..ec0a1cb 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -251,8 +251,8 @@ class App: return False name = profile_name or 'toxygen_user' self._tox = tox_factory() - self._tox.self_set_name(bytes(name, 'utf-8') if name else b'Toxygen User') - self._tox.self_set_status_message(b'Toxing on Toxygen') + self._tox.self_set_name(name if name else 'Toxygen User') + self._tox.self_set_status_message('Toxing on Toxygen') self._path = profile_path if result.password: self._toxes.set_password(result.password) diff --git a/toxygen/contacts/profile.py b/toxygen/contacts/profile.py index ab8cb2a..c47eca2 100644 --- a/toxygen/contacts/profile.py +++ b/toxygen/contacts/profile.py @@ -51,11 +51,11 @@ class Profile(basecontact.BaseContact, tox_save.ToxSave): if self.name == value: return super().set_name(value) - self._tox.self_set_name(self._name.encode('utf-8')) + self._tox.self_set_name(self._name) def set_status_message(self, value): super().set_status_message(value) - self._tox.self_set_status_message(self._status_message.encode('utf-8')) + self._tox.self_set_status_message(self._status_message) def set_new_nospam(self): """Sets new nospam part of tox id""" diff --git a/toxygen/wrapper/tox.py b/toxygen/wrapper/tox.py index 836d38c..9cdac2e 100644 --- a/toxygen/wrapper/tox.py +++ b/toxygen/wrapper/tox.py @@ -375,6 +375,7 @@ class Tox: :return: True on success. """ tox_err_set_info = c_int() + name = bytes(name, 'utf-8') result = Tox.libtoxcore.tox_self_set_name(self._tox_pointer, c_char_p(name), c_size_t(len(name)), byref(tox_err_set_info)) tox_err_set_info = tox_err_set_info.value @@ -423,6 +424,7 @@ class Tox: :return: True on success. """ tox_err_set_info = c_int() + status_message = bytes(status_message, 'utf-8') result = Tox.libtoxcore.tox_self_set_status_message(self._tox_pointer, c_char_p(status_message), c_size_t(len(status_message)), byref(tox_err_set_info)) tox_err_set_info = tox_err_set_info.value