From 6754b2bbbfa560e7e6c7459341e5f1b9b7ff0c23 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 20 Feb 2016 19:53:42 +0300 Subject: [PATCH] added generation exception while creating tox_options instance --- src/main.py | 4 ++-- src/tox.py | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main.py b/src/main.py index a7c6fd1..171b2be 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ from mainscreen import MainWindow from profile import Profile import sys from PySide import QtCore, QtGui -from tox import Tox +from tox import Tox, tox_factory from bootstrap import node_generator @@ -76,7 +76,7 @@ def main(): data = Profile.open_profile(path, name) ms = MainWindow() # creating tox instance - tox = Tox(data, settings) + tox = tox_factory(data, settings) # bootstrap for data in node_generator(): tox.bootstrap(*data) diff --git a/src/tox.py b/src/tox.py index 4e36578..ca1c176 100644 --- a/src/tox.py +++ b/src/tox.py @@ -34,7 +34,7 @@ class LibToxCore(object): def __getattr__(self, item): return self._libtoxcore.__getattr__(item) - + class Tox(object): libtoxcore = LibToxCore() @@ -108,7 +108,7 @@ class Tox(object): Objects returned from this function must be freed using the tox_options_free function. - :return: A pointer to new ToxOptions object with default options or NULL on failure. + :return: A pointer to new ToxOptions object with default options or raise MemoryError. """ tox_err_options_new = c_int() Tox.libtoxcore.tox_options_new.restype = POINTER(ToxOptions) @@ -1003,6 +1003,21 @@ class Tox(object): Tox.libtoxcore.tox_kill(self._tox_pointer) +def tox_factory(data, settings): + tox_options = Tox.options_new() + tox_options.contents.udp_enabled = settings['udp_enabled'] + tox_options.contents.proxy_type = settings['proxy_type'] + tox_options.contents.proxy_host = settings['proxy_host'] + tox_options.contents.proxy_port = settings['proxy_port'] + tox_options.contents.start_port = settings['start_port'] + tox_options.contents.end_port = settings['end_port'] + tox_options.contents.tcp_port = settings['tcp_port'] + tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['TOX_SAVEDATA_TYPE_TOX_SAVE'] + tox_options.contents.savedata_data = c_char_p(data) + tox_options.contents.savedata_length = len(data) + return Tox(tox_options) + + if __name__ == '__main__': options = Tox.options_new()