From c9af24392d35edb488198cbbb95bea44e1e2fdb4 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 12 Aug 2020 17:29:53 -0500 Subject: [PATCH] Fix netutils formatting --- src/communicatorutils/netcheck.py | 2 +- src/utils/netutils.py | 41 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/communicatorutils/netcheck.py b/src/communicatorutils/netcheck.py index 01eca304..b4a5ddf6 100755 --- a/src/communicatorutils/netcheck.py +++ b/src/communicatorutils/netcheck.py @@ -46,7 +46,7 @@ def net_check(comm_inst): rec = True except ValueError: pass - if not rec and not netutils.checkNetwork(torPort=comm_inst.proxyPort): + if not rec and not netutils.check_network(torPort=comm_inst.proxyPort): if not kv.get('shutdown'): if not comm_inst.config.get('general.offline_mode', False): logger.warn('Network check failed, are you connected to ' + diff --git a/src/utils/netutils.py b/src/utils/netutils.py index c1a265b8..c49cd524 100755 --- a/src/utils/netutils.py +++ b/src/utils/netutils.py @@ -1,9 +1,11 @@ -''' - Onionr - P2P Microblogging Platform & Social network +"""Onionr - Private P2P Communication. - OnionrUtils offers various useful functions to Onionr networking. -''' -''' +NetUtils offers various useful functions to Onionr networking. +""" +from onionrutils import basicrequests +from .readstatic import read_static +from onionrcrypto.cryptoutils import random_shuffle +""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -16,21 +18,22 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -''' -from onionrutils import basicrequests -from . import readstatic -from onionrcrypto import cryptoutils -def checkNetwork(torPort=0): - '''Check if we are connected to the internet (through Tor)''' - retData = False - connectURLs = [] - try: - connectURLs = cryptoutils.random_shuffle(readstatic.read_static('connect-check.txt').split(',')) +""" - for url in connectURLs: - if basicrequests.do_get_request(url, port=torPort, ignoreAPI=True) != False: - retData = True + +def check_network(torPort=0) -> bool: + """Check if we are connected to the internet (through Tor).""" + success = False + connect_urls = [] + try: + connect_urls = random_shuffle( + read_static('connect-check.txt').split(',')) + + for url in connect_urls: + if basicrequests.do_get_request( + url, port=torPort, ignoreAPI=True) is not False: + success = True break except FileNotFoundError: pass - return retData \ No newline at end of file + return success