wrapper and docs update.

This commit is contained in:
ingvar1995 2016-04-30 15:18:15 +03:00
parent 6a82b7d285
commit 59c72486f4
6 changed files with 45 additions and 49 deletions

View File

@ -14,11 +14,19 @@ Based on [toxygen](https://github.com/xveduk/toxygen/) toxcore wrapper
1. [Download and install latest Python 2.7](https://www.python.org/downloads/windows/) 1. [Download and install latest Python 2.7](https://www.python.org/downloads/windows/)
2. [Download file bot](https://github.com/ingvar1995/filebot/archive/master.zip) 2. [Download file bot](https://github.com/ingvar1995/filebot/archive/master.zip)
3. Unpack archive 3. Unpack archive
4. Download latest [libtox.dll](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86_shared_release.zip) build, download latest [libsodium.a](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86_static_release.zip) build, put it into libs\ 4. Download latest libtox.dll build, download latest libsodium.a build, put it into \libs\
5. Run app: 5. Run app:
``python main.py path_to_profile`` ``python main.py path_to_profile``
[libtox.dll for 32-bit Python](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86_shared_release.zip)
[libtox.dll for 64-bit Python](https://build.tox.chat/view/libtoxcore/job/libtoxcore_build_windows_x86-64_shared_release/lastSuccessfulBuild/artifact/libtoxcore_build_windows_x86-64_shared_release.zip)
[libsodium.a for 32-bit Python](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86_static_release.zip)
[libsodium.a for 64-bit Python](https://build.tox.chat/view/libsodium/job/libsodium_build_windows_x86-64_static_release/lastSuccessfulBuild/artifact/libsodium_build_windows_x86-64_static_release.zip)
### Linux ### Linux

View File

@ -2,6 +2,7 @@ import random
class Node(object): class Node(object):
def __init__(self, ip, port, tox_key, rand): def __init__(self, ip, port, tox_key, rand):
self._ip, self._port, self._tox_key, self.rand = ip, port, tox_key, rand self._ip, self._port, self._tox_key, self.rand = ip, port, tox_key, rand
@ -80,8 +81,3 @@ def node_generator():
arr = sorted(nodes, key=lambda x: x.rand)[:4] arr = sorted(nodes, key=lambda x: x.rand)[:4]
for elem in arr: for elem in arr:
yield elem.get_data() yield elem.get_data()
if __name__ == "__main__":
for elem in node_generator():
print str(elem)

5
bot.py
View File

@ -3,7 +3,7 @@ import os
from settings import * from settings import *
from toxcore_enums_and_consts import * from toxcore_enums_and_consts import *
from ctypes import * from ctypes import *
from util import log, Singleton from util import Singleton
from file_transfers import * from file_transfers import *
from collections import defaultdict from collections import defaultdict
@ -62,7 +62,7 @@ class Bot(Singleton):
:param friend_num: number of friend who sent message :param friend_num: number of friend who sent message
:param message: text of message :param message: text of message
""" """
id = self._tox.friend_get_public_key(friend_num) id = self._tox.friend_get_public_key(friend_num) # public key of user
settings = Settings.get_instance() settings = Settings.get_instance()
message = message.strip() message = message.strip()
# message parsing # message parsing
@ -277,6 +277,7 @@ class Bot(Singleton):
:param tox_id: tox id of contact :param tox_id: tox id of contact
:param message: message :param message: message
""" """
print 'Friend request:', message
self._tox.friend_add_norequest(tox_id) self._tox.friend_add_norequest(tox_id)
settings = Settings.get_instance() settings = Settings.get_instance()
# give friend default rights # give friend default rights

View File

@ -13,7 +13,7 @@ class FileBot(object):
self.stop = False self.stop = False
self.profile = None self.profile = None
self.path = path self.path = path
print 'FileBot v0.1' print 'FileBot v0.1.1'
def main(self): def main(self):
self.tox = tox_factory(ProfileHelper.open_profile(self.path)) self.tox = tox_factory(ProfileHelper.open_profile(self.path))

View File

@ -1,4 +1,3 @@
from platform import system
import json import json
import os import os
import locale import locale

68
tox.py
View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from ctypes import c_char_p, Structure, CDLL, c_bool, addressof, c_int, c_size_t, POINTER, c_uint16, c_void_p, c_uint64 from ctypes import c_char_p, Structure, CDLL, c_bool, byref, c_int, c_size_t, POINTER, c_uint16, c_void_p, c_uint64
from ctypes import create_string_buffer, ArgumentError, CFUNCTYPE, c_uint32, sizeof, c_uint8 from ctypes import create_string_buffer, ArgumentError, CFUNCTYPE, c_uint32, sizeof, c_uint8
from platform import system from platform import system
from toxcore_enums_and_consts import * from toxcore_enums_and_consts import *
@ -62,7 +62,7 @@ class Tox(object):
else: else:
tox_err_new = c_int() tox_err_new = c_int()
Tox.libtoxcore.tox_new.restype = POINTER(c_void_p) Tox.libtoxcore.tox_new.restype = POINTER(c_void_p)
self._tox_pointer = Tox.libtoxcore.tox_new(tox_options, addressof(tox_err_new)) self._tox_pointer = Tox.libtoxcore.tox_new(tox_options, byref(tox_err_new))
tox_err_new = tox_err_new.value tox_err_new = tox_err_new.value
if tox_err_new == TOX_ERR_NEW['NULL']: if tox_err_new == TOX_ERR_NEW['NULL']:
raise ArgumentError('One of the arguments to the function was NULL when it was not expected.') raise ArgumentError('One of the arguments to the function was NULL when it was not expected.')
@ -138,7 +138,7 @@ class Tox(object):
tox_err_options_new = c_int() tox_err_options_new = c_int()
f = Tox.libtoxcore.tox_options_new f = Tox.libtoxcore.tox_options_new
f.restype = POINTER(ToxOptions) f.restype = POINTER(ToxOptions)
result = f(addressof(tox_err_options_new)) result = f(byref(tox_err_options_new))
tox_err_options_new = tox_err_options_new.value tox_err_options_new = tox_err_options_new.value
if tox_err_options_new == TOX_ERR_OPTIONS_NEW['OK']: if tox_err_options_new == TOX_ERR_OPTIONS_NEW['OK']:
return result return result
@ -202,7 +202,7 @@ class Tox(object):
""" """
tox_err_bootstrap = c_int() tox_err_bootstrap = c_int()
result = Tox.libtoxcore.tox_bootstrap(self._tox_pointer, c_char_p(address), c_uint16(port), result = Tox.libtoxcore.tox_bootstrap(self._tox_pointer, c_char_p(address), c_uint16(port),
string_to_bin(public_key), addressof(tox_err_bootstrap)) string_to_bin(public_key), byref(tox_err_bootstrap))
tox_err_bootstrap = tox_err_bootstrap.value tox_err_bootstrap = tox_err_bootstrap.value
if tox_err_bootstrap == TOX_ERR_BOOTSTRAP['OK']: if tox_err_bootstrap == TOX_ERR_BOOTSTRAP['OK']:
return bool(result) return bool(result)
@ -228,7 +228,7 @@ class Tox(object):
""" """
tox_err_bootstrap = c_int() tox_err_bootstrap = c_int()
result = Tox.libtoxcore.tox_add_tcp_relay(self._tox_pointer, c_char_p(address), c_uint16(port), result = Tox.libtoxcore.tox_add_tcp_relay(self._tox_pointer, c_char_p(address), c_uint16(port),
c_char_p(public_key), addressof(tox_err_bootstrap)) c_char_p(public_key), byref(tox_err_bootstrap))
tox_err_bootstrap = tox_err_bootstrap.value tox_err_bootstrap = tox_err_bootstrap.value
if tox_err_bootstrap == TOX_ERR_BOOTSTRAP['OK']: if tox_err_bootstrap == TOX_ERR_BOOTSTRAP['OK']:
return bool(result) return bool(result)
@ -355,7 +355,7 @@ class Tox(object):
""" """
tox_err_set_info = c_int() tox_err_set_info = c_int()
result = Tox.libtoxcore.tox_self_set_name(self._tox_pointer, c_char_p(name), result = Tox.libtoxcore.tox_self_set_name(self._tox_pointer, c_char_p(name),
c_size_t(len(name)), addressof(tox_err_set_info)) c_size_t(len(name)), byref(tox_err_set_info))
tox_err_set_info = tox_err_set_info.value tox_err_set_info = tox_err_set_info.value
if tox_err_set_info == TOX_ERR_SET_INFO['OK']: if tox_err_set_info == TOX_ERR_SET_INFO['OK']:
return bool(result) return bool(result)
@ -403,7 +403,7 @@ class Tox(object):
""" """
tox_err_set_info = c_int() tox_err_set_info = c_int()
result = Tox.libtoxcore.tox_self_set_status_message(self._tox_pointer, c_char_p(status_message), result = Tox.libtoxcore.tox_self_set_status_message(self._tox_pointer, c_char_p(status_message),
c_size_t(len(status_message)), addressof(tox_err_set_info)) c_size_t(len(status_message)), byref(tox_err_set_info))
tox_err_set_info = tox_err_set_info.value tox_err_set_info = tox_err_set_info.value
if tox_err_set_info == TOX_ERR_SET_INFO['OK']: if tox_err_set_info == TOX_ERR_SET_INFO['OK']:
return bool(result) return bool(result)
@ -479,7 +479,7 @@ class Tox(object):
""" """
tox_err_friend_add = c_int() tox_err_friend_add = c_int()
result = Tox.libtoxcore.tox_friend_add(self._tox_pointer, string_to_bin(address), c_char_p(message), result = Tox.libtoxcore.tox_friend_add(self._tox_pointer, string_to_bin(address), c_char_p(message),
c_size_t(len(message)), addressof(tox_err_friend_add)) c_size_t(len(message)), byref(tox_err_friend_add))
tox_err_friend_add = tox_err_friend_add.value tox_err_friend_add = tox_err_friend_add.value
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']: if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']:
return result return result
@ -519,7 +519,7 @@ class Tox(object):
""" """
tox_err_friend_add = c_int() tox_err_friend_add = c_int()
result = Tox.libtoxcore.tox_friend_add_norequest(self._tox_pointer, string_to_bin(public_key), result = Tox.libtoxcore.tox_friend_add_norequest(self._tox_pointer, string_to_bin(public_key),
addressof(tox_err_friend_add)) byref(tox_err_friend_add))
tox_err_friend_add = tox_err_friend_add.value tox_err_friend_add = tox_err_friend_add.value
if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']: if tox_err_friend_add == TOX_ERR_FRIEND_ADD['OK']:
return result return result
@ -554,7 +554,7 @@ class Tox(object):
""" """
tox_err_friend_delete = c_int() tox_err_friend_delete = c_int()
result = Tox.libtoxcore.tox_friend_delete(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_delete(self._tox_pointer, c_uint32(friend_number),
addressof(tox_err_friend_delete)) byref(tox_err_friend_delete))
tox_err_friend_delete = tox_err_friend_delete.value tox_err_friend_delete = tox_err_friend_delete.value
if tox_err_friend_delete == TOX_ERR_FRIEND_DELETE['OK']: if tox_err_friend_delete == TOX_ERR_FRIEND_DELETE['OK']:
return bool(result) return bool(result)
@ -574,7 +574,7 @@ class Tox(object):
""" """
tox_err_friend_by_public_key = c_int() tox_err_friend_by_public_key = c_int()
result = Tox.libtoxcore.tox_friend_by_public_key(self._tox_pointer, string_to_bin(public_key), result = Tox.libtoxcore.tox_friend_by_public_key(self._tox_pointer, string_to_bin(public_key),
addressof(tox_err_friend_by_public_key)) byref(tox_err_friend_by_public_key))
tox_err_friend_by_public_key = tox_err_friend_by_public_key.value tox_err_friend_by_public_key = tox_err_friend_by_public_key.value
if tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['OK']: if tox_err_friend_by_public_key == TOX_ERR_FRIEND_BY_PUBLIC_KEY['OK']:
return result return result
@ -629,7 +629,7 @@ class Tox(object):
public_key = create_string_buffer(TOX_PUBLIC_KEY_SIZE) public_key = create_string_buffer(TOX_PUBLIC_KEY_SIZE)
tox_err_friend_get_public_key = c_int() tox_err_friend_get_public_key = c_int()
Tox.libtoxcore.tox_friend_get_public_key(self._tox_pointer, c_uint32(friend_number), public_key, Tox.libtoxcore.tox_friend_get_public_key(self._tox_pointer, c_uint32(friend_number), public_key,
addressof(tox_err_friend_get_public_key)) byref(tox_err_friend_get_public_key))
tox_err_friend_get_public_key = tox_err_friend_get_public_key.value tox_err_friend_get_public_key = tox_err_friend_get_public_key.value
if tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['OK']: if tox_err_friend_get_public_key == TOX_ERR_FRIEND_GET_PUBLIC_KEY['OK']:
return bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE) return bin_to_string(public_key, TOX_PUBLIC_KEY_SIZE)
@ -646,7 +646,7 @@ class Tox(object):
""" """
tox_err_last_online = c_int() tox_err_last_online = c_int()
result = Tox.libtoxcore.tox_friend_get_last_online(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_get_last_online(self._tox_pointer, c_uint32(friend_number),
addressof(tox_err_last_online)) byref(tox_err_last_online))
tox_err_last_online = tox_err_last_online.value tox_err_last_online = tox_err_last_online.value
if tox_err_last_online == TOX_ERR_FRIEND_GET_LAST_ONLINE['OK']: if tox_err_last_online == TOX_ERR_FRIEND_GET_LAST_ONLINE['OK']:
return result return result
@ -665,7 +665,7 @@ class Tox(object):
""" """
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_name_size(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_get_name_size(self._tox_pointer, c_uint32(friend_number),
addressof(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result return result
@ -691,7 +691,7 @@ class Tox(object):
name = create_string_buffer(self.friend_get_name_size(friend_number)) name = create_string_buffer(self.friend_get_name_size(friend_number))
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
Tox.libtoxcore.tox_friend_get_name(self._tox_pointer, c_uint32(friend_number), name, Tox.libtoxcore.tox_friend_get_name(self._tox_pointer, c_uint32(friend_number), name,
addressof(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return name.value.decode('utf8') return name.value.decode('utf8')
@ -727,7 +727,7 @@ class Tox(object):
""" """
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_status_message_size(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_get_status_message_size(self._tox_pointer, c_uint32(friend_number),
addressof(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result return result
@ -755,7 +755,7 @@ class Tox(object):
status_message = create_string_buffer(self.friend_get_status_message_size(friend_number)) status_message = create_string_buffer(self.friend_get_status_message_size(friend_number))
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
Tox.libtoxcore.tox_friend_get_status_message(self._tox_pointer, c_uint32(friend_number), status_message, Tox.libtoxcore.tox_friend_get_status_message(self._tox_pointer, c_uint32(friend_number), status_message,
addressof(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return status_message.value.decode('utf8') return status_message.value.decode('utf8')
@ -796,7 +796,7 @@ class Tox(object):
""" """
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_status(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_get_status(self._tox_pointer, c_uint32(friend_number),
addressof(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result return result
@ -835,7 +835,7 @@ class Tox(object):
""" """
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_connection_status(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_get_connection_status(self._tox_pointer, c_uint32(friend_number),
addressof(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return result return result
@ -875,7 +875,7 @@ class Tox(object):
""" """
tox_err_friend_query = c_int() tox_err_friend_query = c_int()
result = Tox.libtoxcore.tox_friend_get_typing(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_friend_get_typing(self._tox_pointer, c_uint32(friend_number),
addressof(tox_err_friend_query)) byref(tox_err_friend_query))
tox_err_friend_query = tox_err_friend_query.value tox_err_friend_query = tox_err_friend_query.value
if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']: if tox_err_friend_query == TOX_ERR_FRIEND_QUERY['OK']:
return bool(result) return bool(result)
@ -918,7 +918,7 @@ class Tox(object):
""" """
tox_err_set_typing = c_int() tox_err_set_typing = c_int()
result = Tox.libtoxcore.tox_self_set_typing(self._tox_pointer, c_uint32(friend_number), result = Tox.libtoxcore.tox_self_set_typing(self._tox_pointer, c_uint32(friend_number),
c_bool(typing), addressof(tox_err_set_typing)) c_bool(typing), byref(tox_err_set_typing))
tox_err_set_typing = tox_err_set_typing.value tox_err_set_typing = tox_err_set_typing.value
if tox_err_set_typing == TOX_ERR_SET_TYPING['OK']: if tox_err_set_typing == TOX_ERR_SET_TYPING['OK']:
return bool(result) return bool(result)
@ -948,7 +948,7 @@ class Tox(object):
tox_err_friend_send_message = c_int() tox_err_friend_send_message = c_int()
result = Tox.libtoxcore.tox_friend_send_message(self._tox_pointer, c_uint32(friend_number), 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)), c_int(message_type), c_char_p(message), c_size_t(len(message)),
addressof(tox_err_friend_send_message)) byref(tox_err_friend_send_message))
tox_err_friend_send_message = tox_err_friend_send_message.value tox_err_friend_send_message = tox_err_friend_send_message.value
if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['OK']: if tox_err_friend_send_message == TOX_ERR_FRIEND_SEND_MESSAGE['OK']:
return result return result
@ -1058,7 +1058,7 @@ class Tox(object):
""" """
tox_err_file_control = c_int() tox_err_file_control = c_int()
result = Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), result = Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number),
c_int(control), addressof(tox_err_file_control)) c_int(control), byref(tox_err_file_control))
tox_err_file_control = tox_err_file_control.value tox_err_file_control = tox_err_file_control.value
if tox_err_file_control == TOX_ERR_FILE_CONTROL['OK']: if tox_err_file_control == TOX_ERR_FILE_CONTROL['OK']:
return bool(result) return bool(result)
@ -1113,7 +1113,7 @@ class Tox(object):
""" """
tox_err_file_seek = c_int() tox_err_file_seek = c_int()
result = Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), result = Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number),
c_uint64(position), addressof(tox_err_file_seek)) c_uint64(position), byref(tox_err_file_seek))
tox_err_file_seek = tox_err_file_seek.value tox_err_file_seek = tox_err_file_seek.value
if tox_err_file_seek == TOX_ERR_FILE_SEEK['OK']: if tox_err_file_seek == TOX_ERR_FILE_SEEK['OK']:
return bool(result) return bool(result)
@ -1143,8 +1143,8 @@ class Tox(object):
if file_id is None: if file_id is None:
file_id = create_string_buffer(TOX_FILE_ID_LENGTH) file_id = create_string_buffer(TOX_FILE_ID_LENGTH)
tox_err_file_get = c_int() tox_err_file_get = c_int()
Tox.libtoxcore.tox_file_control(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), file_id, Tox.libtoxcore.tox_get_file_id(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), file_id,
addressof(tox_err_file_get)) byref(tox_err_file_get))
tox_err_file_get = tox_err_file_get.value tox_err_file_get = tox_err_file_get.value
if tox_err_file_get == TOX_ERR_FILE_GET['OK']: if tox_err_file_get == TOX_ERR_FILE_GET['OK']:
return bin_to_string(file_id, TOX_FILE_ID_LENGTH) return bin_to_string(file_id, TOX_FILE_ID_LENGTH)
@ -1207,7 +1207,7 @@ class Tox(object):
tox_err_file_send = c_int() tox_err_file_send = c_int()
result = self.libtoxcore.tox_file_send(self._tox_pointer, c_uint32(friend_number), c_uint32(kind), result = self.libtoxcore.tox_file_send(self._tox_pointer, c_uint32(friend_number), c_uint32(kind),
c_uint64(file_size), string_to_bin(file_id), c_char_p(filename), c_uint64(file_size), string_to_bin(file_id), c_char_p(filename),
c_size_t(len(filename)), addressof(tox_err_file_send)) c_size_t(len(filename)), byref(tox_err_file_send))
tox_err_file_send = tox_err_file_send.value tox_err_file_send = tox_err_file_send.value
if tox_err_file_send == TOX_ERR_FILE_SEND['OK']: if tox_err_file_send == TOX_ERR_FILE_SEND['OK']:
return result return result
@ -1242,7 +1242,7 @@ class Tox(object):
tox_err_file_send_chunk = c_int() tox_err_file_send_chunk = c_int()
result = self.libtoxcore.tox_file_send_chunk(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number), result = self.libtoxcore.tox_file_send_chunk(self._tox_pointer, c_uint32(friend_number), c_uint32(file_number),
c_uint64(position), c_char_p(data), c_size_t(len(data)), c_uint64(position), c_char_p(data), c_size_t(len(data)),
addressof(tox_err_file_send_chunk)) byref(tox_err_file_send_chunk))
tox_err_file_send_chunk = tox_err_file_send_chunk.value tox_err_file_send_chunk = tox_err_file_send_chunk.value
if tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['OK']: if tox_err_file_send_chunk == TOX_ERR_FILE_SEND_CHUNK['OK']:
return bool(result) return bool(result)
@ -1383,7 +1383,7 @@ class Tox(object):
Return the UDP port this Tox instance is bound to. Return the UDP port this Tox instance is bound to.
""" """
tox_err_get_port = c_int() tox_err_get_port = c_int()
result = Tox.libtoxcore.tox_self_get_udp_port(self._tox_pointer, addressof(tox_err_get_port)) result = Tox.libtoxcore.tox_self_get_udp_port(self._tox_pointer, byref(tox_err_get_port))
tox_err_get_port = tox_err_get_port.value tox_err_get_port = tox_err_get_port.value
if tox_err_get_port == TOX_ERR_GET_PORT['OK']: if tox_err_get_port == TOX_ERR_GET_PORT['OK']:
return result return result
@ -1396,17 +1396,9 @@ class Tox(object):
relay. relay.
""" """
tox_err_get_port = c_int() tox_err_get_port = c_int()
result = Tox.libtoxcore.tox_self_get_tcp_port(self._tox_pointer, addressof(tox_err_get_port)) result = Tox.libtoxcore.tox_self_get_tcp_port(self._tox_pointer, byref(tox_err_get_port))
tox_err_get_port = tox_err_get_port.value tox_err_get_port = tox_err_get_port.value
if tox_err_get_port == TOX_ERR_GET_PORT['OK']: if tox_err_get_port == TOX_ERR_GET_PORT['OK']:
return result return result
elif tox_err_get_port == TOX_ERR_GET_PORT['NOT_BOUND']: elif tox_err_get_port == TOX_ERR_GET_PORT['NOT_BOUND']:
raise RuntimeError('The instance was not bound to any port.') raise RuntimeError('The instance was not bound to any port.')
if __name__ == '__main__':
tox = Tox(Tox.options_new())
p = tox.get_savedata()
print type(p)
print p
del tox