From c738d93056b0f1b04c723ab5ac3bc82a9521fc37 Mon Sep 17 00:00:00 2001
From: Peter Surda <surda@economicsofbitcoin.com>
Date: Wed, 11 Jan 2017 18:13:00 +0100
Subject: [PATCH] Assorted fixes

- landscape.io was complaining, this fixes most easily fixable errors
---
 src/bitmessageqt/__init__.py         | 12 ++----------
 src/bitmessageqt/account.py          |  8 ++++----
 src/bitmessageqt/blacklist.py        |  1 -
 src/bitmessageqt/newaddresswizard.py | 10 +++++-----
 src/class_objectHashHolder.py        |  1 -
 src/class_receiveDataThread.py       |  4 ++--
 src/class_smtpDeliver.py             |  1 +
 src/class_smtpServer.py              |  3 ++-
 src/openclpow.py                     |  4 ----
 src/proofofwork.py                   |  3 +--
 src/shared.py                        |  2 +-
 src/upnp.py                          | 15 ++++++++-------
 12 files changed, 26 insertions(+), 38 deletions(-)

diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py
index 91424c86..008647ab 100644
--- a/src/bitmessageqt/__init__.py
+++ b/src/bitmessageqt/__init__.py
@@ -19,6 +19,7 @@ try:
 except Exception as err:
     logmsg = 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download it from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\' (without quotes).'
     logger.critical(logmsg, exc_info=True)
+    import sys
     sys.exit()
 
 try:
@@ -1214,8 +1215,6 @@ class MyForm(settingsmixin.SMainWindow):
 
     # When an unread inbox row is selected on then clear the messaging menu
     def ubuntuMessagingMenuClear(self, inventoryHash):
-        global withMessagingMenu
-
         # if this isn't ubuntu then don't do anything
         if not self.isUbuntu():
             return
@@ -1315,8 +1314,6 @@ class MyForm(settingsmixin.SMainWindow):
 
     # update the Ubuntu messaging menu
     def ubuntuMessagingMenuUpdate(self, drawAttention, newItem, toLabel):
-        global withMessagingMenu
-
         # if this isn't ubuntu then don't do anything
         if not self.isUbuntu():
             return
@@ -1440,14 +1437,11 @@ class MyForm(settingsmixin.SMainWindow):
 
     # initialise the message notifier
     def notifierInit(self):
-        global withMessagingMenu
         if withMessagingMenu:
             Notify.init('pybitmessage')
 
     # shows a notification
     def notifierShow(self, title, subtitle, fromCategory, label):
-        global withMessagingMenu
-
         self.playSound(fromCategory, label)
 
         if withMessagingMenu:
@@ -1642,7 +1636,6 @@ class MyForm(settingsmixin.SMainWindow):
     connected = False
 
     def setStatusIcon(self, color):
