-
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 #2
Conversation
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.
Due to GitHub API limits, only the first 60 comments can be shown.
interested = [] | ||
interested.append(False) | ||
interested.append(False) | ||
interested = [False, 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.
Lines 7-9
refactored with the following changes:
- Merge append into list declaration [×2] (
merge-list-append
)
t = int(random.randint(0, 1)) | ||
t = random.randint(0, 1) |
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 proc
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
opener.addheaders.append(("Content-Type", "text/html;" + buff)) | ||
opener.addheaders.append(("Content-Type", f"text/html;{buff}")) | ||
else: | ||
opener.addheaders.append(("Content-Type", "text/html;")) | ||
|
||
data = opener.open(url).read() | ||
|
||
return data | ||
return opener.open(url).read() |
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 check_url
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
E = 0xFF | ||
F = 0xFF | ||
G = 0xFF | ||
H = 0xFF | ||
|
||
if l > 4: | ||
E = 0x30 + int(N[4]) | ||
if l > 5: | ||
F = 0x30 + int(N[5]) | ||
if l > 6: | ||
G = 0x30 + int(N[6]) | ||
if l > 7: | ||
H = 0x30 + int(N[7]) | ||
|
||
COMM = [ | ||
E = 0x30 + int(N[4]) if l > 4 else 0xFF | ||
F = 0x30 + int(N[5]) if l > 5 else 0xFF | ||
G = 0x30 + int(N[6]) if l > 6 else 0xFF | ||
H = 0x30 + int(N[7]) if l > 7 else 0xFF | ||
return [ |
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 Attack.encode_pin_cmd
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Move assignment closer to its usage within a block [×4] (
move-assign-in-block
) - Move setting of default value for variable into
else
branch [×4] (introduce-default-else
) - Replace if statement with if expression [×4] (
assign-if-exp
)
This removes the following comments ( why? ):
# APDU with command pkt
if args.startpin: | ||
# n= 00274710 | ||
n = int(args.startpin) | ||
else: | ||
n = 0 | ||
|
||
n = int(args.startpin) if args.startpin else 0 |
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 189-194
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
This removes the following comments ( why? ):
# n= 00274710
data = "" | ||
addrs = [] | ||
|
||
for line in f: | ||
data += line | ||
|
||
data = "".join(f) |
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 getinputs
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Simplify generator expression (
simplify-generator
) - Use str.join() instead of for loop (
use-join
)
fp = open(f, "r") | ||
d = fp.read() | ||
fp.close() | ||
with open(f, "r") as fp: | ||
d = fp.read() |
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 loadfile
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
fp = open(f, "w") | ||
fp.write(data) | ||
fp.close() | ||
with open(f, "w") as fp: | ||
fp.write(data) |
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 savefile
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
json_data = str(json.dumps(s)) | ||
json_data = json.dumps(s) |
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 json2file
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
old_nm = file2json(".check_nmap.py." + host + ".cache") | ||
old_nm = file2json(f".check_nmap.py.{host}.cache") |
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 getold_nm
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
output0 += "tcp %s: %s," % (port, b) | ||
output0 += f"tcp {port}: {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 proc_results
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
while len(s) == 0: | ||
while not s: |
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 48-48
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
data = "" | ||
for line in fileinput.input(): | ||
data += line | ||
|
||
data = "".join(fileinput.input()) |
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 85-88
refactored with the following changes:
- Use str.join() instead of for loop (
use-join
) - Simplify generator expression (
simplify-generator
)
tmp = 0 | ||
for i in range(0, len(s) - 1): | ||
if s[i] == "1": | ||
tmp += 1 | ||
return tmp | ||
return sum(1 for i in range(0, len(s) - 1) if s[i] == "1") |
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 count_ones
refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i in d[k]: | ||
data.append(i) | ||
|
||
data.extend(iter(d[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.
Lines 29-31
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
) - Simplify generator expression (
simplify-generator
)
print("Factodb: " + str(r)) | ||
print(f"Factodb: {str(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 send2db
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
data=[] | ||
#fp=open(sys.argv[1]) | ||
for line in fileinput.input(): | ||
data.append(line.rstrip()) | ||
data = [line.rstrip() for line in fileinput.input()] |
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 25-28
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
This removes the following comments ( why? ):
#fp=open(sys.argv[1])
if len(sys.argv)>3: | ||
fp_dump = open(sys.argv[3],'w') | ||
else: | ||
fp_dump = None | ||
|
||
fp_dump = open(sys.argv[3],'w') if len(sys.argv)>3 else None |
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 37-41
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
ipaddr = str(a) + "." + str(b) + "." + str(c) + "." + str(d) | ||
ipaddr = f"{str(a)}.{str(b)}.{str(c)}.{str(d)}" |
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 39-39
refactored with the following changes:
- Use f-string instead of string concatenation [×6] (
use-fstring-for-concatenation
)
dt = t2 - t1 | ||
return dt | ||
return t2 - t1 |
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 measure
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if big_endian: | ||
return struct.pack(">I", value) | ||
else: | ||
return struct.pack("<I", value) | ||
return struct.pack(">I", value) if big_endian else struct.pack("<I", value) |
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 uint32tobytes
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
if big_endian: | ||
return struct.pack(">i", value) | ||
else: | ||
return struct.pack("<i", value) | ||
return struct.pack(">i", value) if big_endian else struct.pack("<i", value) |
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 int32tobytes
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
# Feriados en Uruguay | ||
holidays = [ # feriados no laborables | ||
return [ # feriados no laborables | ||
date(year=year, month=1, day=1), # dia del transportista | ||
date(year=year, month=5, day=1), # dia de los trabajadores | ||
date(year=year, month=7, day=18), # dia de la independencia | ||
date(year=year, month=8, day=25), # dia de la declaratoria de la independencia | ||
date( | ||
year=year, month=8, day=25 | ||
), # dia de la declaratoria de la independencia |
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 init_holidays
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# Feriados en Uruguay
d = s2 - s1 | ||
return d | ||
return s2 - s1 |
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i in xrange(imin, imax): | ||
for _ in xrange(imin, imax): |
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 seek
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
for i in range(MAX_STRETCH): | ||
for _ in range(MAX_STRETCH): |
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 stretch_password
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
h = "0" + h | ||
h = f"0{h}" |
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 inttobin
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
l = len(plaintext) | ||
n=0 | ||
cont = True | ||
while cont: | ||
a = bintoint(plaintext + (" "*n)) | ||
b = gmpy2.isqrt(a) | ||
c = b**2 | ||
tmp = inttobin(c) | ||
n+=1 | ||
cont = not (tmp[0:l] == plaintext) | ||
return b,n | ||
l = len(plaintext) | ||
n=0 | ||
cont = True | ||
while cont: | ||
a = bintoint(plaintext + (" "*n)) | ||
b = gmpy2.isqrt(a) | ||
c = b**2 | ||
tmp = inttobin(c) | ||
n+=1 | ||
cont = tmp[:l] != plaintext | ||
return b,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.
Function crypt
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
print(hostname + ":" + str(port)) | ||
print(f"{hostname}:{str(port)}") | ||
try: | ||
pem = ssl.get_server_certificate((hostname, port)) | ||
if pem != None: | ||
print(pem) | ||
fp = open("output/%s_%d.pem" % (hostname, port), "w") | ||
fp.write(pem + "\n") | ||
fp.close() | ||
with open("output/%s_%d.pem" % (hostname, port), "w") as fp: | ||
fp.write(pem + "\n") | ||
except: | ||
print(hostname + " error") | ||
print(f"{hostname} error") |
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 16-25
refactored with the following changes:
- Use f-string instead of string concatenation [×3] (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
)
tmp = "" | ||
for byte in val: | ||
tmp += bin(ord(byte)).replace("0b", "") | ||
return "0b" + tmp.zfill(32) | ||
tmp = "".join(bin(ord(byte)).replace("0b", "") for byte in val) | ||
return f"0b{tmp.zfill(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.
Function bitrepr32
refactored with the following changes:
- Use str.join() instead of for loop (
use-join
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
e794b29
to
abd98be
Compare
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!