more typing
This commit is contained in:
parent
daee891825
commit
b934928fe3
9 changed files with 288 additions and 264 deletions
116
wrapper/tox.py
116
wrapper/tox.py
|
@ -1,4 +1,11 @@
|
|||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||
|
||||
# ctypes wrapping of libtoxcore
|
||||
|
||||
# WIP: - all functions are being changed to accept strings or byres for variables
|
||||
# the library will use as bytes, and return sstrings not bytes for things
|
||||
# you will use as strings. YMMV.
|
||||
|
||||
from ctypes import *
|
||||
from datetime import datetime
|
||||
from typing import Union, Callable, Union
|
||||
|
@ -7,12 +14,12 @@ try:
|
|||
from wrapper.libtox import LibToxCore
|
||||
from wrapper.toxav import ToxAV
|
||||
from wrapper.toxcore_enums_and_consts import *
|
||||
import wrapper.toxcore_enums_and_consts as enums
|
||||
import wrapper.toxcore_enums_and_consts as enum
|
||||
except:
|
||||
from libtox import LibToxCore
|
||||
from toxav import ToxAV
|
||||
from toxcore_enums_and_consts import *
|
||||
import toxcore_enums_and_consts as enums
|
||||
import toxcore_enums_and_consts as enum
|
||||
|
||||
# callbacks can be called in any thread so were being careful
|
||||
# tox.py can be called by callbacks
|
||||
|
@ -667,7 +674,7 @@ class Tox:
|
|||
' returned from tox_friend_add_norequest.')
|
||||
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OWN_KEY']:
|
||||
raise ArgumentError('The friend address belongs to the sending client.')
|
||||
elif tox_err_friend_add == TOX_ERR_FRIEND_ADD['ALREADY_SENT']:
|
||||
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['ALREADY_SENT']:
|
||||
raise ArgumentError('A friend request has already been sent, or the address belongs to a friend that is'
|
||||
' already on the friend list.')
|
||||
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['BAD_CHECKSUM']:
|
||||
|
@ -805,7 +812,7 @@ class Tox:
|
|||
Tox.libtoxcore.tox_self_get_friend_list(self._tox_pointer, friend_list)
|
||||
return friend_list[0:friend_list_size]
|
||||
|
||||
def friend_get_public_key(self, friend_number: int, public_key: str=None) -> str:
|
||||
def friend_get_public_key(self, friend_number: int, public_key: Union[bytes,None]=None) -> str:
|
||||
"""
|
||||
Copies the Public Key associated with a given friend number to a byte array.
|
||||
|
||||
|
@ -826,6 +833,7 @@ class Tox:
|
|||
return bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE)
|
||||
elif tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('No friend with the given number exists on the friend list.')
|
||||
raise ToxError('The function did not return OK')
|
||||
|
||||
def friend_get_last_online(self, friend_number: int) -> int:
|
||||
"""
|
||||
|
@ -938,12 +946,13 @@ class Tox:
|
|||
tox_err_friend_query = tox_err_friend_query.value
|
||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
|
||||
return int(result)
|
||||
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
||||
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
|
||||
' the `_self_` variants of these functions, which have no effect when a parameter is'
|
||||
' NULL, these functions return an error in that case.')
|
||||
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
|
||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('The friend_number did not designate a valid friend.')
|
||||
raise ToxError('The function did not return OK')
|
||||
|
||||
def friend_get_status_message(self, friend_number: int, status_message=None) -> str:
|
||||
"""
|
||||
|
@ -1020,11 +1029,11 @@ class Tox:
|
|||
tox_err_friend_query = tox_err_friend_query.value
|
||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
|
||||
return int(result)
|
||||
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
||||
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
|
||||
' the `_self_` variants of these functions, which have no effect when a parameter is'
|
||||
' NULL, these functions return an error in that case.')
|
||||
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
|
||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('The friend_number did not designate a valid friend.')
|
||||
raise ToxError('The function did not return OK.')
|
||||
|
||||
|
@ -1069,11 +1078,11 @@ class Tox:
|
|||
tox_err_friend_query = tox_err_friend_query.value
|
||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
|
||||
return int(result)
|
||||
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['NULL']:
|
||||
raise ArgumentError('The pointer parameter for storing the query result (name, message) was NULL. Unlike'
|
||||
' the `_self_` variants of these functions, which have no effect when a parameter is'
|
||||
' NULL, these functions return an error in that case.')
|
||||
elif tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
|
||||
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('The friend_number did not designate a valid friend.')
|
||||
raise ToxError('The function did not return OK for friend get connection status.')
|
||||
|
||||
|
@ -1200,23 +1209,25 @@ class Tox:
|
|||
message = bytes(message, 'utf-8')
|
||||
tox_err_friend_send_message = c_int()
|
||||
LOG_DEBUG(f"tox.friend_send_message")
|
||||
result = Tox.libtoxcore.tox_friend_send_message(self._tox_pointer, c_uint32(friend_number),
|
||||
c_int(message_type), c_char_p(message), c_size_t(len(message)),
|
||||
result = Tox.libtoxcore.tox_friend_send_message(self._tox_pointer,
|
||||
c_uint32(friend_number),
|
||||
c_int(message_type),
|
||||
c_char_p(message), c_size_t(len(message)),
|
||||
byref(tox_err_friend_send_message))
|
||||
tox_err_friend_send_message = tox_err_friend_send_message.value
|
||||
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['OK']:
|
||||
return int(result)
|
||||
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['NULL']:
|
||||
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['NULL']:
|
||||
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
|
||||
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['FRIEND_NOT_FOUND']:
|
||||
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('The friend number did not designate a valid friend.')
|
||||
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['FRIEND_NOT_CONNECTED']:
|
||||
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['FRIEND_NOT_CONNECTED']:
|
||||
raise ArgumentError('This client is currently not connected to the friend.')
|
||||
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['SENDQ']:
|
||||
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['SENDQ']:
|
||||
raise MemoryError('An allocation error occurred while increasing the send queue size.')
|
||||
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['TOO_LONG']:
|
||||
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['TOO_LONG']:
|
||||
raise ArgumentError('Message length exceeded TOX_MAX_MESSAGE_LENGTH.')
|
||||
elif tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['EMPTY']:
|
||||
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['EMPTY']:
|
||||
raise ArgumentError('Attempted to send a zero-length message.')
|
||||
raise ToxError('The function did not return OK for friend send message.')
|
||||
|
||||
|
@ -1444,8 +1455,9 @@ class Tox:
|
|||
if error.value == TOX_ERR_FILE_GET['OK']:
|
||||
return bin_to_string(file_id, TOX_FILE_ID_LENGTH)
|
||||
s = sGetError(error.value, TOX_ERR_FILE_GET)
|
||||
LOG_ERROR(f"group_new {error.value} {s}")
|
||||
raise ArgumentError(f"group_new {error.value} {s}")
|
||||
LOG_ERROR(f"group_new err={error.value} {s}")
|
||||
# have seen ArgumentError: group_new 3 NOT_FOUND
|
||||
raise ArgumentError(f"group_new err={error.value} {s}")
|
||||
|
||||
# File transmission: sending
|
||||
|
||||
|
@ -1702,20 +1714,20 @@ class Tox:
|
|||
tox_err_friend_custom_packet = tox_err_friend_custom_packet.value
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['OK']:
|
||||
return bool(result)
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['NULL']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['NULL']:
|
||||
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['FRIEND_NOT_FOUND']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('The friend number did not designate a valid friend.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['FRIEND_NOT_CONNECTED']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['FRIEND_NOT_CONNECTED']:
|
||||
raise ArgumentError('This client is currently not connected to the friend.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['INVALID']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['INVALID']:
|
||||
raise ArgumentError('The first byte of data was not in the specified range for the packet type.'
|
||||
'This range is 200-254 for lossy, and 160-191 for lossless packets.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['EMPTY']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['EMPTY']:
|
||||
raise ArgumentError('Attempted to send an empty packet.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['TOO_LONG']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['TOO_LONG']:
|
||||
raise ArgumentError('Packet data length exceeded TOX_MAX_CUSTOM_PACKET_SIZE.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['SENDQ']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['SENDQ']:
|
||||
raise ToxError('Packet queue is full.')
|
||||
raise ToxError('The function did not return OK')
|
||||
|
||||
|
@ -1740,21 +1752,22 @@ class Tox:
|
|||
tox_err_friend_custom_packet = tox_err_friend_custom_packet.value
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['OK']:
|
||||
return bool(result)
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['NULL']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['NULL']:
|
||||
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['FRIEND_NOT_FOUND']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('The friend number did not designate a valid friend.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['FRIEND_NOT_CONNECTED']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['FRIEND_NOT_CONNECTED']:
|
||||
raise ArgumentError('This client is currently not connected to the friend.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['INVALID']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['INVALID']:
|
||||
raise ArgumentError('The first byte of data was not in the specified range for the packet type.'
|
||||
'This range is 200-254 for lossy, and 160-191 for lossless packets.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['EMPTY']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['EMPTY']:
|
||||
raise ArgumentError('Attempted to send an empty packet.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['TOO_LONG']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['TOO_LONG']:
|
||||
raise ArgumentError('Packet data length exceeded TOX_MAX_CUSTOM_PACKET_SIZE.')
|
||||
elif tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['SENDQ']:
|
||||
if tox_err_friend_custom_packet == TOX_ERR_FRIEND_CUSTOM_PACKET['SENDQ']:
|
||||
raise ToxError('Packet queue is full.')
|
||||
raise ToxError('The function did not return OK')
|
||||
|
||||
def callback_friend_lossy_packet(self, callback: Callable) -> None:
|
||||
"""
|
||||
|
@ -1890,7 +1903,7 @@ class Tox:
|
|||
|
||||
if error.value:
|
||||
s = sGetError(error.value, TOX_ERR_GROUP_NEW)
|
||||
LOG_ERROR(f"group_new {error.value} {s}")
|
||||
LOG_ERROR(f"group_new err={error.value} {s}")
|
||||
raise ToxError(f"group_new {s} err={error.value}")
|
||||
|
||||
# TypeError: '<' not supported between instances of 'c_uint' and 'int'
|
||||
|
@ -1971,7 +1984,7 @@ class Tox:
|
|||
byref(error))
|
||||
if error.value:
|
||||
s = sGetError(error.value, TOX_ERR_GROUP_RECONNECT)
|
||||
LOG_ERROR(f"group_new {error.value} {s}")
|
||||
LOG_ERROR(f"group_new err={error.value} {s}")
|
||||
raise ToxError(f"group_new {s} err={error.value}")
|
||||
return bool(result)
|
||||
|
||||
|
@ -1997,7 +2010,7 @@ class Tox:
|
|||
result = Tox.libtoxcore.tox_group_disconnect(self._tox_pointer, c_uint32(group_number), byref(error))
|
||||
if error.value:
|
||||
s = sGetError(error.value, TOX_ERR_GROUP_DISCONNECT)
|
||||
LOG_ERROR(f"group_disconnect {error.value} {s}")
|
||||
LOG_ERROR(f"group_disconnect err={error.value} {s}")
|
||||
raise ToxError(f"group_disconnect {s} err={error.value}")
|
||||
return bool(result)
|
||||
|
||||
|
@ -2051,9 +2064,12 @@ class Tox:
|
|||
|
||||
error = c_int()
|
||||
if type(name) != bytes:
|
||||
topic = bytes(name, 'utf-8')
|
||||
name = bytes(name, 'utf-8')
|
||||
LOG_DEBUG(f"tox.group_self_set_name")
|
||||
result = Tox.libtoxcore.tox_group_self_set_name(self._tox_pointer, c_uint32(group_number), name, c_size_t(len(name)), byref(error))
|
||||
result = Tox.libtoxcore.tox_group_self_set_name(self._tox_pointer,
|
||||
c_uint32(group_number),
|
||||
c_char_p(name), c_size_t(len(name)),
|
||||
byref(error))
|
||||
if error.value:
|
||||
LOG_ERROR(f"group_self_set_name err={error.value}")
|
||||
raise ToxError("group_self_set_name err={error.value}")
|
||||
|
@ -2346,7 +2362,7 @@ class Tox:
|
|||
Tox.libtoxcore.tox_callback_group_peer_name(self._tox_pointer, self.group_peer_name_cb)
|
||||
except Exception as e: # AttributeError
|
||||
LOG_ERROR(f"tox.callback_conference_peer_name")
|
||||
return None
|
||||
return
|
||||
|
||||
def callback_group_peer_status(self, callback: Callable, user_data) -> int:
|
||||
"""
|
||||
|
@ -2369,7 +2385,7 @@ class Tox:
|
|||
Tox.libtoxcore.tox_callback_group_peer_status(self._tox_pointer, self.group_peer_status_cb)
|
||||
except Exception as e:
|
||||
LOG_WARN(f"callback_group_peer_status Exception {e}")
|
||||
return None
|
||||
return
|
||||
|
||||
# Group chat state queries and events.
|
||||
|
||||
|
@ -2712,7 +2728,7 @@ class Tox:
|
|||
|
||||
# Group message sending
|
||||
|
||||
def group_send_custom_packet(self, group_number: int, lossless: bool, data) -> bool:
|
||||
def group_send_custom_packet(self, group_number: int, lossless: bool, data: bytes) -> bool:
|
||||
"""Send a custom packet to the group.
|
||||
|
||||
If lossless is true the packet will be lossless. Lossless
|
||||
|
@ -2786,8 +2802,8 @@ class Tox:
|
|||
byref(error))
|
||||
if error.value:
|
||||
s = sGetError(error.value, TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE)
|
||||
LOG_ERROR(f"group_send_private_message {error.value} {s}")
|
||||
raise ToxError(f"group_send_private_message {error.value} {s}")
|
||||
LOG_ERROR(f"group_send_private_message err={error.value} {s}")
|
||||
raise ToxError(f"group_send_private_message err={error.value} {s}")
|
||||
|
||||
return bool(result)
|
||||
|
||||
|
@ -2829,8 +2845,8 @@ class Tox:
|
|||
|
||||
if error.value:
|
||||
s = sGetError(error.value, TOX_ERR_GROUP_SEND_MESSAGE)
|
||||
LOG_ERROR(f"group_send_message {error.value} {s}")
|
||||
raise ToxError(f"group_send_message {error.value} {s}")
|
||||
LOG_ERROR(f"group_send_message err={error.value} {s}")
|
||||
raise ToxError(f"group_send_message err={error.value} {s}")
|
||||
|
||||
return bool(result)
|
||||
|
||||
|
@ -2915,8 +2931,8 @@ class Tox:
|
|||
result = Tox.libtoxcore.tox_group_invite_friend(self._tox_pointer, c_uint(group_number), c_uint32(friend_number), byref(error))
|
||||
if error.value:
|
||||
s = sGetError(error.value, TOX_ERR_GROUP_INVITE_FRIEND)
|
||||
LOG_ERROR(f"group_invite_friend {error.value} {s}")
|
||||
raise ToxError(f"group_invite_friend {error.value} {s}")
|
||||
LOG_ERROR(f"group_invite_friend err={error.value} {s}")
|
||||
raise ToxError(f"group_invite_friend err={error.value} {s}")
|
||||
return bool(result)
|
||||
|
||||
# API change - this no longer exists
|
||||
|
@ -2976,7 +2992,7 @@ class Tox:
|
|||
raise ToxError(f"group_invite_accept ERROR {e}")
|
||||
if error.value:
|
||||
s = sGetError(error.value, TOX_ERR_GROUP_INVITE_ACCEPT)
|
||||
LOG_ERROR(f"group_invite_friend {error.value} {s}")
|
||||
LOG_ERROR(f"group_invite_friend err={error.value} {s}")
|
||||
raise ToxError(f"group_invite_accept {s} err={error.value}")
|
||||
return result
|
||||
|
||||
|
@ -3136,7 +3152,7 @@ class Tox:
|
|||
byref(error))
|
||||
if error.value:
|
||||
s = sGetError(error.value, TOX_ERR_GROUP_FOUNDER_SET_PASSWORD)
|
||||
LOG_ERROR(f"group_founder_set_password {error.value} {s}")
|
||||
LOG_ERROR(f"group_founder_set_password err={error.value} {s}")
|
||||
raise ToxError(f"group_founder_set_password {s} err={error.value}")
|
||||
return bool(result)
|
||||
|
||||
|
|
|
@ -42,10 +42,10 @@ class ToxAV:
|
|||
toxav_err_new = toxav_err_new.value
|
||||
if toxav_err_new == enum.TOXAV_ERR_NEW['NULL']:
|
||||
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
|
||||
elif toxav_err_new == enum.TOXAV_ERR_NEW['MALLOC']:
|
||||
if toxav_err_new == enum.TOXAV_ERR_NEW['MALLOC']:
|
||||
raise MemoryError('Memory allocation failure while trying to allocate structures required for the A/V '
|
||||
'session.')
|
||||
elif toxav_err_new == enum.TOXAV_ERR_NEW['MULTIPLE']:
|
||||
if toxav_err_new == enum.TOXAV_ERR_NEW['MULTIPLE']:
|
||||
raise RuntimeError('Attempted to create a second session for the same Tox instance.')
|
||||
|
||||
self.call_state_cb = None
|
||||
|
@ -124,6 +124,7 @@ class ToxAV:
|
|||
raise ArgumentError('Attempted to call a friend while already in an audio or video call with them.')
|
||||
elif toxav_err_call == enum.TOXAV_ERR_CALL['INVALID_BIT_RATE']:
|
||||
raise ArgumentError('Audio or video bit rate is invalid.')
|
||||
raise ArgumentError('The function did not return OK')
|
||||
|
||||
def callback_call(self, callback: Callable, user_data) -> None:
|
||||
"""
|
||||
|
@ -169,18 +170,19 @@ class ToxAV:
|
|||
toxav_err_answer = toxav_err_answer.value
|
||||
if toxav_err_answer == enum.TOXAV_ERR_ANSWER['OK']:
|
||||
return bool(result)
|
||||
elif toxav_err_answer == enum.TOXAV_ERR_ANSWER['SYNC']:
|
||||
if toxav_err_answer == enum.TOXAV_ERR_ANSWER['SYNC']:
|
||||
raise RuntimeError('Synchronization error occurred.')
|
||||
elif toxav_err_answer == enum.TOXAV_ERR_ANSWER['CODEC_INITIALIZATION']:
|
||||
if toxav_err_answer == enum.TOXAV_ERR_ANSWER['CODEC_INITIALIZATION']:
|
||||
raise RuntimeError('Failed to initialize codecs for call session. Note that codec initiation will fail if '
|
||||
'there is no receive callback registered for either audio or video.')
|
||||
elif toxav_err_answer == enum.TOXAV_ERR_ANSWER['FRIEND_NOT_FOUND']:
|
||||
if toxav_err_answer == enum.TOXAV_ERR_ANSWER['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('The friend number did not designate a valid friend.')
|
||||
elif toxav_err_answer == enum.TOXAV_ERR_ANSWER['FRIEND_NOT_CALLING']:
|
||||
if toxav_err_answer == enum.TOXAV_ERR_ANSWER['FRIEND_NOT_CALLING']:
|
||||
raise ArgumentError('The friend was valid, but they are not currently trying to initiate a call. This is '
|
||||
'also returned if this client is already in a call with the friend.')
|
||||
elif toxav_err_answer == enum.TOXAV_ERR_ANSWER['INVALID_BIT_RATE']:
|
||||
if toxav_err_answer == enum.TOXAV_ERR_ANSWER['INVALID_BIT_RATE']:
|
||||
raise ArgumentError('Audio or video bit rate is invalid.')
|
||||
raise ToxError('The function did not return OK')
|
||||
|
||||
# Call state graph
|
||||
|
||||
|
@ -224,16 +226,17 @@ class ToxAV:
|
|||
toxav_err_call_control = toxav_err_call_control.value
|
||||
if toxav_err_call_control == enum.TOXAV_ERR_CALL_CONTROL['OK']:
|
||||
return bool(result)
|
||||
elif toxav_err_call_control == enum.TOXAV_ERR_CALL_CONTROL['SYNC']:
|
||||
if toxav_err_call_control == enum.TOXAV_ERR_CALL_CONTROL['SYNC']:
|
||||
raise RuntimeError('Synchronization error occurred.')
|
||||
elif toxav_err_call_control == enum.TOXAV_ERR_CALL_CONTROL['FRIEND_NOT_FOUND']:
|
||||
if toxav_err_call_control == enum.TOXAV_ERR_CALL_CONTROL['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('The friend_number passed did not designate a valid friend.')
|
||||
elif toxav_err_call_control == enum.TOXAV_ERR_CALL_CONTROL['FRIEND_NOT_IN_CALL']:
|
||||
if toxav_err_call_control == enum.TOXAV_ERR_CALL_CONTROL['FRIEND_NOT_IN_CALL']:
|
||||
raise RuntimeError('This client is currently not in a call with the friend. Before the call is answered, '
|
||||
'only CANCEL is a valid control.')
|
||||
elif toxav_err_call_control == enum.TOXAV_ERR_CALL_CONTROL['INVALID_TRANSITION']:
|
||||
if toxav_err_call_control == enum.TOXAV_ERR_CALL_CONTROL['INVALID_TRANSITION']:
|
||||
raise RuntimeError('Happens if user tried to pause an already paused call or if trying to resume a call '
|
||||
'that is not paused.')
|
||||
raise ToxError('The function did not return OK.')
|
||||
|
||||
# TODO Controlling bit rates
|
||||
|
||||
|
@ -267,22 +270,23 @@ class ToxAV:
|
|||
toxav_err_send_frame = toxav_err_send_frame.value
|
||||
if toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['OK']:
|
||||
return bool(result)
|
||||
elif toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['NULL']:
|
||||
if toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['NULL']:
|
||||
raise ArgumentError('The samples data pointer was NULL.')
|
||||
elif toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['FRIEND_NOT_FOUND']:
|
||||
if toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['FRIEND_NOT_FOUND']:
|
||||
raise ArgumentError('The friend_number passed did not designate a valid friend.')
|
||||
elif toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['FRIEND_NOT_IN_CALL']:
|
||||
if toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['FRIEND_NOT_IN_CALL']:
|
||||
raise RuntimeError('This client is currently not in a call with the friend.')
|
||||
elif toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['SYNC']:
|
||||
if toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['SYNC']:
|
||||
raise RuntimeError('Synchronization error occurred.')
|
||||
elif toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['INVALID']:
|
||||
if toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['INVALID']:
|
||||
raise ArgumentError('One of the frame parameters was invalid. E.g. the resolution may be too small or too '
|
||||
'large, or the audio sampling rate may be unsupported.')
|
||||
elif toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['PAYLOAD_TYPE_DISABLED']:
|
||||
if toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['PAYLOAD_TYPE_DISABLED']:
|
||||
raise RuntimeError('Either friend turned off audio or video receiving or we turned off sending for the said'
|
||||
'payload.')
|
||||
elif toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['RTP_FAILED']:
|
||||
if toxav_err_send_frame == enum.TOXAV_ERR_SEND_FRAME['RTP_FAILED']:
|
||||
RuntimeError('Failed to push frame through rtp interface.')
|
||||
raise ToxError('The function did not return OK.')
|
||||
|
||||
def video_send_frame(self, friend_number: int, width: int, height: int, y, u, v) -> None:
|
||||
"""
|
||||
|
|
|
@ -46,13 +46,14 @@ class ToxEncryptSave:
|
|||
tox_err_encryption = tox_err_encryption.value
|
||||
if tox_err_encryption == enum.TOX_ERR_ENCRYPTION['OK']:
|
||||
return out[:]
|
||||
elif tox_err_encryption == enum.TOX_ERR_ENCRYPTION['NULL']:
|
||||
if tox_err_encryption == enum.TOX_ERR_ENCRYPTION['NULL']:
|
||||
raise ArgumentError('Some input data, or maybe the output pointer, was null.')
|
||||
elif tox_err_encryption == enum.TOX_ERR_ENCRYPTION['KEY_DERIVATION_FAILED']:
|
||||
if tox_err_encryption == enum.TOX_ERR_ENCRYPTION['KEY_DERIVATION_FAILED']:
|
||||
raise RuntimeError('The crypto lib was unable to derive a key from the given passphrase, which is usually a'
|
||||
' lack of memory issue. The functions accepting keys do not produce this error.')
|
||||
elif tox_err_encryption == enum.TOX_ERR_ENCRYPTION['FAILED']:
|
||||
if tox_err_encryption == enum.TOX_ERR_ENCRYPTION['FAILED']:
|
||||
raise RuntimeError('The encryption itself failed.')
|
||||
raise ToxError('The function did not return OK.')
|
||||
|
||||
def pass_decrypt(self, data: bytes, password: str) -> bytes:
|
||||
"""
|
||||
|
|
|
@ -16,7 +16,6 @@ import traceback
|
|||
import threading
|
||||
import random
|
||||
from ctypes import *
|
||||
import argparse
|
||||
import time
|
||||
|
||||
# LOG=util.log
|
||||
|
@ -32,7 +31,7 @@ def LOG_trace(a): pass # print('TRAC_ '+a)
|
|||
|
||||
import wrapper
|
||||
import wrapper.toxcore_enums_and_consts as enums
|
||||
from wrapper.tox import Tox, UINT32_MAX, ToxError
|
||||
from wrapper.tox import Tox, UINT32_MAX
|
||||
from wrapper.toxcore_enums_and_consts import TOX_CONNECTION, TOX_USER_STATUS, \
|
||||
TOX_MESSAGE_TYPE, TOX_PUBLIC_KEY_SIZE, TOX_FILE_CONTROL, TOX_FILE_KIND
|
||||
|
||||
|
@ -54,7 +53,6 @@ except ImportError as e:
|
|||
# logging.log(logging.DEBUG, f"coloredlogs not available: {e}")
|
||||
coloredlogs = None
|
||||
|
||||
import wrapper_tests.support_testing as ts
|
||||
if 'USER' in os.environ:
|
||||
sDATA_FILE = '/tmp/logging_toxygen_' +os.environ['USER'] +'.tox'
|
||||
elif 'USERNAME' in os.environ:
|
||||
|
@ -276,9 +274,9 @@ class EchoBot():
|
|||
LOG.info('on_friend_request Accepted.')
|
||||
save_to_file(self._tox, sDATA_FILE)
|
||||
|
||||
def on_friend_message(self, friendId, type, message) -> None:
|
||||
def on_friend_message(self, friendId, message_type , message) -> None:
|
||||
name = self._tox.friend_get_name(friendId)
|
||||
LOG.debug('%s: %s' % (name, message))
|
||||
LOG.debug(f"{name}, {message}, {message_type}")
|
||||
yMessage = bytes(message, 'UTF-8')
|
||||
self._tox.friend_send_message(friendId, TOX_MESSAGE_TYPE['NORMAL'], yMessage)
|
||||
LOG.info('EchoBot sent: %s' % message)
|
||||
|
@ -311,7 +309,7 @@ class EchobotTox(Tox):
|
|||
|
||||
def __init__(self, opts, app=None):
|
||||
|
||||
super(EchobotTox, self).__init__(opts, app=app)
|
||||
super().__init__(opts, app=app)
|
||||
self._address = self.self_get_address()
|
||||
self.name = 'pyechobot'
|
||||
self._opts = opts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue