async def get_torrent(request): tid = request.match_info.get('tid', None) if tid is None: return web.json_response(get_torrent_list()) else: handle = get_valid_handle(tid) # We don't want to return all of the keys as they are just an enum ignored = ['states'] + list(lt.torrent_status.states.names.keys()) status = common.struct_to_dict( handle.status(), ignore_keys=ignored, ) return web.json_response(status)
def test_struct_to_dict(): class struct(object): a = 1 b = 2 __mytest__ = 3 sha1_hash = lt.sha1_hash(binascii.unhexlify('a0'*20)) s = struct() d = common.struct_to_dict(s) assert isinstance(d, dict) assert d['a'] == 1 assert d['b'] == 2 assert '__mytest__' not in d assert len(d) == 3 assert d['sha1_hash'] == 'a0'*20
def test_struct_to_dict(): class struct(object): a = 1 b = 2 __mytest__ = 3 sha1_hash = lt.sha1_hash(binascii.unhexlify('a0' * 20)) s = struct() d = common.struct_to_dict(s) assert isinstance(d, dict) assert d['a'] == 1 assert d['b'] == 2 assert '__mytest__' not in d assert len(d) == 3 assert d['sha1_hash'] == 'a0' * 20
async def get_torrent(request): core = request.app['spritzle.core'] tid = request.match_info.get('tid', None) if tid is None: return web.json_response(get_torrent_list(core)) else: handle = get_valid_handle(core, tid) # We don't want to return all of the keys as they are just an enum ignored = (['states', 'handle', 'torrent_file'] + list(lt.torrent_status.states.names.keys())) status = common.struct_to_dict( handle.status(), ignore_keys=ignored, ) if tid in core.torrent_data: status.update(core.torrent_data[tid]) return web.json_response(status)
async def get_torrent(request): core = request.app['spritzle.core'] tid = request.match_info.get('tid', None) if tid is None: return web.json_response(get_torrent_list(core)) else: handle = get_valid_handle(core, tid) # We don't want to return all of the keys as they are just an enum ignored = (['states', 'handle', 'torrent_file'] + list(lt.torrent_status.states.names.keys())) status = common.struct_to_dict( handle.status(), ignore_keys=ignored, ) if tid in core.torrent_data: status.update(core.torrent_data[tid]) return web.json_response(status)
def get_session_cache_status(): return common.struct_to_dict(core.session.get_cache_status())
def get_settings_pe(): return common.struct_to_dict(core.session.get_pe_settings())
def get_settings_proxy(): return common.struct_to_dict(core.session.proxy())
def get_settings_session_mmu(): return common.struct_to_dict(libtorrent.min_memory_usage())
def get_settings_session_hps(): return common.struct_to_dict(libtorrent.high_performance_seed())