Skip to content

Another portion of the formatting and import fixes #1789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 23 additions & 29 deletions src/class_sqlThread.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,22 @@
import threading
import time

if sys.version_info[0] == 3:
from . import helper_sql
from . import helper_startup
from . import paths
from . import queues
from . import state
from . import tr
from .bmconfigparser import BMConfigParser
from .debug import logger
# pylint: disable=attribute-defined-outside-init,protected-access
from .addresses import encodeAddress
else:
try:
import helper_sql
import helper_startup
import paths
import queues
import state
import tr
from addresses import encodeAddress
from bmconfigparser import BMConfigParser
from debug import logger
# pylint: disable=attribute-defined-outside-init,protected-access
from addresses import encodeAddress
from tr import _translate
except ImportError:
from . import helper_sql, helper_startup, paths, queues, state
from .addresses import encodeAddress
from .bmconfigparser import BMConfigParser
from .debug import logger
from .tr import _translate


class sqlThread(threading.Thread):
Expand Down Expand Up @@ -454,10 +448,10 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
_translate(
"MainWindow",
"Disk full"),
tr._translate(
_translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
Expand All @@ -484,10 +478,10 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
_translate(
"MainWindow",
"Disk full"),
tr._translate(
_translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
Expand All @@ -510,10 +504,10 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
_translate(
"MainWindow",
"Disk full"),
tr._translate(
_translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
Expand All @@ -535,10 +529,10 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
_translate(
"MainWindow",
"Disk full"),
tr._translate(
_translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
Expand All @@ -561,10 +555,10 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
_translate(
"MainWindow",
"Disk full"),
tr._translate(
_translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
Expand All @@ -588,10 +582,10 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
_translate(
"MainWindow",
"Disk full"),
tr._translate(
_translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
Expand All @@ -609,10 +603,10 @@ def run(self): # pylint: disable=too-many-locals, too-many-branches, too-many-s
' sqlThread will now exit.')
queues.UISignalQueue.put((
'alert', (
tr._translate(
_translate(
"MainWindow",
"Disk full"),
tr._translate(
_translate(
"MainWindow",
'Alert: Your disk or data storage volume is full. Bitmessage will now exit.'),
True)))
Expand Down
21 changes: 5 additions & 16 deletions src/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,15 @@
just import and log.
"""

# import ConfigParser
import sys
if sys.version_info[0] == 3:
# python 3
import configparser as ConfigParser
else:
# python 2
import ConfigParser

import logging
import logging.config
import os
import sys

if sys.version_info[0] == 3:
from . import helper_startup
from . import state
else:
import helper_startup
import state
from six.moves import configparser

import helper_startup
import state

helper_startup.loadConfig()

Expand Down Expand Up @@ -86,7 +75,7 @@ def configureLogging():
False,
'Loaded logger configuration from %s' % logging_config
)
except (OSError, ConfigParser.NoSectionError, KeyError):
except (OSError, configparser.NoSectionError, KeyError):
if os.path.isfile(logging_config):
fail_msg = \
'Failed to load logger configuration from %s, using default' \
Expand Down
14 changes: 4 additions & 10 deletions src/helper_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,14 @@
or isn't thread-safe.
"""


# import Queue
import sys
if sys.version_info[0] == 3:
import queue as Queue #python3
else:
import Queue #python2

import threading

from six.moves import queue


sqlSubmitQueue = Queue.Queue()
sqlSubmitQueue = queue.Queue()
"""the queue for SQL"""
sqlReturnQueue = Queue.Queue()
sqlReturnQueue = queue.Queue()
"""the queue for results"""
sql_lock = threading.Lock()
""" lock to prevent queueing a new request until the previous response
Expand Down
33 changes: 15 additions & 18 deletions src/helper_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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
Expand Down
21 changes: 9 additions & 12 deletions src/multiqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
Elements are added into a random subqueue, and retrieval rotates
"""

import sys
if sys.version_info[0] == 3:
import queue as Queue
else:
import Queue

from collections import deque

if sys.version_info[0] == 3:
from . import helper_random
else:
from six.moves import queue

try:
import helper_random
except ImportError:
from . import helper_random


class MultiQueue(Queue.Queue):
class MultiQueue(queue.Queue):
"""A base queue class"""
# pylint: disable=redefined-builtin,attribute-defined-outside-init
defaultQueueCount = 10
Expand All @@ -27,7 +23,7 @@ def __init__(self, maxsize=0, count=0):
self.queueCount = MultiQueue.defaultQueueCount
else:
self.queueCount = count
Queue.Queue.__init__(self, maxsize)
queue.Queue.__init__(self, maxsize)

# Initialize the queue representation
def _init(self, maxsize):
Expand All @@ -42,7 +38,8 @@ def _qsize(self, len=len):
# Put a new item in the queue
def _put(self, item):
# self.queue.append(item)
self.queues[helper_random.randomrandrange(self.queueCount)].append((item))
self.queues[helper_random.randomrandrange(self.queueCount)].append(
(item))

# Get an item from the queue
def _get(self):
Expand Down
4 changes: 2 additions & 2 deletions src/network/connectionchooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import protocol
import state
from bmconfigparser import BMConfigParser
from queues import Queue, portCheckerQueue
from queues import queue, portCheckerQueue

logger = logging.getLogger('default')

Expand Down Expand Up @@ -37,7 +37,7 @@ def chooseConnection(stream):
retval = portCheckerQueue.get(False)
portCheckerQueue.task_done()
return retval
except Queue.Empty:
except queue.Empty:
pass
# with a probability of 0.5, connect to a discovered peer
if random.choice((False, True)) and not haveOnion:
Expand Down
28 changes: 13 additions & 15 deletions src/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

import threading
import time
try:
import queue as Queue
except ImportError:
import Queue

from six.moves import queue

try:
from multiqueue import MultiQueue
except ImportError:
from .multiqueue import MultiQueue


class ObjectProcessorQueue(Queue.Queue):
class ObjectProcessorQueue(queue.Queue):
"""Special queue class using lock for `.threads.objectProcessor`"""

maxSize = 32000000

def __init__(self):
Queue.Queue.__init__(self)
queue.Queue.__init__(self)
self.sizeLock = threading.Lock()
#: in Bytes. We maintain this to prevent nodes from flooding us
#: with objects which take up too much memory. If this gets
Expand All @@ -31,27 +29,27 @@ def put(self, item, block=True, timeout=None):
time.sleep(1)
with self.sizeLock:
self.curSize += len(item[1])
Queue.Queue.put(self, item, block, timeout)
queue.Queue.put(self, item, block, timeout)

def get(self, block=True, timeout=None):
item = Queue.Queue.get(self, block, timeout)
item = queue.Queue.get(self, block, timeout)
with self.sizeLock:
self.curSize -= len(item[1])
return item


workerQueue = Queue.Queue()
UISignalQueue = Queue.Queue()
addressGeneratorQueue = Queue.Queue()
workerQueue = queue.Queue()
UISignalQueue = queue.Queue()
addressGeneratorQueue = queue.Queue()
#: `.network.ReceiveQueueThread` instances dump objects they hear
#: on the network into this queue to be processed.
objectProcessorQueue = ObjectProcessorQueue()
invQueue = MultiQueue()
addrQueue = MultiQueue()
portCheckerQueue = Queue.Queue()
receiveDataQueue = Queue.Queue()
portCheckerQueue = queue.Queue()
receiveDataQueue = queue.Queue()
#: The address generator thread uses this queue to get information back
#: to the API thread.
apiAddressGeneratorReturnQueue = Queue.Queue()
apiAddressGeneratorReturnQueue = queue.Queue()
#: for exceptions
excQueue = Queue.Queue()
excQueue = queue.Queue()
Loading