minor update
This commit is contained in:
parent
c8e0adcb3e
commit
403f5e7468
17
README.md
17
README.md
@ -1,12 +1,12 @@
|
|||||||
# toxygen_wrapper
|
# toxygen_wrapper
|
||||||
|
|
||||||
ctypes wrapping of [Tox](https://tox.chat/) libtoxcore
|
ctypes wrapping of [Tox](https://tox.chat/) libtoxcore
|
||||||
<https://github.com/TokTok/c-toxcore>
|
<https://github.com/TokTok/c-toxcore> into Python.
|
||||||
into Python. Taken from the wrapper directory of the now abandoned
|
Taken from the wrapper directory of the now abandoned
|
||||||
<https://github.com/toxygen-project/toxygen> `next_gen` branch
|
<https://github.com/toxygen-project/toxygen> `next_gen` branch
|
||||||
by Ingvar.
|
by Ingvar.
|
||||||
|
|
||||||
The basics of NGC groups are supported.
|
The basics of NGC groups are supported, as well as AV and toxencryptsave.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ No prerequisites in Python3.
|
|||||||
There are a number of other wrappings into Python of Tox core.
|
There are a number of other wrappings into Python of Tox core.
|
||||||
This one uses CTYPES which has its merits - there is no need to
|
This one uses CTYPES which has its merits - there is no need to
|
||||||
recompile anything as with Cython - change the Python file and it's done.
|
recompile anything as with Cython - change the Python file and it's done.
|
||||||
CTYPES code can be brittle, segfaulting if you got things wrong,
|
CTYPES code can be brittle, segfaulting if you've got things wrong,
|
||||||
but if your wrapping is right, it is very efficient and easy to work on.
|
but if your wrapping is right, it is very efficient and easy to work on.
|
||||||
|
|
||||||
Others include:
|
Others include:
|
||||||
@ -30,11 +30,12 @@ Others include:
|
|||||||
* <https://github.com/TokTok/py-toxcore-c> Cython bindings.
|
* <https://github.com/TokTok/py-toxcore-c> Cython bindings.
|
||||||
Incomplete and not really actively supported. Maybe it will get
|
Incomplete and not really actively supported. Maybe it will get
|
||||||
worked on in the future, but TokTok seems to be working on
|
worked on in the future, but TokTok seems to be working on
|
||||||
java, rust, go, etc. bindings instead.
|
java, rust, scalla, go, etc. bindings instead.
|
||||||
|
No support for NGC groups or toxencryptsave.
|
||||||
|
|
||||||
* <https://github.com/oxij/PyTox>
|
* <https://github.com/oxij/PyTox>
|
||||||
forked from https://github.com/aitjcize/PyTox
|
forked from https://github.com/aitjcize/PyTox
|
||||||
by Wei-Ning Huang <aitjcize@gmail.com>.
|
by Wei-Ning Huang <aitjcize@gmail.com>.
|
||||||
Abandonned. Hardcore C wrapping which is not easy to keep up to date.
|
Hardcore C wrapping which is not easy to keep up to date.
|
||||||
|
No support for NGC or toxencryptsave. Abandonned.
|
||||||
|
This was the basis for the TokTok/py-toxcore-c code until recently.
|
||||||
|
5
wrapper/__init__.py
Normal file
5
wrapper/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
|
# You need a libs directory beside this directory
|
||||||
|
# and you need to link your libtoxcore.so and libtoxav.so
|
||||||
|
# and libtoxencryptsave.so into ../libs/
|
||||||
|
# Link all 3 to libtoxcore.so if you have only libtoxcore.so
|
@ -1,4 +1,5 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from ctypes import CDLL
|
from ctypes import CDLL
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
|
||||||
|
|
||||||
from wrapper.toxcore_enums_and_consts import *
|
try:
|
||||||
from wrapper.toxav import ToxAV
|
from wrapper.toxcore_enums_and_consts import *
|
||||||
from wrapper.libtox import LibToxCore
|
from wrapper.toxav import ToxAV
|
||||||
|
from wrapper.libtox import LibToxCore
|
||||||
|
except:
|
||||||
|
from toxcore_enums_and_consts import *
|
||||||
|
from toxav import ToxAV
|
||||||
|
from libtox import LibToxCore
|
||||||
|
|
||||||
global LOG
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
def LOG_ERROR(a): print('EROR> '+a)
|
def LOG_ERROR(a): print('EROR> '+a)
|
||||||
def LOG_WARN(a): print('WARN> '+a)
|
def LOG_WARN(a): print('WARN> '+a)
|
||||||
def LOG_INFO(a): print('INFO> '+a)
|
def LOG_INFO(a): print('INFO> '+a)
|
||||||
@ -163,6 +165,7 @@ class Tox:
|
|||||||
|
|
||||||
def kill(self):
|
def kill(self):
|
||||||
if hasattr(self, 'AV'): del self.AV
|
if hasattr(self, 'AV'): del self.AV
|
||||||
|
LOG_DEBUG(f"tox_kill")
|
||||||
try:
|
try:
|
||||||
Tox.libtoxcore.tox_kill(self._tox_pointer)
|
Tox.libtoxcore.tox_kill(self._tox_pointer)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -270,7 +273,7 @@ class Tox:
|
|||||||
:return: True on success.
|
:return: True on success.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# LOG_DEBUG(f"tox_bootstrap")
|
LOG_DEBUG(f"tox_bootstrap={address}")
|
||||||
address = bytes(address, 'utf-8')
|
address = bytes(address, 'utf-8')
|
||||||
tox_err_bootstrap = c_int()
|
tox_err_bootstrap = c_int()
|
||||||
try:
|
try:
|
||||||
@ -340,9 +343,9 @@ class Tox:
|
|||||||
"""
|
"""
|
||||||
iRet = Tox.libtoxcore.tox_self_get_connection_status(self._tox_pointer)
|
iRet = Tox.libtoxcore.tox_self_get_connection_status(self._tox_pointer)
|
||||||
if iRet > 2:
|
if iRet > 2:
|
||||||
# LOG_ERROR(f"self_get_connection_status {iRet} > 2")
|
LOG_ERROR(f"self_get_connection_status {iRet} > 2")
|
||||||
# return 0
|
return 0
|
||||||
pass
|
LOG_TRACE(f"self_get_connection_status {iRet}")
|
||||||
return iRet
|
return iRet
|
||||||
|
|
||||||
def callback_self_connection_status(self, callback):
|
def callback_self_connection_status(self, callback):
|
||||||
@ -363,7 +366,6 @@ class Tox:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
if callback is None:
|
if callback is None:
|
||||||
LOG_DEBUG(f"tox_callback_self_connection_status")
|
|
||||||
Tox.libtoxcore.tox_callback_self_connection_status(self._tox_pointer,
|
Tox.libtoxcore.tox_callback_self_connection_status(self._tox_pointer,
|
||||||
POINTER(None)())
|
POINTER(None)())
|
||||||
self.self_connection_status_cb = None
|
self.self_connection_status_cb = None
|
||||||
@ -391,12 +393,13 @@ class Tox:
|
|||||||
if user_data is not None:
|
if user_data is not None:
|
||||||
user_data = c_char_p(user_data)
|
user_data = c_char_p(user_data)
|
||||||
try:
|
try:
|
||||||
|
LOG_TRACE(f"tox_iterate")
|
||||||
Tox.libtoxcore.tox_iterate(self._tox_pointer, user_data)
|
Tox.libtoxcore.tox_iterate(self._tox_pointer, user_data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Fatal Python error: Segmentation fault
|
# Fatal Python error: Segmentation fault
|
||||||
LOG_ERROR(f"iterate {e!s}")
|
LOG_ERROR(f"iterate {e!s}")
|
||||||
else:
|
else:
|
||||||
LOG_TRACE(f"tox_iterate")
|
LOG_TRACE(f"iterate")
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Internal client information (Tox address/id)
|
# Internal client information (Tox address/id)
|
||||||
@ -1223,7 +1226,6 @@ class Tox:
|
|||||||
pointer (c_void_p) to user_data
|
pointer (c_void_p) to user_data
|
||||||
:param user_data: pointer (c_void_p) to user data
|
:param user_data: pointer (c_void_p) to user data
|
||||||
"""
|
"""
|
||||||
LOG_DEBUG(f"tox_callback_friend_request")
|
|
||||||
if callback is None:
|
if callback is None:
|
||||||
Tox.libtoxcore.tox_callback_friend_request(self._tox_pointer,
|
Tox.libtoxcore.tox_callback_friend_request(self._tox_pointer,
|
||||||
POINTER(None)())
|
POINTER(None)())
|
||||||
@ -2169,12 +2171,12 @@ class Tox:
|
|||||||
error = c_int()
|
error = c_int()
|
||||||
size = self.group_peer_get_name_size(group_number, peer_id)
|
size = self.group_peer_get_name_size(group_number, peer_id)
|
||||||
name = create_string_buffer(size)
|
name = create_string_buffer(size)
|
||||||
|
LOG_DEBUG(f"tox_group_peer_get_name")
|
||||||
result = Tox.libtoxcore.tox_group_peer_get_name(self._tox_pointer, group_number, peer_id, name, byref(error))
|
result = Tox.libtoxcore.tox_group_peer_get_name(self._tox_pointer, group_number, peer_id, name, byref(error))
|
||||||
if error.value:
|
if error.value:
|
||||||
LOG_ERROR(f" {error.value}")
|
LOG_ERROR(f" {error.value}")
|
||||||
raise RuntimeError(f"tox_group_peer_get_name {error.value}")
|
raise RuntimeError(f"tox_group_peer_get_name {error.value}")
|
||||||
sRet = str(name[:], 'utf-8', errors='ignore')
|
sRet = str(name[:], 'utf-8', errors='ignore')
|
||||||
LOG_DEBUG(f"tox_group_peer_get_name {sRet}")
|
|
||||||
return sRet
|
return sRet
|
||||||
|
|
||||||
def group_peer_get_status(self, group_number, peer_id):
|
def group_peer_get_status(self, group_number, peer_id):
|
||||||
@ -2312,6 +2314,7 @@ class Tox:
|
|||||||
|
|
||||||
error = c_int()
|
error = c_int()
|
||||||
try:
|
try:
|
||||||
|
LOG_DEBUG(f"tox_group_get_topic_size")
|
||||||
result = Tox.libtoxcore.tox_group_get_topic_size(self._tox_pointer, group_number, byref(error))
|
result = Tox.libtoxcore.tox_group_get_topic_size(self._tox_pointer, group_number, byref(error))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG_WARN(f" Exception {e}")
|
LOG_WARN(f" Exception {e}")
|
||||||
@ -2349,6 +2352,7 @@ class Tox:
|
|||||||
return value is unspecified.
|
return value is unspecified.
|
||||||
"""
|
"""
|
||||||
error = c_int()
|
error = c_int()
|
||||||
|
LOG_DEBUG(f"tox_group_get_name_size")
|
||||||
result = Tox.libtoxcore.tox_group_get_name_size(self._tox_pointer, group_number, byref(error))
|
result = Tox.libtoxcore.tox_group_get_name_size(self._tox_pointer, group_number, byref(error))
|
||||||
if error.value:
|
if error.value:
|
||||||
LOG_ERROR(f" {error.value}")
|
LOG_ERROR(f" {error.value}")
|
||||||
@ -2383,6 +2387,7 @@ class Tox:
|
|||||||
|
|
||||||
error = c_int()
|
error = c_int()
|
||||||
buff = create_string_buffer(TOX_GROUP_CHAT_ID_SIZE)
|
buff = create_string_buffer(TOX_GROUP_CHAT_ID_SIZE)
|
||||||
|
LOG_DEBUG(f"tox_group_get_chat_id")
|
||||||
result = Tox.libtoxcore.tox_group_get_chat_id(self._tox_pointer,
|
result = Tox.libtoxcore.tox_group_get_chat_id(self._tox_pointer,
|
||||||
group_number,
|
group_number,
|
||||||
buff, byref(error))
|
buff, byref(error))
|
||||||
@ -2854,6 +2859,7 @@ class Tox:
|
|||||||
self.group_peer_exit_cb = None
|
self.group_peer_exit_cb = None
|
||||||
return
|
return
|
||||||
|
|
||||||
|
LOG_DEBUG(f"tox_callback_group_peer_exit")
|
||||||
c_callback = CFUNCTYPE(None, c_void_p,
|
c_callback = CFUNCTYPE(None, c_void_p,
|
||||||
c_uint32, # group_number,
|
c_uint32, # group_number,
|
||||||
c_uint32, # peer_id,
|
c_uint32, # peer_id,
|
||||||
@ -2863,8 +2869,9 @@ class Tox:
|
|||||||
c_char_p, # message
|
c_char_p, # message
|
||||||
c_size_t, # message length
|
c_size_t, # message length
|
||||||
c_void_p) # user_data
|
c_void_p) # user_data
|
||||||
try:
|
|
||||||
self.group_peer_exit_cb = c_callback(callback)
|
self.group_peer_exit_cb = c_callback(callback)
|
||||||
|
try:
|
||||||
|
LOG_DEBUG(f"tox_callback_group_peer_exit")
|
||||||
Tox.libtoxcore.tox_callback_group_peer_exit(self._tox_pointer, self.group_peer_exit_cb)
|
Tox.libtoxcore.tox_callback_group_peer_exit(self._tox_pointer, self.group_peer_exit_cb)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG_ERROR(f"tox_callback_group_peer_exit {e}") # req
|
LOG_ERROR(f"tox_callback_group_peer_exit {e}") # req
|
||||||
@ -2888,9 +2895,11 @@ class Tox:
|
|||||||
self.group_self_join_cb = None
|
self.group_self_join_cb = None
|
||||||
return
|
return
|
||||||
|
|
||||||
|
LOG_DEBUG(f"tox_callback_group_self_join")
|
||||||
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_void_p)
|
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_void_p)
|
||||||
self.group_self_join_cb = c_callback(callback)
|
self.group_self_join_cb = c_callback(callback)
|
||||||
try:
|
try:
|
||||||
|
LOG_DEBUG(f"tox_callback_group_self_join")
|
||||||
Tox.libtoxcore.tox_callback_group_self_join(self._tox_pointer, self.group_self_join_cb)
|
Tox.libtoxcore.tox_callback_group_self_join(self._tox_pointer, self.group_self_join_cb)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG_ERROR(f"tox_callback_group_self_join {e}") # req
|
LOG_ERROR(f"tox_callback_group_self_join {e}") # req
|
||||||
@ -3036,6 +3045,7 @@ class Tox:
|
|||||||
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_uint32, c_int, c_void_p)
|
c_callback = CFUNCTYPE(None, c_void_p, c_uint32, c_uint32, c_uint32, c_int, c_void_p)
|
||||||
self.group_moderation_cb = c_callback(callback)
|
self.group_moderation_cb = c_callback(callback)
|
||||||
try:
|
try:
|
||||||
|
LOG_DEBUG(f"tox_callback_group_moderation")
|
||||||
Tox.libtoxcore.tox_callback_group_moderation(self._tox_pointer, self.group_moderation_cb)
|
Tox.libtoxcore.tox_callback_group_moderation(self._tox_pointer, self.group_moderation_cb)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG_ERROR(f"tox_callback_group_moderation {e}") # req
|
LOG_ERROR(f"tox_callback_group_moderation {e}") # req
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
|
|
||||||
import logging
|
|
||||||
from ctypes import c_int, POINTER, c_void_p, byref, ArgumentError, c_uint32, CFUNCTYPE, c_size_t, c_uint8, c_uint16
|
from ctypes import c_int, POINTER, c_void_p, byref, ArgumentError, c_uint32, CFUNCTYPE, c_size_t, c_uint8, c_uint16
|
||||||
from ctypes import c_char_p, c_int32, c_bool, cast
|
from ctypes import c_char_p, c_int32, c_bool, cast
|
||||||
|
|
||||||
from wrapper.libtox import LibToxAV
|
from wrapper.libtox import LibToxAV
|
||||||
from wrapper.toxav_enums import *
|
from wrapper.toxav_enums import *
|
||||||
|
|
||||||
LOG = logging.getLogger('app.'+__name__)
|
|
||||||
def LOG_ERROR(a): print('EROR> '+a)
|
def LOG_ERROR(a): print('EROR> '+a)
|
||||||
def LOG_WARN(a): print('WARN> '+a)
|
def LOG_WARN(a): print('WARN> '+a)
|
||||||
def LOG_INFO(a): print('INFO> '+a)
|
def LOG_INFO(a): print('INFO> '+a)
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||||
|
|
||||||
from ctypes import c_size_t, create_string_buffer, byref, c_int, ArgumentError, c_char_p, c_bool
|
from ctypes import c_size_t, create_string_buffer, byref, c_int, ArgumentError, c_char_p, c_bool
|
||||||
|
|
||||||
from wrapper import libtox
|
try:
|
||||||
from wrapper.toxencryptsave_enums_and_consts import *
|
from wrapper import libtox
|
||||||
|
from wrapper.toxencryptsave_enums_and_consts import *
|
||||||
|
except:
|
||||||
|
import libtox
|
||||||
|
from toxencryptsave_enums_and_consts import *
|
||||||
|
|
||||||
class ToxEncryptSave:
|
class ToxEncryptSave:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user