-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #4
Conversation
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function enter_region
refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable
)
print("recv:" + ssl_sock.recv(512)) | ||
print(f"recv:{ssl_sock.recv(512)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 33-33
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
i = list(difflib.unified_diff(s1, s2)) | ||
|
||
if len(i) > 0: | ||
if i := list(difflib.unified_diff(s1, s2)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 34-36
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Simplify sequence length comparison (
simplify-len-comparison
)
os.system("cat %s | gpg --decrypt > %s" % (sys.argv[1], tmp)) | ||
os.system(f"cat {sys.argv[1]} | gpg --decrypt > {tmp}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 15-25
refactored with the following changes:
- Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring
)
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." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 36-55
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
ftp.storlines("STOR %s" % filename, open(filename, "r")) | ||
ftp.storlines(f"STOR {filename}", open(filename, "r")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function upload
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
a.append("sha3_256") | ||
a.append("sha3_512") | ||
a.extend(("sha3_256", "sha3_512")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 10-11
refactored with the following changes:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
)
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"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 21-42
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Use f-string instead of string concatenation [×14] (
use-fstring-for-concatenation
) - Remove unnecessary call to
str()
withinprint()
(remove-str-from-print
)
for i in range(0, 365): | ||
for _ in range(0, 365): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function calculate_best_candidate
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
tmp = [x for x in range(1024 * 1024 * 20)] | ||
tmp = list(range(1024 * 1024 * 20)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test
refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension
)
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace unused for index with underscore [×5] (
for-index-underscore
)
for line in maps_file.readlines(): | ||
for line in maps_file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 11-11
refactored with the following changes:
- Iterate over files directly rather than using readlines() (
use-file-iterator
)
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 30-45
refactored with the following changes:
- Simplify conditional into switch-like form [×4] (
switch
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Convert for loop into list comprehension (
list-comprehension
)
data = get_json(fp, line.replace("\n", "")) | ||
if data: | ||
if data := get_json(fp, line.replace("\n", "")): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 31-32
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
)
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])}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 14-36
refactored with the following changes:
- Replace interpolated string formatting with f-string [×6] (
replace-interpolation-with-fstring
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test2
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
"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))}'""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function test
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function benchmark
refactored with the following changes:
- Replace unused for index with underscore [×3] (
for-index-underscore
)
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function partition
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
url = "https://xchain.io/api/balances/%s" % addr | ||
url = f"https://xchain.io/api/balances/{addr}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 77-77
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
Branch
master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run:Help us improve this pull request!