From 2cc4435cfc6e139b441fc162830df9499c5b266a Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Wed, 8 Feb 2017 14:19:02 +0100 Subject: [PATCH] Imports, typos, syntax errors - remove obsolete imports - add missing imports - fix typos - fix syntax errors - thanks to landscape.io for report --- src/addresses.py | 2 +- src/api.py | 2 +- src/bitmessagecli.py | 5 ----- src/bitmessagecurses/__init__.py | 12 ++++-------- src/bitmessageqt/safehtmlparser.py | 2 +- src/configparser.py | 2 +- src/helper_bootstrap.py | 1 - src/messagetypes/message.py | 2 +- src/messagetypes/vote.py | 2 +- src/network/advanceddispatcher.py | 8 +++++--- src/openclpow.py | 2 +- src/proofofwork.py | 4 ---- src/protocol.py | 1 + src/shared.py | 4 ---- src/state.py | 1 - 15 files changed, 17 insertions(+), 33 deletions(-) diff --git a/src/addresses.py b/src/addresses.py index fa87677a..c8caaf82 100644 --- a/src/addresses.py +++ b/src/addresses.py @@ -3,7 +3,7 @@ from struct import * from pyelliptic import arithmetic from binascii import hexlify, unhexlify - +#from debug import logger #There is another copy of this function in Bitmessagemain.py def convertIntToString(n): diff --git a/src/api.py b/src/api.py index 101241ec..4de01092 100644 --- a/src/api.py +++ b/src/api.py @@ -907,7 +907,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): with shared.printLock: print 'broadcasting inv within API command disseminatePubkey with hash:', hexlify(inventoryHash) protocol.broadcastToSendDataQueues(( - streamNumber, 'advertiseobject', inventoryHash)) + pubkeyStreamNumber, 'advertiseobject', inventoryHash)) def HandleGetMessageDataByDestinationHash(self, params): # Method will eventually be used by a particular Android app to diff --git a/src/bitmessagecli.py b/src/bitmessagecli.py index 79272aee..74836877 100644 --- a/src/bitmessagecli.py +++ b/src/bitmessagecli.py @@ -63,8 +63,6 @@ def lookupAppdataFolder(): #gets the appropriate folders for the .dat files depe return dataFolder def configInit(): - global keysName - BMConfigParser().add_section('bitmessagesettings') BMConfigParser().set('bitmessagesettings', 'port', '8444') #Sets the bitmessage port to stop the warning about the api not properly being setup. This is in the event that the keys.dat is in a different directory or is created locally to connect to a machine remotely. BMConfigParser().set('bitmessagesettings','apienabled','true') #Sets apienabled to true in keys.dat @@ -76,7 +74,6 @@ def configInit(): print ' You will now need to configure the ' + str(keysName) + ' file.\n' def apiInit(apiEnabled): - global keysPath global usrPrompt BMConfigParser().read(keysPath) @@ -1144,8 +1141,6 @@ def delSentMsg(msgNum): #Deletes a specified message from the outbox return msgAck def getLabelForAddress(address): - global usrPrompt - if address in knownAddresses: return knownAddresses[address] else: diff --git a/src/bitmessagecurses/__init__.py b/src/bitmessagecurses/__init__.py index 61e2466a..2cfb8c67 100644 --- a/src/bitmessagecurses/__init__.py +++ b/src/bitmessagecurses/__init__.py @@ -333,7 +333,6 @@ def handlech(c, stdscr): sendMessage(fromaddr, toaddr, ischan, subject, body, True) dialogreset(stdscr) elif t == "4": # Add to Address Book - global addrbook addr = inbox[inboxcur][4] if addr not in [item[1] for i,item in enumerate(addrbook)]: r, t = d.inputbox("Label for address \""+addr+"\"") @@ -572,7 +571,7 @@ def handlech(c, stdscr): subscriptions.append([label, addr, True]) subscriptions.reverse() - sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, address, True) + sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, addr, True) shared.reloadBroadcastSendersForWhichImWatching() elif t == "2": r, t = d.inpuxbox("Type in \"I want to delete this subscription\"") @@ -611,7 +610,7 @@ def handlech(c, stdscr): subscriptions.append([label, addr, True]) subscriptions.reverse() - sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, address, True) + sqlExecute("INSERT INTO subscriptions VALUES (?,?,?)", label, addr, True) shared.reloadBroadcastSendersForWhichImWatching() elif t == "3": r, t = d.inputbox("Input new address") @@ -836,7 +835,6 @@ def loadInbox(): FROM inbox WHERE folder='inbox' AND %s LIKE ? ORDER BY received """ % (where,), what) - global inbox for row in ret: msgid, toaddr, fromaddr, subject, received, read = row subject = ascii(shared.fixPotentiallyInvalidUTF8Data(subject)) @@ -886,7 +884,6 @@ def loadSent(): FROM sent WHERE folder='sent' AND %s LIKE ? ORDER BY lastactiontime """ % (where,), what) - global sent for row in ret: toaddr, fromaddr, subject, status, ackdata, lastactiontime = row subject = ascii(shared.fixPotentiallyInvalidUTF8Data(subject)) @@ -958,7 +955,6 @@ def loadAddrBook(): sys.stdout = printlog ret = sqlQuery("SELECT label, address FROM addressbook") - global addrbook for row in ret: label, addr = row label = shared.fixPotentiallyInvalidUTF8Data(label) @@ -1003,7 +999,7 @@ def runwrapper(): stdscr.timeout(1000) curses.wrapper(run) - shutdown() + doShutdown() def run(stdscr): # Schedule inventory lookup data @@ -1050,7 +1046,7 @@ def run(stdscr): drawtab(stdscr) handlech(stdscr.getch(), stdscr) -def shutdown(): +def doShutdown(): sys.stdout = sys.__stdout__ print("Shutting down...") sys.stdout = printlog diff --git a/src/bitmessageqt/safehtmlparser.py b/src/bitmessageqt/safehtmlparser.py index 1692844e..5fe5265c 100644 --- a/src/bitmessageqt/safehtmlparser.py +++ b/src/bitmessageqt/safehtmlparser.py @@ -110,7 +110,7 @@ class SafeHTMLParser(HTMLParser): self.sanitised += "&" + name + ";" def feed(self, data): - global parserLock, parserProcess, parserInputQueue, parserOutputQueue + global parserProcess HTMLParser.feed(self, data) tmp = SafeHTMLParser.multi_replace(data) tmp = unicode(tmp, 'utf-8', 'replace') diff --git a/src/configparser.py b/src/configparser.py index 37a35868..bc16b05a 100644 --- a/src/configparser.py +++ b/src/configparser.py @@ -56,7 +56,7 @@ class BMConfigParser(ConfigParser.SafeConfigParser): shutil.copyfile(fileName, fileNameBak) # The backup succeeded. fileNameExisted = True - except (IOError, Error): + except (IOError, Exception): # The backup failed. This can happen if the file didn't exist before. fileNameExisted = False # write the file diff --git a/src/helper_bootstrap.py b/src/helper_bootstrap.py index a3f74288..795b4d2a 100644 --- a/src/helper_bootstrap.py +++ b/src/helper_bootstrap.py @@ -1,4 +1,3 @@ -import shared import socket import defaultKnownNodes import pickle diff --git a/src/messagetypes/message.py b/src/messagetypes/message.py index 0ba97cd9..ab61e375 100644 --- a/src/messagetypes/message.py +++ b/src/messagetypes/message.py @@ -23,7 +23,7 @@ class Message(MsgBase): self.data["subject"] = data["subject"] self.data["body"] = data["body"] except KeyError as e: - logger.error("Missing key ", e.name) + logger.error("Missing key %s", e.name) return self.data def process(self): diff --git a/src/messagetypes/vote.py b/src/messagetypes/vote.py index 539aed8a..df8d267f 100644 --- a/src/messagetypes/vote.py +++ b/src/messagetypes/vote.py @@ -15,7 +15,7 @@ class Vote(MsgBase): self.data["msgid"] = data["msgid"] self.data["vote"] = data["vote"] except KeyError as e: - logger.error("Missing key ", e.name) + logger.error("Missing key %s", e.name) return self.data def process(self): diff --git a/src/network/advanceddispatcher.py b/src/network/advanceddispatcher.py index 47eacc5a..8258412a 100644 --- a/src/network/advanceddispatcher.py +++ b/src/network/advanceddispatcher.py @@ -1,3 +1,5 @@ +import asyncore + class AdvancedDispatcher(asyncore.dispatcher): _buf_len = 131072 @@ -7,13 +9,13 @@ class AdvancedDispatcher(asyncore.dispatcher): self.write_buf = "" self.state = "init" - def slice_read_buf(length=0): + def slice_read_buf(self, length=0): self.read_buf = self.read_buf[length:] - def slice_write_buf(length=0): + def slice_write_buf(self, length=0): self.write_buf = self.read_buf[length:] - def read_buf_sufficient(length=0): + def read_buf_sufficient(self, length=0): if len(self.read_buf) < length: return False else: diff --git a/src/openclpow.py b/src/openclpow.py index 168f963f..b8c73987 100644 --- a/src/openclpow.py +++ b/src/openclpow.py @@ -26,7 +26,7 @@ except: libAvailable = False def initCL(): - global ctx, queue, program, gpus, enabledGpus, hash_dt, vendors + global ctx, queue, program, enabledGpus, hash_dt try: hash_dt = numpy.dtype([('target', numpy.uint64), ('v', numpy.str_, 73)]) try: diff --git a/src/proofofwork.py b/src/proofofwork.py index 8cb6e7e8..6ad790c0 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -157,8 +157,6 @@ def getPowType(): return "python" def notifyBuild(tried=False): - global bmpow - if bmpow: queues.UISignalQueue.put(('updateStatusBar', (tr._translate("proofofwork", "C PoW module built successfully."), 1))) elif tried: @@ -167,8 +165,6 @@ def notifyBuild(tried=False): queues.UISignalQueue.put(('updateStatusBar', (tr._translate("proofofwork", "C PoW module unavailable. Please build it."), 1))) def buildCPoW(): - global bmpow - if bmpow is not None: return if paths.frozen is not None: diff --git a/src/protocol.py b/src/protocol.py index 60e270bc..2993abdd 100644 --- a/src/protocol.py +++ b/src/protocol.py @@ -15,6 +15,7 @@ from debug import logger from helper_sql import sqlExecute import highlevelcrypto from inventory import Inventory +from queues import objectProcessorQueue import state from version import softwareVersion diff --git a/src/shared.py b/src/shared.py index a41271bc..4fefa0f8 100644 --- a/src/shared.py +++ b/src/shared.py @@ -9,9 +9,6 @@ useVeryEasyProofOfWorkForTesting = False # If you set this to True while on the # Libraries. import os -import pickle -import Queue -from multiprocessing import active_children, Queue as mpQueue, Lock as mpLock import sys import stat import threading @@ -25,7 +22,6 @@ from configparser import BMConfigParser import highlevelcrypto #import helper_startup from helper_sql import * -from helper_threading import * from inventory import Inventory, PendingDownload from queues import objectProcessorQueue import protocol diff --git a/src/state.py b/src/state.py index e1a5adad..3d5209c4 100644 --- a/src/state.py +++ b/src/state.py @@ -1,5 +1,4 @@ import collections -import threading neededPubkeys = {} streamsInWhichIAmParticipating = []