Skip to content

Commit

Permalink
Changes based on style and lint checks. (final_code_quality_17)
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeedogs committed Nov 26, 2018
1 parent 881e523 commit 6d98a4e
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 120 deletions.
20 changes: 13 additions & 7 deletions dev/bloomfiltertest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from math import ceil
from os import stat, getenv, path
from pybloom import BloomFilter as BloomFilter1
from pybloomfilter import BloomFilter as BloomFilter2
"""
dev/bloomfiltertest.py
======================
"""

import sqlite3
from os import getenv, path
from time import time

from pybloom import BloomFilter as BloomFilter1 # pylint: disable=import-error
from pybloomfilter import BloomFilter as BloomFilter2 # pylint: disable=import-error

# Ubuntu: apt-get install python-pybloomfiltermmap

conn = sqlite3.connect(path.join(getenv("HOME"), '.config/PyBitmessage/messages.dat'))
Expand Down Expand Up @@ -41,9 +47,9 @@
except IndexError:
pass

#f = open("/home/shurdeek/tmp/bloom.dat", "wb")
#sb1.tofile(f)
#f.close()
# f = open("/home/shurdeek/tmp/bloom.dat", "wb")
# sb1.tofile(f)
# f.close()


print "Item count: %i" % (itemcount)
Expand Down
34 changes: 21 additions & 13 deletions src/bitmessageqt/dialogs.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from PyQt4 import QtGui
from tr import _translate
from retranslateui import RetranslateMixin
import widgets
"""
src/bitmessageqt/dialogs.py
===========================
"""

from newchandialog import NewChanDialog
from address_dialogs import (
AddAddressDialog, NewAddressDialog, NewSubscriptionDialog,
RegenerateAddressesDialog, SpecialAddressBehaviorDialog, EmailGatewayDialog
)
from PyQt4 import QtGui

import paths
from version import softwareVersion

import paths
import widgets
from address_dialogs import (
AddAddressDialog, EmailGatewayDialog, NewAddressDialog, NewSubscriptionDialog, RegenerateAddressesDialog,
SpecialAddressBehaviorDialog
)
from newchandialog import NewChanDialog
from retranslateui import RetranslateMixin
from tr import _translate

__all__ = [
"NewChanDialog", "AddAddressDialog", "NewAddressDialog",
Expand All @@ -21,6 +25,7 @@


class AboutDialog(QtGui.QDialog, RetranslateMixin):
"""The `About` dialog"""
def __init__(self, parent=None):
super(AboutDialog, self).__init__(parent)
widgets.load('about.ui', self)
Expand All @@ -32,7 +37,7 @@ def __init__(self, parent=None):
self.labelVersion.setText(
self.labelVersion.text().replace(
':version:', version
).replace(':branch:', commit or 'v%s' % version)
).replace(':branch:', commit or 'v%s' % version)
)
self.labelVersion.setOpenExternalLinks(True)

Expand All @@ -48,28 +53,31 @@ def __init__(self, parent=None):


class IconGlossaryDialog(QtGui.QDialog, RetranslateMixin):
"""The `Icon Glossary` dialog, explaining the status icon colors"""
def __init__(self, parent=None, config=None):
super(IconGlossaryDialog, self).__init__(parent)
widgets.load('iconglossary.ui', self)

# FIXME: check the window title visibility here
# .. todo:: FIXME: check the window title visibility here
self.groupBox.setTitle('')

self.labelPortNumber.setText(_translate(
"iconGlossaryDialog",
"You are using TCP port %1. (This can be changed in the settings)."
).arg(config.getint('bitmessagesettings', 'port')))
).arg(config.getint('bitmessagesettings', 'port')))
self.setFixedSize(QtGui.QWidget.sizeHint(self))


class HelpDialog(QtGui.QDialog, RetranslateMixin):
"""The `Help` dialog"""
def __init__(self, parent=None):
super(HelpDialog, self).__init__(parent)
widgets.load('help.ui', self)
self.setFixedSize(QtGui.QWidget.sizeHint(self))


class ConnectDialog(QtGui.QDialog, RetranslateMixin):
"""The `Connect` dialog"""
def __init__(self, parent=None):
super(ConnectDialog, self).__init__(parent)
widgets.load('connect.ui', self)
Expand Down
52 changes: 42 additions & 10 deletions src/bitmessageqt/newchandialog.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,72 @@
"""
src/bitmessageqt/newchandialog.py
=================================
"""

from PyQt4 import QtCore, QtGui

import widgets
from addresses import addBMIfNotPresent
from addressvalidator import AddressValidator, PassPhraseValidator
from queues import apiAddressGeneratorReturnQueue, addressGeneratorQueue, UISignalQueue
from queues import UISignalQueue, addressGeneratorQueue, apiAddressGeneratorReturnQueue
from retranslateui import RetranslateMixin
from tr import _translate
from utils import str_chan
import widgets


