Revisit helper_startup: rewrite weird imports, fix W504 and line length

This commit is contained in:
Dmitri Bogomolov 2021-07-07 21:54:16 +03:00
parent b75585f26c
commit db21f3ea6b
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -10,19 +10,15 @@ import sys
import time import time
from distutils.version import StrictVersion from distutils.version import StrictVersion
import sys try:
if sys.version_info[0] == 3:
from . import defaults
from . import helper_random
from . import paths
from . import state
from .bmconfigparser import BMConfigParser
else:
import defaults import defaults
import helper_random import helper_random
import paths import paths
import state import state
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
except ImportError:
from . import defaults, helper_random, paths, state
from .bmconfigparser import BMConfigParser
try: try:
from plugins.plugin import get_plugin from plugins.plugin import get_plugin
@ -180,9 +176,9 @@ def updateConfig():
# acts as a salt # acts as a salt
config.set( config.set(
'bitmessagesettings', 'identiconsuffix', ''.join( 'bitmessagesettings', 'identiconsuffix', ''.join(
helper_random.randomchoice("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") helper_random.randomchoice(
for x in range(12) "123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
) "abcdefghijkmnopqrstuvwxyz") for x in range(12))
) # a twelve character pseudo-password to salt the identicons ) # a twelve character pseudo-password to salt the identicons
# Add settings to support no longer resending messages after # Add settings to support no longer resending messages after
@ -249,14 +245,15 @@ def updateConfig():
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte') == 0: 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte') == 0:
config.set( config.set(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte',
str(defaults.ridiculousDifficulty * str(defaults.ridiculousDifficulty
defaults.networkDefaultProofOfWorkNonceTrialsPerByte) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
) )
if config.safeGetInt('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') == 0: if config.safeGetInt(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') == 0:
config.set( config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
str(defaults.ridiculousDifficulty * str(defaults.ridiculousDifficulty
defaults.networkDefaultPayloadLengthExtraBytes) * defaults.networkDefaultPayloadLengthExtraBytes)
) )
if not config.has_option('bitmessagesettings', 'onionhostname'): if not config.has_option('bitmessagesettings', 'onionhostname'):
@ -298,8 +295,8 @@ def adjustHalfOpenConnectionsLimit():
# connections at a time. # connections at a time.
VER_THIS = StrictVersion(platform.version()) VER_THIS = StrictVersion(platform.version())
is_limited = ( is_limited = (
StrictVersion("5.1.2600") <= VER_THIS and StrictVersion("5.1.2600") <= VER_THIS
StrictVersion("6.0.6000") >= VER_THIS and StrictVersion("6.0.6000") >= VER_THIS
) )
except ValueError: except ValueError:
pass pass