From aadbe9a50b65c84fdf1eb8c5cfa04913093caa5b Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Mon, 8 Jan 2024 22:06:23 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- 2proc_pmutex.py | 4 ++-- CVE-2016-2017.py | 2 +- CVE-2017-7679.py | 4 +--- TOTP_test.py | 6 +++--- android_fde_decryptkey.py | 10 ++++----- bitnodes.py | 2 +- brainflayer_parallelize.py | 6 +----- check_nmap.py | 4 ++-- compression_test2.py | 2 +- crack_AES256.py | 19 +++++++++--------- crc_make_tables.py | 4 +--- docker-get-swarm-nodes-ips.py | 2 +- ecdsa_privtopub.py | 2 +- exo2mp4.py | 2 +- ftpmassuploader.py | 2 +- hashtime.py | 3 +-- imm_pasadas.py | 22 ++++++-------------- licencia.py | 2 +- logsearch.py | 2 +- lrutest.py | 12 +++++------ mmapread.py | 2 +- msfhelper.py | 15 ++++---------- originstamp_privkey_get.py | 3 +-- pmkid_test_calc.py | 22 ++++++++------------ pw-aes-memcache.py | 18 ++++++++--------- readprocmem.py | 38 +++++++++++++++++------------------ readtest.py | 2 +- regex_test.py | 8 +++----- rpn.py | 12 +++++------ shuffledata.py | 5 +---- testQuasiLinearGCD.py | 2 +- test_AES256_2.py | 5 +---- test_rsa.py | 3 +-- test_rsqrt.py | 6 +++--- testpartition.py | 15 +++++++------- testxchain.py | 2 +- 36 files changed, 112 insertions(+), 158 deletions(-) diff --git a/2proc_pmutex.py b/2proc_pmutex.py index da6d8d2..c8ac0f3 100644 --- a/2proc_pmutex.py +++ b/2proc_pmutex.py @@ -15,12 +15,12 @@ def enter_region(process): other = 1 - process interested[process] = True turn = process - while turn == process and interested[other] == True: + while turn == turn and interested[other] == True: k += 1 # if (k % 10000 == 0): # print "process wait",process continue - print("entered_critical: %d ticks %d" % (process, k)) + print("entered_critical: %d ticks %d" % (turn, k)) def leave_region(process): diff --git a/CVE-2016-2017.py b/CVE-2016-2017.py index 773ae18..aeded84 100644 --- a/CVE-2016-2017.py +++ b/CVE-2016-2017.py @@ -30,7 +30,7 @@ ssl_sock.write("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") print("sent...") try: - print("recv:" + ssl_sock.recv(512)) + print(f"recv:{ssl_sock.recv(512)}") except ssl.SSLError as err: if err.find("record overflow"): print("Vulnerable") diff --git a/CVE-2017-7679.py b/CVE-2017-7679.py index d65216e..d877fa7 100644 --- a/CVE-2017-7679.py +++ b/CVE-2017-7679.py @@ -31,9 +31,7 @@ def check_url(url, buff=None): s1 = check_url(sys.argv[1]) s2 = check_url(sys.argv[1], buff) -i = list(difflib.unified_diff(s1, s2)) - -if len(i) > 0: +if i := list(difflib.unified_diff(s1, s2)): print("[+] Host Vulnerable!") else: print("[-] Host Not vulnerable!") diff --git a/TOTP_test.py b/TOTP_test.py index 998d5e5..bacc593 100644 --- a/TOTP_test.py +++ b/TOTP_test.py @@ -12,7 +12,7 @@ tmp = tempfile.mkstemp()[1] -os.system("cat %s | gpg --decrypt > %s" % (sys.argv[1], tmp)) +os.system(f"cat {sys.argv[1]} | gpg --decrypt > {tmp}") conn = sqlite3.connect(tmp) c = conn.cursor() @@ -21,5 +21,5 @@ totp = pyotp.TOTP(row[2]) print(totp.now(), row[1]) -os.system("shred %s -v" % tmp) -os.system("rm %s" % tmp) +os.system(f"shred {tmp} -v") +os.system(f"rm {tmp}") diff --git a/android_fde_decryptkey.py b/android_fde_decryptkey.py index fa21dfc..16c8a33 100644 --- a/android_fde_decryptkey.py +++ b/android_fde_decryptkey.py @@ -33,10 +33,10 @@ ENCRYPT = 1 DECRYPT = 0 -assert path.isfile(header_file), "Input file '%s' not found." % header_file -assert path.isfile(encrypted_partition), ( - "Input file '%s' not found." % encrypted_partition -) +assert path.isfile(header_file), f"Input file '{header_file}' not found." +assert path.isfile( + encrypted_partition +), f"Input file '{encrypted_partition}' not found." header = open(header_file, "rb").read() # Unpack header @@ -52,7 +52,7 @@ fsSize2, failedDecrypt, cryptoType, -) = struct.unpack(HEADER_FORMAT, header[0:100]) +) = struct.unpack(HEADER_FORMAT, header[:100]) encrypted_key = header[ftrSize : ftrSize + keySize] salt = header[ftrSize + keySize + 32 : ftrSize + keySize + 32 + 16] diff --git a/bitnodes.py b/bitnodes.py index bc6e2cb..25d05fd 100644 --- a/bitnodes.py +++ b/bitnodes.py @@ -9,7 +9,7 @@ def make_request(*args): opener = urllib.request.build_opener() - opener.addheaders = [("User-agent", "Mozilla/5.0" + str(random.randrange(1000000)))] + opener.addheaders = [("User-agent", f"Mozilla/5.0{random.randrange(1000000)}")] try: return opener.open(*args).read().strip() except Exception as e: diff --git a/brainflayer_parallelize.py b/brainflayer_parallelize.py index e7f853b..46ed4fe 100644 --- a/brainflayer_parallelize.py +++ b/brainflayer_parallelize.py @@ -12,11 +12,7 @@ outputfile = sys.argv[2] h = sys.argv[1] -cmd = ( - "%s -b %s -m %s -f %s -v -a -o %s -I" - % (binary, bloomfile, tabfile, binfile, outputfile) - + " %s" -) +cmd = f"{binary} -b {bloomfile} -m {tabfile} -f {binfile} -v -a -o {outputfile} -I %s" n = 10 for i in range(1, n + 1): diff --git a/check_nmap.py b/check_nmap.py index ce4ab17..7992b6d 100755 --- a/check_nmap.py +++ b/check_nmap.py @@ -94,8 +94,8 @@ def main(): nm.scan(host, sys.argv[2], arguments="--system-dns") ports = getports(nm, host) num_status, output = proc_results(nm, old_nm, host, ports) - json2file(".check_nmap.py." + host + ".cache", nm[host]) - print(status[num_status] + ": " + output) + json2file(f".check_nmap.py.{host}.cache", nm[host]) + print(f"{status[num_status]}: {output}") sys.exit(num_status) diff --git a/compression_test2.py b/compression_test2.py index 181a0a5..664d6c7 100644 --- a/compression_test2.py +++ b/compression_test2.py @@ -39,7 +39,7 @@ def test(msg_data): a, b, c = struct.unpack(">4si{0:d}s".format(msg_len), msg_data) print("Pack:", a, b, c.encode("hex")) new_data = zlib.decompress(c) - print("Decompressed data: " + new_data) + print(f"Decompressed data: {new_data}") test("dario") diff --git a/crack_AES256.py b/crack_AES256.py index f3ab21d..66cf5e3 100644 --- a/crack_AES256.py +++ b/crack_AES256.py @@ -29,16 +29,15 @@ def Hash(x): def pw_decode(s, password): - if password is not None: - secret = Hash(password) - try: - d = DecodeAES(secret, s) - # d = decrypt(s,secret) - except Exception as e: - raise Exception("Invalid password") - return d - else: + if password is None: return s + secret = Hash(password) + try: + d = DecodeAES(secret, s) + # d = decrypt(s,secret) + except Exception as e: + raise Exception("Invalid password") + return d def try_pw(encoded_seed, pw_cand): @@ -174,7 +173,7 @@ def test(): seed = try_pw(encoded_seed, pw_cand1) if chk_seed(seed): - print("pw is good: %s" % pw_cand1) + print(f"pw is good: {pw_cand1}") print(seed) cnt_good += 1 break diff --git a/crc_make_tables.py b/crc_make_tables.py index ab40f8c..ded3454 100644 --- a/crc_make_tables.py +++ b/crc_make_tables.py @@ -18,9 +18,7 @@ def make_crc_table(const): def displaytable(table): - string_hex_line = "" - for i in numbers: - string_hex_line += hex(i) + string_hex_line = "".join(hex(i) for i in numbers) print(string_hex_line) diff --git a/docker-get-swarm-nodes-ips.py b/docker-get-swarm-nodes-ips.py index 83037ca..ce540a8 100644 --- a/docker-get-swarm-nodes-ips.py +++ b/docker-get-swarm-nodes-ips.py @@ -1,7 +1,7 @@ import docker import sys -client = docker.DockerClient(base_url="tcp://%s:2375" % sys.argv[1]) +client = docker.DockerClient(base_url=f"tcp://{sys.argv[1]}:2375") nodes = client.nodes.list() for node in nodes: diff --git a/ecdsa_privtopub.py b/ecdsa_privtopub.py index fb13ddd..b375c0b 100644 --- a/ecdsa_privtopub.py +++ b/ecdsa_privtopub.py @@ -63,7 +63,7 @@ def leftmost_bit(x): assert x > 0 result = 1 while result <= x: - result = 2 * result + result *= 2 return result / 2 e = other diff --git a/exo2mp4.py b/exo2mp4.py index 3a397a9..3e90a24 100644 --- a/exo2mp4.py +++ b/exo2mp4.py @@ -21,4 +21,4 @@ for key, value in sorted(parts): print(key, value) - system("cat %s >> %s" % (value, target)) + system(f"cat {value} >> {target}") diff --git a/ftpmassuploader.py b/ftpmassuploader.py index c51674b..6e9872e 100644 --- a/ftpmassuploader.py +++ b/ftpmassuploader.py @@ -18,7 +18,7 @@ def upload(ip, filename): if run: ftp = FTP(ip, USER, PASS, timeout=timeout) # tp.login() - ftp.storlines("STOR %s" % filename, open(filename, "r")) + ftp.storlines(f"STOR {filename}", open(filename, "r")) filename = sys.argv[1] diff --git a/hashtime.py b/hashtime.py index a955fe1..6268a5f 100644 --- a/hashtime.py +++ b/hashtime.py @@ -7,8 +7,7 @@ print("Algo\tSpeed") a = list(hashlib.algorithms_available) -a.append("sha3_256") -a.append("sha3_512") +a.extend(("sha3_256", "sha3_512")) for h in a: size = 100 diff --git a/imm_pasadas.py b/imm_pasadas.py index 4d56c7e..9ac61e2 100644 --- a/imm_pasadas.py +++ b/imm_pasadas.py @@ -18,28 +18,18 @@ url_base = "http://www.montevideo.gub.uy/transporteRest/" -if l > 4: - url = ( - url_base - + "pasadas/" - + str(codigo_parada) - + "/" - + tipo_dia - + "/" - + str(linea) - + "/" - + hora - ) -else: - url = url_base + "pasadas/" + str(codigo_parada) + "/" + tipo_dia + "/" + hora - +url = ( + f"{url_base}pasadas/{str(codigo_parada)}/{tipo_dia}/{str(linea)}/{hora}" + if l > 4 + else f"{url_base}pasadas/{str(codigo_parada)}/{tipo_dia}/{hora}" +) j = json.loads(urllib.request.urlopen(url).read()) for pasada in j: print( "Linea:", pasada["linea"], "Hora:", - str(pasada["horaDesc"]), + pasada["horaDesc"], "Destino:", pasada["destino"], ) diff --git a/licencia.py b/licencia.py index caa605f..f305031 100644 --- a/licencia.py +++ b/licencia.py @@ -136,7 +136,7 @@ def calculate_best_candidate(start_date, days, franqueo): last_best = 0 hs = init_holidays(dstart.year) best = [] - for i in range(0, 365): + for _ in range(0, 365): # dstart += timedelta(days=1) r, d = lic(dstart, days, franqueo, hs) diff --git a/logsearch.py b/logsearch.py index 63cdf0a..043531a 100644 --- a/logsearch.py +++ b/logsearch.py @@ -44,7 +44,7 @@ def seeklog(A, key, imin, imax): def test(): - tmp = [x for x in range(1024 * 1024 * 20)] + tmp = list(range(1024 * 1024 * 20)) print("res=", seeklog(tmp, 1337, 0, len(tmp))) print("count=", count) diff --git a/lrutest.py b/lrutest.py index f8c2a90..6da3640 100644 --- a/lrutest.py +++ b/lrutest.py @@ -44,22 +44,22 @@ def test(): lru = LRU(4) for i in range(0, 21): - lru.insert("key" + str(i), str(i)) + lru.insert(f"key{str(i)}", str(i)) - for i in range(0, 1000): + for _ in range(0, 1000): lru.get("key13") - for i in range(0, 500): + for _ in range(0, 500): lru.get("key11") - for i in range(0, 250): + for _ in range(0, 250): lru.get("key7") - for i in range(0, 125): + for _ in range(0, 125): lru.get("key5") lru.get("key3") lru.get("key2") lru.get("key1") print(lru.access) - for i in range(0, 3): + for _ in range(0, 3): lru.purge() print(lru.access) diff --git a/mmapread.py b/mmapread.py index 6cd4174..025675a 100644 --- a/mmapread.py +++ b/mmapread.py @@ -8,7 +8,7 @@ pid = int(sys.argv[1]) with open("/proc/%d/maps" % pid, "r") as maps_file: with open("/proc/%d/mem" % pid, "r", 0) as mem_file: - for line in maps_file.readlines(): + for line in maps_file: line = line.rstrip() cols = line.split(" ") print(cols) diff --git a/msfhelper.py b/msfhelper.py index b8432c4..06e21ec 100644 --- a/msfhelper.py +++ b/msfhelper.py @@ -27,20 +27,13 @@ local_host = lhost[0] local_port = lhost[1] -if opt == "-n": - remote_hosts = list(ipaddress.IPv4Network(str(sys.argv[2]), strict=False).hosts()) - if opt == "-f": - remote_hosts = [] fp = open(sys.argv[2], "r") - for line in fp: - if line.find("#") == -1: - remote_hosts.append(line.strip()) + remote_hosts = [line.strip() for line in fp if line.find("#") == -1] +elif opt == "-n": + remote_hosts = list(ipaddress.IPv4Network(str(sys.argv[2]), strict=False).hosts()) for remote_host in remote_hosts: - if no_ping: + if not no_ping and pyping.ping(str(remote_host)) or no_ping: print(payload % (exploit, remote_host, local_host, local_port, meterpreter)) - else: - if pyping.ping(str(remote_host)): - print(payload % (exploit, remote_host, local_host, local_port, meterpreter)) print("exit") diff --git a/originstamp_privkey_get.py b/originstamp_privkey_get.py index 752fcfb..4e4c5da 100644 --- a/originstamp_privkey_get.py +++ b/originstamp_privkey_get.py @@ -28,8 +28,7 @@ def get_json(fp, sha256s): for line in fileinput.input(): - data = get_json(fp, line.replace("\n", "")) - if data: + if data := get_json(fp, line.replace("\n", "")): print(data["blockchain_transaction"]["private_key"]) fp.close() diff --git a/pmkid_test_calc.py b/pmkid_test_calc.py index b330e7c..3e86b1d 100644 --- a/pmkid_test_calc.py +++ b/pmkid_test_calc.py @@ -11,26 +11,20 @@ def PMKID(apmac, clmac, PSK, SSID): REQ = "2a416a999af0a6bf454684269afb06ef" -print("Required hash: %s" % REQ) +print(f"Required hash: {REQ}") apmac = "34:bf:90:4a:bb:57" clmac = "98:de:d0:1a:97:c2" PSK = "786 5555" SSID = "unknown" -print("SSID: [%s]" % SSID) -print("PSK: [%s]" % PSK) -print("AP mac: %s" % apmac) -print("Cl mac: %s" % clmac) +print(f"SSID: [{SSID}]") +print(f"PSK: [{PSK}]") +print(f"AP mac: {apmac}") +print(f"Cl mac: {clmac}") print( - "HASH: %s*%s*%s*%s" - % ( - REQ, - apmac.replace(":", ""), - clmac.replace(":", ""), - binascii.hexlify(SSID), - ) + f'HASH: {REQ}*{apmac.replace(":", "")}*{clmac.replace(":", "")}*{binascii.hexlify(SSID)}' ) pmkid, pmk = PMKID(apmac, clmac, PSK, SSID) -print("PMK: " + binascii.hexlify(pmk)) -print("PMKID: " + binascii.hexlify(pmkid[0:32])) +print(f"PMK: {binascii.hexlify(pmk)}") +print(f"PMKID: {binascii.hexlify(pmkid[:32])}") diff --git a/pw-aes-memcache.py b/pw-aes-memcache.py index 74e9fa4..ee4622d 100644 --- a/pw-aes-memcache.py +++ b/pw-aes-memcache.py @@ -71,27 +71,27 @@ def getkey(): def pw_get(): key = getkey() - print(key, len(key[0:32]), len(key[32:65])) - s = getmemcached(key[0:32]) + print(key, len(key[:32]), len(key[32:65])) + s = getmemcached(key[:32]) if s != None: - sys.stderr.write("memcached Crypted: " + s + "\n") + sys.stderr.write(f"memcached Crypted: {s}" + "\n") s = s.split(" ") ret = unpad(decrypt(s[1], key[32:65], s[0])) key = getkey() - sys.stderr.write("Time key: " + key + "\n") + sys.stderr.write(f"Time key: {key}" + "\n") s = encrypt(pad(ret), key[32:65]) - sys.stderr.write("reCrypted: " + s + "\n") - setmemcached(key[0:32], s) + sys.stderr.write(f"reCrypted: {s}" + "\n") + setmemcached(key[:32], s) return ret else: pw0 = getpass.getpass("Password: ") pw1 = getpass.getpass("Retype password: ") if pw0 == pw1: key = getkey() - sys.stderr.write("Time key: " + key + "\n") + sys.stderr.write(f"Time key: {key}" + "\n") s = encrypt(pad(pw0), key[32:65]) - sys.stderr.write("Crypted: " + s + "\n") - setmemcached(key[0:32], s) + sys.stderr.write(f"Crypted: {s}" + "\n") + setmemcached(key[:32], s) del pw1 return pw0 diff --git a/readprocmem.py b/readprocmem.py index 9db2111..84d33ef 100644 --- a/readprocmem.py +++ b/readprocmem.py @@ -7,24 +7,22 @@ pid = sys.argv[1] outputdir = sys.argv[2] -maps_file = open("/proc/%s/maps" % pid, "r") -mem_file = open("/proc/%s/mem" % pid, "r", 0) -for line in maps_file.readlines(): # for each mapped region - m = re.match(r"([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])", line) - if m.group(3) == "r": # if this is a readable region - start = m.group(1) - end = m.group(2) - istart = int(start, 16) - iend = int(end, 16) - mem_file.seek(istart) # seek to region start - try: - chunk = mem_file.read(iend - istart) # read region contents - # print chunk, # dump contents to standard output - print("mapping:", start, end, "read ok") - fp = open("%s/%s-%s-%s.dump" % (outputdir, pid, start, end), "w") - fp.write(chunk) - fp.close() - except: - print("mapping:", start, end, "read fail!") -maps_file.close() +with open(f"/proc/{pid}/maps", "r") as maps_file: + mem_file = open(f"/proc/{pid}/mem", "r", 0) + for line in maps_file: + m = re.match(r"([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])", line) + if m.group(3) == "r": # if this is a readable region + start = m.group(1) + end = m.group(2) + istart = int(start, 16) + iend = int(end, 16) + mem_file.seek(istart) # seek to region start + try: + chunk = mem_file.read(iend - istart) # read region contents + # print chunk, # dump contents to standard output + print("mapping:", start, end, "read ok") + with open(f"{outputdir}/{pid}-{start}-{end}.dump", "w") as fp: + fp.write(chunk) + except: + print("mapping:", start, end, "read fail!") mem_file.close() diff --git a/readtest.py b/readtest.py index eb0df39..e9ab302 100644 --- a/readtest.py +++ b/readtest.py @@ -38,9 +38,9 @@ def measure(sec_read, blocksize, filesize, fp): print("--------------------------------------------------") fp = open("/dev/sda") +sec_read = False for i in range(9, 22): blocksize = 2**i - sec_read = False dt = measure(sec_read, blocksize, READSIZE, fp) print( "Bs:%d bytes\t%s MB/s\t%d IOPs sec: %s" diff --git a/regex_test.py b/regex_test.py index 2822843..8e09885 100644 --- a/regex_test.py +++ b/regex_test.py @@ -3,14 +3,12 @@ import re import fileinput -data = "" - these_regex = "
(.+?)" pattern = re.compile(these_regex) -for line in fileinput.input(): - data += line.replace("\n", "____SEPARATOR____") - +data = "".join( + line.replace("\n", "____SEPARATOR____") for line in fileinput.input() +) ext = re.findall(pattern, data) for t in ext: diff --git a/rpn.py b/rpn.py index 4028c87..e6ad89c 100644 --- a/rpn.py +++ b/rpn.py @@ -13,25 +13,25 @@ ops = ops.split() for op in ops: stack.append(op) - if op == "+": + if op == "*": a = int(stack[-2]) b = int(stack[-3]) - r = a + b + r = a * b stack.pop() stack.pop() stack.pop() stack.append(r) print(r) - if op == "*": + elif op == "+": a = int(stack[-2]) b = int(stack[-3]) - r = a * b + r = a + b stack.pop() stack.pop() stack.pop() stack.append(r) print(r) - if op == "-": + elif op == "-": a = int(stack[-2]) b = int(stack[-3]) stack.pop() @@ -40,7 +40,7 @@ r = a - b stack.append(r) print(r) - if op == "/": + elif op == "/": a = int(stack[-2]) b = int(stack[-3]) stack.pop() diff --git a/shuffledata.py b/shuffledata.py index 5b4d729..268574b 100644 --- a/shuffledata.py +++ b/shuffledata.py @@ -10,8 +10,5 @@ def buff_shuffle(buff): return buff -data = "" -for line in fileinput.input(): - data += line - +data = "".join(fileinput.input()) print(buff_shuffle(data)) diff --git a/testQuasiLinearGCD.py b/testQuasiLinearGCD.py index a46c055..99f429b 100644 --- a/testQuasiLinearGCD.py +++ b/testQuasiLinearGCD.py @@ -79,7 +79,7 @@ def test0(n, verbose=False): print("inputs:") print(hex(p), hex(q), hex(p * q)) # we chose some arbitrary parameters with common factors to test. - k = [q * q, p * p, ((p + 1) * q), (p * (q + 1))] * n + k = [q**2, p**2, (p + 1) * q, p * (q + 1)] * n if verbose: print("pubs:") pubs = [] diff --git a/test_AES256_2.py b/test_AES256_2.py index efdb93a..7849be2 100644 --- a/test_AES256_2.py +++ b/test_AES256_2.py @@ -64,10 +64,7 @@ def test2(payload): print(passphrase) dec = decrypt(payload, passphrase) # print dec - if binascii.hexlify(sha256(dec)) == sha256_payload_check: - return dec - else: - return False + return dec if binascii.hexlify(sha256(dec)) == sha256_payload_check else False def main(): diff --git a/test_rsa.py b/test_rsa.py index 8464fb6..7814f53 100644 --- a/test_rsa.py +++ b/test_rsa.py @@ -78,8 +78,7 @@ def test(): message = decrypt(cipher, d, N) print("message_decoded:", hex(message)) print( - "Plaintext_decoded: '%s'" - % binascii.unhexlify(hex(message).replace("0x", "").replace("L", "").zfill(b)) + f"""Plaintext_decoded: '{binascii.unhexlify(hex(message).replace("0x", "").replace("L", "").zfill(b))}'""" ) diff --git a/test_rsqrt.py b/test_rsqrt.py index 03f8dcc..cf1c948 100644 --- a/test_rsqrt.py +++ b/test_rsqrt.py @@ -45,17 +45,17 @@ def test(): def benchmark(): print("benchmark") t0 = time.time() - for i in range(0, 1000000): + for _ in range(0, 1000000): tmp = math.sqrt(n) t1 = time.time() - t0 print(t1) t0 = time.time() - for i in range(0, 1000000): + for _ in range(0, 1000000): tmp = math.pow(n, -0.5) t1 = time.time() - t0 print(t1) t0 = time.time() - for i in range(0, 1000000): + for _ in range(0, 1000000): tmp = Q_rsqrt(n) t1 = time.time() - t0 print(t1) diff --git a/testpartition.py b/testpartition.py index a5932ad..0a47dbb 100644 --- a/testpartition.py +++ b/testpartition.py @@ -8,15 +8,14 @@ def split(data): def partition(n, data): - if n > 0: - tmp = [] - for dataset in data: - a, b = split(dataset) - tmp += [a] + [b] - print(tmp) - return partition(n - 1, tmp) - else: + if n <= 0: return data + tmp = [] + for dataset in data: + a, b = split(dataset) + tmp += [a] + [b] + print(tmp) + return partition(n - 1, tmp) data = [ diff --git a/testxchain.py b/testxchain.py index 678d35a..46a48cd 100644 --- a/testxchain.py +++ b/testxchain.py @@ -74,7 +74,7 @@ def _get_next_item(s): for line in fileinput.input(): addr = line.rstrip() - url = "https://xchain.io/api/balances/%s" % addr + url = f"https://xchain.io/api/balances/{addr}" raw_html = download_page(url) if raw_html != '{"error":"Address not found"}': print(addr, raw_html)