From c813f679ae82fc4b802c896b5d5f75cd8e21700f Mon Sep 17 00:00:00 2001 From: "jai.s" Date: Thu, 3 Oct 2019 20:27:22 +0530 Subject: [PATCH] Solved bmconfigparser python3 incompatibility issue and removed unrequired comment and line of code which are added during python3 plotting --- src/addresses.py | 1 - src/bitmessagekivy/mpybit.py | 3 ++- src/bitmessagemain.py | 1 - src/bmconfigparser.py | 6 ++++-- src/helper_startup.py | 2 +- src/highlevelcrypto.py | 2 -- src/knownnodes.py | 2 -- src/network/asyncore_pollchoose.py | 1 - src/network/connectionpool.py | 2 +- src/network/dandelion.py | 18 +++++++++--------- src/network/downloadthread.py | 4 ++-- src/network/stats.py | 1 - src/network/uploadthread.py | 4 ++-- src/pyelliptic/arithmetic.py | 6 ------ src/pyelliptic/ecc.py | 27 +++++++-------------------- src/shared.py | 2 -- 16 files changed, 28 insertions(+), 54 deletions(-) diff --git a/src/addresses.py b/src/addresses.py index 4d200332..a55fc415 100644 --- a/src/addresses.py +++ b/src/addresses.py @@ -191,7 +191,6 @@ def decodeAddress(address): return status, 0, 0, '' # after converting to hex, the string will be prepended # with a 0x and appended with a L - # import pdb;pdb.set_trace() hexdata = hex(integer)[2:] if len(hexdata) % 2 != 0: diff --git a/src/bitmessagekivy/mpybit.py b/src/bitmessagekivy/mpybit.py index 6f7b1cc6..aa55d35b 100644 --- a/src/bitmessagekivy/mpybit.py +++ b/src/bitmessagekivy/mpybit.py @@ -93,7 +93,7 @@ class Inbox(Screen): def init_ui(self, dt=0): """Clock Schdule for method inbox accounts.""" self.inboxaccounts() - print (dt) + print(dt) def inboxaccounts(self): """Load inbox accounts.""" @@ -309,6 +309,7 @@ class MyAddress(Screen): self.init_ui() self.ids.refresh_layout.refresh_done() self.tick = 0 + Clock.schedule_once(refresh_callback, 1) @staticmethod diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 6e8206ef..dcf03118 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -200,7 +200,6 @@ class Main: # pylint: disable=no-init, old-style-class from plugins.plugin import get_plugin try: proxyconfig_start = time.time() - import pdb;pdb.set_trace if not get_plugin('proxyconfig', name=proxy_type)(config): raise TypeError except TypeError: diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index 6f5660e0..d05787d9 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -125,10 +125,12 @@ class BMConfigParser(configparser.ConfigParser): try: if not self.validate( section, option, - configparser.ConfigParser.get(self, section, option) + self[section][option] ): try: newVal = BMConfigDefaults[section][option] + except configparser.NoSectionError: + continue except KeyError: continue configparser.ConfigParser.set( @@ -159,7 +161,7 @@ class BMConfigParser(configparser.ConfigParser): def validate(self, section, option, value): try: - return getattr(self, 'validate_%s_%s' % (section, option))(value) + return getattr(self, 'validate_{}_{}'.format(section, option))(value) except AttributeError: return True diff --git a/src/helper_startup.py b/src/helper_startup.py index f0457638..110110b6 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -33,7 +33,7 @@ def _loadTrustedPeer(): # can just leave it as None return try: - # import pdb;pdb.set_trace() + if trustedPeer != None: host, port = trustedPeer.split(':') state.trustedPeer = state.Peer(host, int(port)) diff --git a/src/highlevelcrypto.py b/src/highlevelcrypto.py index 648e11a7..512c55b5 100644 --- a/src/highlevelcrypto.py +++ b/src/highlevelcrypto.py @@ -13,12 +13,10 @@ from pyelliptic import arithmetic as a def makeCryptor(privkey): """Return a private pyelliptic.ECC() instance""" - # import pdb;pdb.set_trace() private_key = a.changebase(privkey, 16, 256, minlen=32) public_key = pointMult(private_key) privkey_bin = '\x02\xca\x00\x20'.encode('utf-8') + private_key pubkey_bin = '\x02\xca\x00\x20'.encode('utf-8') + public_key[1:-32] + '\x00\x20'.encode('utf-8') + public_key[-32:] - import pdb;pdb.set_trace() cryptor = pyelliptic.ECC(curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin) return cryptor diff --git a/src/knownnodes.py b/src/knownnodes.py index 35d105bc..4052e3ae 100644 --- a/src/knownnodes.py +++ b/src/knownnodes.py @@ -46,7 +46,6 @@ def json_serialize_knownnodes(output): _serialized.append({ 'stream': stream, 'peer': peer._asdict(), 'info': info }) - # import pdb;pdb.set_trace() json.dump(_serialized, output, indent=4) @@ -55,7 +54,6 @@ def json_deserialize_knownnodes(source): Read JSON from source and make knownnodes dict """ global knownNodesActual # pylint: disable=global-statement - # import pdb;pdb.set_trace() for node in json.load(source): peer = node['peer'] info = node['info'] diff --git a/src/network/asyncore_pollchoose.py b/src/network/asyncore_pollchoose.py index 3137797c..1c93283f 100644 --- a/src/network/asyncore_pollchoose.py +++ b/src/network/asyncore_pollchoose.py @@ -767,7 +767,6 @@ class dispatcher: # references to the underlying socket object. def __getattr__(self, attr): try: - # import pdb;pdb.set_trace() retattr = getattr(self.socket, attr) except AttributeError: raise AttributeError("{} instance has no attribute {}" diff --git a/src/network/connectionpool.py b/src/network/connectionpool.py index 313f3924..adc8cf51 100644 --- a/src/network/connectionpool.py +++ b/src/network/connectionpool.py @@ -236,7 +236,7 @@ class BMConnectionPool(object): except ValueError: Proxy.onion_proxy = None established = sum( - 1 for c in self.outboundConnections.values() + 1 for c in list(self.outboundConnections.values()) if (c.connected and c.fullyEstablished)) pending = len(self.outboundConnections) - established if established < BMConfigParser().safeGetInt( diff --git a/src/network/dandelion.py b/src/network/dandelion.py index abba16ba..e51df5d1 100644 --- a/src/network/dandelion.py +++ b/src/network/dandelion.py @@ -99,12 +99,12 @@ class Dandelion(): # pylint: disable=old-style-class with self.lock: if len(self.stem) < MAX_STEMS: self.stem.append(connection) - for k in (k for k, v in self.nodeMap.iteritems() if v is None): + for k in (k for k, v in iter(self.nodeMap.items()) if v is None): self.nodeMap[k] = connection - for k, v in { - k: v for k, v in self.hashMap.iteritems() + for k, v in iter({ + k: v for k, v in iter(self.hashMap.items()) if v.child is None - }.iteritems(): + }).items(): self.hashMap[k] = Stem( connection, v.stream, self.poissonTimeout()) invQueue.put((v.stream, k, v.child)) @@ -120,13 +120,13 @@ class Dandelion(): # pylint: disable=old-style-class self.stem.remove(connection) # active mappings to pointing to the removed node for k in ( - k for k, v in self.nodeMap.iteritems() if v == connection + k for k, v in iter(self.nodeMap.items()) if v == connection ): self.nodeMap[k] = None - for k, v in { - k: v for k, v in self.hashMap.iteritems() + for k, v in iter({ + k: v for k, v in iter(self.hashMap.items()) if v.child == connection - }.iteritems(): + }).items(): self.hashMap[k] = Stem( None, v.stream, self.poissonTimeout()) @@ -167,7 +167,7 @@ class Dandelion(): # pylint: disable=old-style-class with self.lock: deadline = time() toDelete = [ - [v.stream, k, v.child] for k, v in self.hashMap.iteritems() + [v.stream, k, v.child] for k, v in iter(self.hashMap.items()) if v.timeout < deadline ] diff --git a/src/network/downloadthread.py b/src/network/downloadthread.py index a09d0c1d..561fd342 100644 --- a/src/network/downloadthread.py +++ b/src/network/downloadthread.py @@ -32,7 +32,7 @@ class DownloadThread(StoppableThread): """Expire pending downloads eventually""" deadline = time.time() - DownloadThread.requestExpires try: - toDelete = [k for k, v in missingObjects.iteritems() if v < deadline] + toDelete = [k for k, v in iter(missingObjects.items()) if v < deadline] except RuntimeError: pass else: @@ -46,7 +46,7 @@ class DownloadThread(StoppableThread): # Choose downloading peers randomly connections = [ x for x in - BMConnectionPool().inboundConnections.values() + BMConnectionPool().outboundConnections.values() + list(BMConnectionPool().inboundConnections.values()) + list(BMConnectionPool().outboundConnections.values()) if x.fullyEstablished] helper_random.randomshuffle(connections) try: diff --git a/src/network/stats.py b/src/network/stats.py index 31ffcbf3..1a57629d 100644 --- a/src/network/stats.py +++ b/src/network/stats.py @@ -20,7 +20,6 @@ currentSentSpeed = 0 def connectedHostsList(): """List of all the connected hosts""" retval = [] - # import pdb;pdb.set_trace() for i in list(BMConnectionPool().inboundConnections.values()) + \ list(BMConnectionPool().outboundConnections.values()): if not i.fullyEstablished: diff --git a/src/network/uploadthread.py b/src/network/uploadthread.py index 1b06af23..a0329c83 100644 --- a/src/network/uploadthread.py +++ b/src/network/uploadthread.py @@ -26,8 +26,8 @@ class UploadThread(StoppableThread): while not self._stopped: uploaded = 0 # Choose downloading peers randomly - connections = [x for x in BMConnectionPool().inboundConnections.values() + - BMConnectionPool().outboundConnections.values() if x.fullyEstablished] + connections = [x for x in list(BMConnectionPool().inboundConnections.values()) + + list(BMConnectionPool().outboundConnections.values()) if x.fullyEstablished] helper_random.randomshuffle(connections) for i in connections: now = time.time() diff --git a/src/pyelliptic/arithmetic.py b/src/pyelliptic/arithmetic.py index 7b7a477b..f5106768 100644 --- a/src/pyelliptic/arithmetic.py +++ b/src/pyelliptic/arithmetic.py @@ -42,14 +42,10 @@ def encode(val, base, minlen=0): result = "" result = str.encode(result) count = 0 - # import pdb;pdb.set_trace() while val > 0: count += 1 - # import pdb;pdb.set_trace() result = code_string[int(val) % base:int(val) % base + 1] + result - # print('the value of the result-{}'.format(result)) val = int(val / base) - # import pdb;pdb.set_trace() if len(result) < minlen: result = code_string[0] * (minlen - len(result)) + result return result @@ -62,7 +58,6 @@ def decode(string, base): if base == 16: string = string.lower() while string: - # import pdb;pdb.set_trace() result *= base result += code_string.find(string.decode()[0]) string = string[1:] @@ -70,7 +65,6 @@ def decode(string, base): def changebase(string, frm, to, minlen=0): - # import pdb;pdb.set_trace() return encode(decode(string, frm), to, minlen) diff --git a/src/pyelliptic/ecc.py b/src/pyelliptic/ecc.py index 63748287..f0cba579 100644 --- a/src/pyelliptic/ecc.py +++ b/src/pyelliptic/ecc.py @@ -74,13 +74,11 @@ class ECC(object): if curve != curve2: raise Exception("Bad ECC keys ...") self.curve = curve - import pdb;pdb.set_trace() self._set_keys(pubkey_x, pubkey_y, raw_privkey) else: self.privkey, self.pubkey_x, self.pubkey_y = self._generate() def _set_keys(self, pubkey_x, pubkey_y, privkey): - import pdb;pdb.set_trace() if self.raw_check_key(privkey, pubkey_x, pubkey_y) < 0: self.pubkey_x = None self.pubkey_y = None @@ -132,35 +130,25 @@ class ECC(object): @staticmethod def _decode_pubkey(pubkey): - # pubkey = pubkey.encode() - import pdb;pdb.set_trace() i = 0 - # curve = unpack('!H', pubkey[i:i + 2])[0] - curve = pack('!s', pubkey[i:i + 1])[0] - + curve = unpack('!H', pubkey[i:i + 2])[0] i += 2 - # tmplen = unpack('!H', pubkey[i:i + 2])[0] - tmplen = pack('!s', pubkey[i:i + 1])[0] + tmplen = unpack('!H', pubkey[i:i + 2])[0] i += 2 pubkey_x = pubkey[i:i + tmplen] - # i += tmplen + i += tmplen i += int(tmplen / 3) - # tmplen = unpack('!H', pubkey[i:i + 2])[0] - tmplen = pack('!s', pubkey[i:i + 1])[0] - # i += 2 + tmplen = unpack('!H', pubkey[i:i + 2])[0] + i += 2 pubkey_y = pubkey[i:i + tmplen] - # i += tmplen + i += tmplen return curve, pubkey_x, pubkey_y, int(i) @staticmethod def _decode_privkey(privkey): i = 0 - # import pdb;pdb.set_trace() - # curve = unpack('!H', privkey[i:i + 2])[0] - curve = pack('!s', privkey[i:i + 1])[0] - + curve = unpack('!H', privkey[i:i + 2])[0] i += 2 - # tmplen = unpack('!H', privkey[i:i + 2])[0] tmplen = pack('!s', privkey[i:i + 1])[0] i += 2 privkey = privkey[i:i + tmplen] @@ -288,7 +276,6 @@ class ECC(object): return self.raw_check_key(raw_privkey, pubkey_x, pubkey_y, curve) def raw_check_key(self, privkey, pubkey_x, pubkey_y, curve=None): - import pdb;pdb.set_trace() """Check key validity, key is supplied as binary data""" # pylint: disable=too-many-branches if curve is None: diff --git a/src/shared.py b/src/shared.py index 2a53452a..60c35096 100644 --- a/src/shared.py +++ b/src/shared.py @@ -174,11 +174,9 @@ def reloadBroadcastSendersForWhichImWatching(): # Now, for all addresses, even version 2 addresses, # we should create Cryptor objects in a dictionary which we will # use to attempt to decrypt encrypted broadcast messages. - # import pdb;pdb.set_trace() if addressVersionNumber <= 3: privEncryptionKey = hashlib.sha512((encodeVarint(addressVersionNumber) \ + encodeVarint(streamNumber) + hash)).digest()[:32] - # import pdb;pdb.set_trace() MyECSubscriptionCryptorObjects[hash] = \ highlevelcrypto.makeCryptor(hexlify(privEncryptionKey)) else: