Skip to content

Commit f020aca

Browse files
Minor Python cleanups to make flake8 pass with the new rules enabled
1 parent 0d69921 commit f020aca

21 files changed

+58
-50
lines changed

contrib/devtools/copyright_header.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def exec_report(base_directory, verbose):
286286
def report_cmd(argv):
287287
if len(argv) == 2:
288288
sys.exit(REPORT_USAGE)
289-
289+
290290
base_directory = argv[2]
291291
if not os.path.exists(base_directory):
292292
sys.exit("*** bad <base_directory>: %s" % base_directory)
@@ -444,7 +444,7 @@ def print_file_action_message(filename, action):
444444
def update_cmd(argv):
445445
if len(argv) != 3:
446446
sys.exit(UPDATE_USAGE)
447-
447+
448448
base_directory = argv[2]
449449
if not os.path.exists(base_directory):
450450
sys.exit("*** bad base_directory: %s" % base_directory)
@@ -570,13 +570,13 @@ def insert_cmd(argv):
570570
_, extension = os.path.splitext(filename)
571571
if extension not in ['.h', '.cpp', '.cc', '.c', '.py']:
572572
sys.exit("*** cannot insert for file extension %s" % extension)
573-
573+
574574
if extension == '.py':
575575
style = 'python'
576576
else:
577577
style = 'cpp'
578578
exec_insert_header(filename, style)
579-
579+
580580
################################################################################
581581
# UI
582582
################################################################################

contrib/devtools/github-merge.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import hashlib
2222
import subprocess
2323
import sys
24-
import json,codecs
24+
import json
25+
import codecs
2526
try:
2627
from urllib.request import Request,urlopen
2728
except:

contrib/devtools/optimize-pngs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ def content_hash(filename):
4141
file_path = os.path.join(absFolder, file)
4242
fileMetaMap = {'file' : file, 'osize': os.path.getsize(file_path), 'sha256Old' : file_hash(file_path)}
4343
fileMetaMap['contentHashPre'] = content_hash(file_path)
44-
44+
4545
try:
4646
subprocess.call([pngcrush, "-brute", "-ow", "-rem", "gAMA", "-rem", "cHRM", "-rem", "iCCP", "-rem", "sRGB", "-rem", "alla", "-rem", "text", file_path],
4747
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
4848
except:
4949
print("pngcrush is not installed, aborting...")
5050
sys.exit(0)
51-
51+
5252
#verify
5353
if "Not a PNG file" in subprocess.check_output([pngcrush, "-n", "-v", file_path], stderr=subprocess.STDOUT, universal_newlines=True):
5454
print("PNG file "+file+" is corrupted after crushing, check out pngcursh version")
5555
sys.exit(1)
56-
56+
5757
fileMetaMap['sha256New'] = file_hash(file_path)
5858
fileMetaMap['contentHashPost'] = content_hash(file_path)
5959

@@ -72,5 +72,5 @@ def content_hash(filename):
7272
totalSaveBytes += fileDict['osize'] - fileDict['psize']
7373
noHashChange = noHashChange and (oldHash == newHash)
7474
print(fileDict['file']+"\n size diff from: "+str(fileDict['osize'])+" to: "+str(fileDict['psize'])+"\n old sha256: "+oldHash+"\n new sha256: "+newHash+"\n")
75-
75+
7676
print("completed. Checksum stable: "+str(noHashChange)+". Total reduction: "+str(totalSaveBytes)+" bytes")

contrib/linearize/linearize-data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
settings = {}
2323

24-
##### Switch endian-ness #####
2524
def hex_switchEndian(s):
2625
""" Switches the endianness of a hex string (in pairs of hex chars) """
2726
pairList = [s[i:i+2].encode() for i in range(0, len(s), 2)]

contrib/linearize/linearize-hashes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
settings = {}
2323

24-
##### Switch endian-ness #####
2524
def hex_switchEndian(s):
2625
""" Switches the endianness of a hex string (in pairs of hex chars) """
2726
pairList = [s[i:i+2].encode() for i in range(0, len(s), 2)]

contrib/seeds/generate-seeds.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434

3535
from base64 import b32decode
3636
from binascii import a2b_hex
37-
import sys, os
37+
import sys
38+
import os
3839
import re
3940

4041
# ipv4 in ipv6 prefix
@@ -46,7 +47,7 @@ def name_to_ipv6(addr):
4647
if len(addr)>6 and addr.endswith('.onion'):
4748
vchAddr = b32decode(addr[0:-6], True)
4849
if len(vchAddr) != 16-len(pchOnionCat):
49-
raise ValueError('Invalid onion %s' % s)
50+
raise ValueError('Invalid onion %s' % vchAddr)
5051
return pchOnionCat + vchAddr
5152
elif '.' in addr: # IPv4
5253
return pchIPv4 + bytearray((int(x) for x in addr.split('.')))
@@ -132,7 +133,7 @@ def main():
132133
with open(os.path.join(indir,'nodes_test.txt'),'r') as f:
133134
process_nodes(g, f, 'pnSeed6_test', 18333)
134135
g.write('#endif // BITCOIN_CHAINPARAMSSEEDS_H\n')
135-
136+
136137
if __name__ == '__main__':
137138
main()
138139

contrib/seeds/makeseeds.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
# Generate seeds.txt from Pieter's DNS seeder
77
#
88

9+
import re
10+
import sys
11+
import dns.resolver
12+
import collections
13+
914
NSEEDS=512
1015

1116
MAX_SEEDS_PER_ASN=2
@@ -22,11 +27,6 @@
2227
"54.94.195.96", "54.94.200.247"
2328
}
2429

25-
import re
26-
import sys
27-
import dns.resolver
28-
import collections
29-
3030
PATTERN_IPV4 = re.compile(r"^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})):(\d+)$")
3131
PATTERN_IPV6 = re.compile(r"^\[([0-9a-z:]+)\]:(\d+)$")
3232
PATTERN_ONION = re.compile(r"^([abcdefghijklmnopqrstuvwxyz234567]{16}\.onion):(\d+)$")

contrib/testgen/base58.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ def b58encode(v):
4343
# leading 0-bytes in the input become leading-1s
4444
nPad = 0
4545
for c in v:
46-
if c == 0: nPad += 1
47-
else: break
46+
if c == 0:
47+
nPad += 1
48+
else:
49+
break
4850

4951
return (__b58chars[0]*nPad) + result
5052

@@ -98,7 +100,8 @@ def b58decode_chk(v):
98100
def get_bcaddress_version(strAddress):
99101
""" Returns None if strAddress is invalid. Otherwise returns integer version of address. """
100102
addr = b58decode_chk(strAddress)
101-
if addr is None or len(addr)!=21: return None
103+
if addr is None or len(addr)!=21:
104+
return None
102105
version = addr[0]
103106
return ord(version)
104107

contrib/testgen/gen_base58_test_vectors.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def gen_invalid_vector(template, corrupt_prefix, randomize_payload_size, corrupt
7474
prefix = os.urandom(1)
7575
else:
7676
prefix = bytearray(template[0])
77-
77+
7878
if randomize_payload_size:
7979
payload = os.urandom(max(int(random.expovariate(0.5)), 50))
8080
else:
8181
payload = os.urandom(template[1])
82-
82+
8383
if corrupt_suffix:
8484
suffix = os.urandom(len(template[2]))
8585
else:
@@ -114,7 +114,8 @@ def gen_invalid_vectors():
114114
yield val,
115115

116116
if __name__ == '__main__':
117-
import sys, json
117+
import sys
118+
import json
118119
iters = {'valid':gen_valid_vectors, 'invalid':gen_invalid_vectors}
119120
try:
120121
uiter = iters[sys.argv[1]]
@@ -124,7 +125,7 @@ def gen_invalid_vectors():
124125
count = int(sys.argv[2])
125126
except IndexError:
126127
count = 0
127-
128+
128129
data = list(islice(uiter(), count))
129130
json.dump(data, sys.stdout, sort_keys=True, indent=4)
130131
sys.stdout.write('\n')

share/rpcauth/rpcauth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#Create 32 byte b64 password
2727
password = base64.urlsafe_b64encode(os.urandom(32)).decode("utf-8")
28-
28+
2929
m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), "SHA256")
3030
result = m.hexdigest()
3131

0 commit comments

Comments
 (0)