str to bytes convert moved to wrapper

This commit is contained in:
ingvar1995 2018-07-21 20:43:16 +03:00
parent 7e08be71e0
commit e15620c3ad
4 changed files with 10 additions and 8 deletions

View file

@ -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

View file

@ -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)

View file

@ -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"""

View file

@ -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