From db21f3ea6b444f6d1ece77296d2bb5c52960443d Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 7 Jul 2021 21:54:16 +0300 Subject: [PATCH] Revisit helper_startup: rewrite weird imports, fix W504 and line length --- src/helper_startup.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/helper_startup.py b/src/helper_startup.py index 332fe058..09f0265e 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -10,19 +10,15 @@ import sys import time from distutils.version import StrictVersion -import sys -if sys.version_info[0] == 3: - from . import defaults - from . import helper_random - from . import paths - from . import state - from .bmconfigparser import BMConfigParser -else: +try: import defaults import helper_random import paths import state from bmconfigparser import BMConfigParser +except ImportError: + from . import defaults, helper_random, paths, state + from .bmconfigparser import BMConfigParser try: from plugins.plugin import get_plugin @@ -180,9 +176,9 @@ def updateConfig(): # acts as a salt config.set( 'bitmessagesettings', 'identiconsuffix', ''.join( - helper_random.randomchoice("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") - for x in range(12) - ) + helper_random.randomchoice( + "123456789ABCDEFGHJKLMNPQRSTUVWXYZ" + "abcdefghijkmnopqrstuvwxyz") for x in range(12)) ) # a twelve character pseudo-password to salt the identicons # Add settings to support no longer resending messages after @@ -249,14 +245,15 @@ def updateConfig(): 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte') == 0: config.set( 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', - str(defaults.ridiculousDifficulty * - defaults.networkDefaultProofOfWorkNonceTrialsPerByte) + str(defaults.ridiculousDifficulty + * defaults.networkDefaultProofOfWorkNonceTrialsPerByte) ) - if config.safeGetInt('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') == 0: + if config.safeGetInt( + 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') == 0: config.set( 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', - str(defaults.ridiculousDifficulty * - defaults.networkDefaultPayloadLengthExtraBytes) + str(defaults.ridiculousDifficulty + * defaults.networkDefaultPayloadLengthExtraBytes) ) if not config.has_option('bitmessagesettings', 'onionhostname'): @@ -298,8 +295,8 @@ def adjustHalfOpenConnectionsLimit(): # connections at a time. VER_THIS = StrictVersion(platform.version()) is_limited = ( - StrictVersion("5.1.2600") <= VER_THIS and - StrictVersion("6.0.6000") >= VER_THIS + StrictVersion("5.1.2600") <= VER_THIS + and StrictVersion("6.0.6000") >= VER_THIS ) except ValueError: pass