class NewChanDialog(QtGui.QDialog, RetranslateMixin):
"""The `New Chan` dialog"""
def __init__(self, parent=None):
super(NewChanDialog, self).__init__(parent)
widgets.load('newchandialog.ui', self)
self.parent = parent
self.chanAddress.setValidator(AddressValidator(self.chanAddress, self.chanPassPhrase, self.validatorFeedback, self.buttonBox, False))
self.chanPassPhrase.setValidator(PassPhraseValidator(self.chanPassPhrase, self.chanAddress, self.validatorFeedback, self.buttonBox, False))
self.chanAddress.setValidator(
AddressValidator(
self.chanAddress,
self.chanPassPhrase,
self.validatorFeedback,
self.buttonBox,
False))
self.chanPassPhrase.setValidator(
PassPhraseValidator(
self.chanPassPhrase,
self.chanAddress,
self.validatorFeedback,
self.buttonBox,
False))

self.timer = QtCore.QTimer()
QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"), self.delayedUpdateStatus)
self.timer.start(500) # milliseconds
QtCore.QObject.connect( # pylint: disable=no-member
self.timer, QtCore.SIGNAL("timeout()"), self.delayedUpdateStatus)
self.timer.start(500) # milliseconds
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.show()

def delayedUpdateStatus(self):
"""Related to updating the UI for the chan passphrase validity"""
self.chanPassPhrase.validator().checkQueue()

def accept(self):
"""Proceed in joining the chan"""
self.timer.stop()
self.hide()
apiAddressGeneratorReturnQueue.queue.clear()
if self.chanAddress.text().toUtf8() == "":
addressGeneratorQueue.put(('createChan', 4, 1, str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()), self.chanPassPhrase.text().toUtf8(), True))
addressGeneratorQueue.put(
('createChan', 4, 1, str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()),
self.chanPassPhrase.text().toUtf8(),
True))
else:
addressGeneratorQueue.put(('joinChan', addBMIfNotPresent(self.chanAddress.text().toUtf8()), str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()), self.chanPassPhrase.text().toUtf8(), True))
addressGeneratorQueue.put(
('joinChan', addBMIfNotPresent(self.chanAddress.text().toUtf8()),
str_chan + ' ' + str(self.chanPassPhrase.text().toUtf8()),
self.chanPassPhrase.text().toUtf8(),
True))
addressGeneratorReturnValue = apiAddressGeneratorReturnQueue.get(True)
if len(addressGeneratorReturnValue) > 0 and addressGeneratorReturnValue[0] != 'chan name does not match address':
UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Successfully created / joined chan %1").arg(unicode(self.chanPassPhrase.text()))))
if addressGeneratorReturnValue and addressGeneratorReturnValue[0] != 'chan name does not match address':
UISignalQueue.put(('updateStatusBar', _translate(
"newchandialog", "Successfully created / joined chan %1").arg(unicode(self.chanPassPhrase.text()))))
self.parent.ui.tabWidget.setCurrentIndex(
self.parent.ui.tabWidget.indexOf(self.parent.ui.chans)
)
Expand All @@ -45,6 +76,7 @@ def accept(self):
self.done(QtGui.QDialog.Rejected)

def reject(self):
"""Cancel joining the chan"""
self.timer.stop()
self.hide()
UISignalQueue.put(('updateStatusBar', _translate("newchandialog", "Chan creation / joining cancelled")))
Expand Down
73 changes: 25 additions & 48 deletions src/helper_startup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
"""Helper Start performs all the startup operations."""
"""
src/helper_startup.py
=====================
Helper Start performs all the startup operations.
"""
# pylint: disable=too-many-branches,too-many-statements
from __future__ import print_function

import ConfigParser
from bmconfigparser import BMConfigParser
import defaults
import sys
import os
import platform
import sys
from distutils.version import StrictVersion

import defaults
import helper_random
import paths
import state
import helper_random
from bmconfigparser import BMConfigParser

# The user may de-select Portable Mode in the settings if they want
# the config files to stay in the application data folder.
Expand All @@ -30,6 +37,7 @@ def _loadTrustedPeer():


def loadConfig():
"""Load the config"""
config = BMConfigParser()
if state.appdata:
config.read(state.appdata + 'keys.dat')
Expand All @@ -44,7 +52,7 @@ def loadConfig():
config.read(paths.lookupExeFolder() + 'keys.dat')
try:
config.get('bitmessagesettings', 'settingsversion')
print 'Loading config files from same directory as program.'
print('Loading config files from same directory as program.')
needToCreateKeysFile = False
state.appdata = paths.lookupExeFolder()
except:
Expand All @@ -55,7 +63,7 @@ def loadConfig():
needToCreateKeysFile = config.safeGet(
'bitmessagesettings', 'settingsversion') is None
if not needToCreateKeysFile:
print 'Loading existing config files from', state.appdata
print('Loading existing config files from', state.appdata)