-        global withMessagingMenu
         # print 'setting status icon color'
         if color == 'red':
             self.pushButtonStatusIcon.setIcon(
@@ -3057,7 +3050,7 @@ class MyForm(settingsmixin.SMainWindow):
             self.statusBar().showMessage(_translate(
                 "MainWindow", "Error: You cannot add the same address to your blacklist twice. Try renaming the existing one if you want."), 10000)
 
-    def deleteRowFromMessagelist(row = None, inventoryHash = None, ackData = None, messageLists = None):
+    def deleteRowFromMessagelist(self, row = None, inventoryHash = None, ackData = None, messageLists = None):
         if messageLists is None:
             messageLists = (self.ui.tableWidgetInbox, self.ui.tableWidgetInboxChans, self.ui.tableWidgetInboxSubscriptions)
         elif type(messageLists) not in (list, tuple):
@@ -4447,7 +4440,6 @@ class MySingleApplication(QApplication):
             self.server.close()
 
     def on_new_connection(self):
-        global myapp
         if myapp:
             myapp.appIndicatorShow()
 
diff --git a/src/bitmessageqt/account.py b/src/bitmessageqt/account.py
index 6e830b38..bdfeaed3 100644
--- a/src/bitmessageqt/account.py
+++ b/src/bitmessageqt/account.py
@@ -147,7 +147,7 @@ class GatewayAccount(BMAccount):
     ALL_OK = 0
     REGISTRATION_DENIED = 1
     def __init__(self, address):
-        super(BMAccount, self).__init__(address)
+        super(GatewayAccount, self).__init__(address)
         
     def send(self):
         status, addressVersionNumber, streamNumber, ripe = decodeAddress(self.toAddress)
@@ -175,7 +175,7 @@ class GatewayAccount(BMAccount):
         shared.workerQueue.put(('sendmessage', self.toAddress))
     
     def parseMessage(self, toAddress, fromAddress, subject, message):
-        super(BMAccount, self).parseMessage(toAddress, fromAddress, subject, message)
+        super(GatewayAccount, self).parseMessage(toAddress, fromAddress, subject, message)
 
 class MailchuckAccount(GatewayAccount):
     # set "gateway" in keys.dat to this
@@ -186,7 +186,7 @@ class MailchuckAccount(GatewayAccount):
     regExpIncoming = re.compile("(.*)MAILCHUCK-FROM::(\S+) \| (.*)")
     regExpOutgoing = re.compile("(\S+) (.*)")
     def __init__(self, address):
-        super(GatewayAccount, self).__init__(address)
+        super(MailchuckAccount, self).__init__(address)
         self.feedback = self.ALL_OK
         
     def createMessage(self, toAddress, fromAddress, subject, message):
@@ -262,7 +262,7 @@ class MailchuckAccount(GatewayAccount):
         self.fromAddress = self.address
 
     def parseMessage(self, toAddress, fromAddress, subject, message):
-        super(GatewayAccount, self).parseMessage(toAddress, fromAddress, subject, message)
+        super(MailchuckAccount, self).parseMessage(toAddress, fromAddress, subject, message)
         if fromAddress == self.relayAddress:
             matches = self.regExpIncoming.search(subject)
             if not matches is None:
diff --git a/src/bitmessageqt/blacklist.py b/src/bitmessageqt/blacklist.py
index 6fcb8f11..94844da5 100644
--- a/src/bitmessageqt/blacklist.py
+++ b/src/bitmessageqt/blacklist.py
@@ -2,7 +2,6 @@ from PyQt4 import QtCore, QtGui
 import shared
 from tr import _translate
 import l10n
-from uisignaler import UISignaler
 import widgets
 from addresses import addBMIfNotPresent
 from configparser import BMConfigParser
diff --git a/src/bitmessageqt/newaddresswizard.py b/src/bitmessageqt/newaddresswizard.py
index e54b18c3..2311239c 100644
--- a/src/bitmessageqt/newaddresswizard.py
+++ b/src/bitmessageqt/newaddresswizard.py
@@ -316,19 +316,19 @@ class NewAddressThread(QtCore.QThread):
     def __del__(self):
         self.wait()
         
-    def createDeterministic():
+    def createDeterministic(self):
         pass
         
-    def createPassphrase():
+    def createPassphrase(self):
         pass
     
-    def broadcastAddress():
+    def broadcastAddress(self):
         pass
     
-    def registerMailchuck():
+    def registerMailchuck(self):
         pass
     
-    def waitRegistration():
+    def waitRegistration(self):
         pass
 
     def run(self):
diff --git a/src/class_objectHashHolder.py b/src/class_objectHashHolder.py
index 24c2438d..2e456d8c 100644
--- a/src/class_objectHashHolder.py
+++ b/src/class_objectHashHolder.py
@@ -41,7 +41,6 @@ class objectHashHolder(threading.Thread):
 
     def hasHash(self, hash):
         if hash in (hashlist for hashlist in self.collectionOfHashLists):
-            logger.debug("Hash in hashHolder")
             return True
         return False
 
diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py
index cf43f7b3..3112575a 100644
--- a/src/class_receiveDataThread.py
+++ b/src/class_receiveDataThread.py
@@ -270,9 +270,9 @@ class receiveDataThread(threading.Thread):
         self.processData()
 
 
-    def sendpong(self):
+    def sendpong(self, payload):
         logger.debug('Sending pong')
-        self.sendDataThreadQueue.put((0, 'sendRawData', protocol.CreatePacket('pong')))
+        self.sendDataThreadQueue.put((0, 'sendRawData', protocol.CreatePacket('pong', payload)))
 
 
     def recverack(self):
diff --git a/src/class_smtpDeliver.py b/src/class_smtpDeliver.py
index ca51946f..18206065 100644
--- a/src/class_smtpDeliver.py
+++ b/src/class_smtpDeliver.py
@@ -8,6 +8,7 @@ import urlparse
 from configparser import BMConfigParser
 from debug import logger
 from helper_threading import *
+from bitmessageqt.uisignaler import UISignaler
 import shared
 
 SMTPDOMAIN = "bmaddr.lan"
diff --git a/src/class_smtpServer.py b/src/class_smtpServer.py
index 4043600c..65a7e1fc 100644
--- a/src/class_smtpServer.py
+++ b/src/class_smtpServer.py
@@ -6,6 +6,7 @@ from email.header import decode_header
 import re
 import signal
 import smtpd
+import socket
 import threading
 import time
 
@@ -43,7 +44,7 @@ class smtpServerChannel(smtpd.SMTPChannel):
                 self.auth = True
                 self.push('235 2.7.0 Authentication successful')
             else:
-                raise Error("Auth fail")
+                raise Exception("Auth fail")
         except:
             self.push('501 Authentication fail')
 
diff --git a/src/openclpow.py b/src/openclpow.py
index 7181c077..001333e5 100644
--- a/src/openclpow.py
+++ b/src/openclpow.py
@@ -53,16 +53,12 @@ def initCL():
         enabledGpus = []
 
 def openclAvailable():
-    global gpus
     return (len(gpus) > 0)
 
 def openclEnabled():
-    global enabledGpus
     return (len(enabledGpus) > 0)
 
 def do_opencl_pow(hash, target):
-    global ctx, queue, program, enabledGpus, hash_dt
-
     output = numpy.zeros(1, dtype=[('v', numpy.uint64, 1)])
     if (len(enabledGpus) == 0):
         return output[0][0]
diff --git a/src/proofofwork.py b/src/proofofwork.py
index ca48e28b..78188777 100644
--- a/src/proofofwork.py
+++ b/src/proofofwork.py
@@ -19,8 +19,7 @@ bitmsglib = 'bitmsghash.so'
 
 def _set_idle():
     if 'linux' in sys.platform:
-        import os
-        os.nice(20)  # @UndefinedVariable
+        os.nice(20)
     else:
         try:
             sys.getwindowsversion()
diff --git a/src/shared.py b/src/shared.py
index 11058fd7..d5438b1c 100644
--- a/src/shared.py
+++ b/src/shared.py
@@ -211,7 +211,7 @@ def reloadBroadcastSendersForWhichImWatching():
             MyECSubscriptionCryptorObjects[tag] = highlevelcrypto.makeCryptor(hexlify(privEncryptionKey))
 
 def doCleanShutdown():
-    global shutdown, thisapp
+    global shutdown
     shutdown = 1 #Used to tell proof of work worker threads and the objectProcessorThread to exit.
     try:
         parserInputQueue.put(None, False)
diff --git a/src/upnp.py b/src/upnp.py
index fd6f3852..69f89233 100644
--- a/src/upnp.py
+++ b/src/upnp.py
@@ -11,7 +11,7 @@ from helper_threading import *
 import shared
 import tr
 
-def createRequestXML(service, action, arguments=[]):
+def createRequestXML(service, action, arguments=None):
     from xml.dom.minidom import Document
 
     doc = Document()
@@ -37,11 +37,12 @@ def createRequestXML(service, action, arguments=[]):
     # iterate over arguments, create nodes, create text nodes,
     # append text nodes to nodes, and finally add the ready product
     # to argument_list
-    for k, v in arguments:
-        tmp_node = doc.createElement(k)
-        tmp_text_node = doc.createTextNode(v)
-        tmp_node.appendChild(tmp_text_node)
-        argument_list.append(tmp_node)
+    if arguments is not None:
+        for k, v in arguments:
+            tmp_node = doc.createElement(k)
+            tmp_text_node = doc.createTextNode(v)
+            tmp_node.appendChild(tmp_text_node)
+            argument_list.append(tmp_node)
 
     # append the prepared argument nodes to the function element
     for arg in argument_list:
@@ -140,7 +141,7 @@ class Router:
         dom = parseString(resp)
         return dom.getElementsByTagName('NewExternalIPAddress')[0].childNodes[0].data
     
-    def soapRequest(self, service, action, arguments=[]):
+    def soapRequest(self, service, action, arguments=None):
         from xml.dom.minidom import parseString
         from debug import logger
         conn = httplib.HTTPConnection(self.routerPath.hostname, self.routerPath.port)