if needToCreateKeysFile:

Expand All @@ -80,7 +88,6 @@ def loadConfig():
config.set('bitmessagesettings', 'sockshostname', 'localhost')
config.set('bitmessagesettings', 'socksport', '9050')
config.set('bitmessagesettings', 'socksauthentication', 'false')
# config.set('bitmessagesettings', 'sockslisten', 'false')
config.set('bitmessagesettings', 'socksusername', '')
config.set('bitmessagesettings', 'sockspassword', '')
config.set('bitmessagesettings', 'keysencrypted', 'false')
Expand All @@ -92,30 +99,14 @@ def loadConfig():
'bitmessagesettings', 'defaultpayloadlengthextrabytes',
str(defaults.networkDefaultPayloadLengthExtraBytes))
config.set('bitmessagesettings', 'minimizeonclose', 'false')
# config.set(
# 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', '0')
# config.set(
# 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
# '0')
config.set('bitmessagesettings', 'dontconnect', 'true')
# config.set('bitmessagesettings', 'userlocale', 'system')
# config.set('bitmessagesettings', 'useidenticons', 'True')
# config.set(
# 'bitmessagesettings', 'identiconsuffix',
# ''.join(helper_random.randomchoice(
# "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
# ) for x in range(12)
# )) # a twelve character pseudo-password to salt the identicons
config.set('bitmessagesettings', 'replybelow', 'False')
config.set('bitmessagesettings', 'maxdownloadrate', '0')
config.set('bitmessagesettings', 'maxuploadrate', '0')
# config.set('bitmessagesettings', 'maxoutboundconnections', '8')
# config.set('bitmessagesettings', 'ttl', '367200')

# UI setting to stop trying to send messages after X days/months
config.set('bitmessagesettings', 'stopresendingafterxdays', '')
config.set('bitmessagesettings', 'stopresendingafterxmonths', '')
# config.set('bitmessagesettings', 'timeperiod', '-1')

# Are you hoping to add a new option to the keys.dat file? You're in
# the right place for adding it to users who install the software for
Expand All @@ -127,9 +118,9 @@ def loadConfig():
# Just use the same directory as the program and forget about
# the appdata folder
state.appdata = ''
print 'Creating new config files in same directory as program.'
print('Creating new config files in same directory as program.')
else:
print 'Creating new config files in', state.appdata
print('Creating new config files in', state.appdata)
if not os.path.exists(state.appdata):
os.makedirs(state.appdata)
if not sys.platform.startswith('win'):
Expand All @@ -142,6 +133,7 @@ def loadConfig():


def updateConfig():
"""Save the config"""
config = BMConfigParser()
settingsversion = config.getint('bitmessagesettings', 'settingsversion')
if settingsversion == 1:
Expand Down Expand Up @@ -172,20 +164,6 @@ def updateConfig():
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0')
settingsversion = 7

# Raise the default required difficulty from 1 to 2
# With the change to protocol v3, this is obsolete.
# if settingsversion == 6:
# if int(shared.config.get(
# 'bitmessagesettings', 'defaultnoncetrialsperbyte'
# )) == defaults.networkDefaultProofOfWorkNonceTrialsPerByte:
# shared.config.set(
# 'bitmessagesettings', 'defaultnoncetrialsperbyte',
# str(
# defaults.networkDefaultProofOfWorkNonceTrialsPerByte
# * 2)
# )
# settingsversion = 7

if not config.has_option('bitmessagesettings', 'sockslisten'):
config.set('bitmessagesettings', 'sockslisten', 'false')

Expand All @@ -200,11 +178,11 @@ def updateConfig():
if not config.has_option('bitmessagesettings', 'identiconsuffix'):
# acts as a salt
config.set(
'bitmessagesettings', 'identiconsuffix',
''.join(helper_random.randomchoice(
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
) for x in range(12)
)) # a twelve character pseudo-password to salt the identicons
'bitmessagesettings', 'identiconsuffix', ''.join(
helper_random.randomchoice("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
for x in range(12)
)
) # a twelve character pseudo-password to salt the identicons

# Add settings to support no longer resending messages after
# a certain period of time even if we never get an ack
Expand Down Expand Up @@ -273,9 +251,7 @@ def updateConfig():
str(defaults.ridiculousDifficulty *
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
)
if config.safeGetInt(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes'
) == 0:
if config.safeGetInt('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes') == 0:
config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
str(defaults.ridiculousDifficulty *
Expand Down Expand Up @@ -308,6 +284,7 @@ def updateConfig():


def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
"""Check for (mainly XP and Vista) limitations"""
try:
if sys.platform[0:3] == "win":
VER_THIS = StrictVersion(platform.version())
Expand Down
Loading

0 comments on commit 6d98a4e

Please sign in to comment.