-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1
base: master
Are you sure you want to change the base?
Conversation
|
||
# logout to prevent stale sessions | ||
print(f'Logging out of firewall') | ||
print('Logging out of firewall') | ||
f.get(f'https://{args.firewall}/logout', verify=False, timeout=10) | ||
|
||
# format the data | ||
if 'results' not in data: | ||
print('Firewall returned no results') | ||
sys.exit(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 main
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
) - Use
with
when opening file to ensure closure (ensure-file-closed
)
if header == 'ipv4_addresses': # parse list, extract ip mask for each item within the field | ||
for x in row[header]: | ||
for x in row[header]: | ||
if header == 'ipv4_addresses': # parse list, extract ip mask for each item within the field | ||
subitems.append(f"{x['ip']}/{x['cidr_netmask']}") | ||
else: # parse list, extract q_origin_key for each item within the field | ||
for x in row[header]: | ||
if address_lookup and x['q_origin_key'] in address_lookup: | ||
subitems.append(address_lookup[x['q_origin_key']]) | ||
else: | ||
subitems.append(x['q_origin_key']) | ||
elif address_lookup and x['q_origin_key'] in address_lookup: | ||
subitems.append(address_lookup[x['q_origin_key']]) | ||
else: | ||
subitems.append(x['q_origin_key']) | ||
# join with a space, can't use comma due to csv | ||
row_data.append(' '.join(map(str, subitems))) | ||
row_data.append(' '.join(map(str, subitems))) | ||
elif type(row[header]) == str: | ||
row_data.append(row[header].replace(",", "")) | ||
elif address_lookup and row[header] in address_lookup: | ||
subitems.append(address_lookup[row[header]]) | ||
else: | ||
# this field is just a string/int, simply add it to the row | ||
if type(row[header]) == str: | ||
row_data.append(row[header].replace(",", "")) | ||
else: | ||
if address_lookup and row[header] in address_lookup: | ||
subitems.append(address_lookup[row[header]]) | ||
else: | ||
row_data.append(row[header]) | ||
row_data.append(row[header]) |
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 build_csv
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Hoist for/while loops out of nested conditionals (
hoist-loop-from-if
)
This removes the following comments ( why? ):
# parse list, extract q_origin_key for each item within the field
# this field is just a string/int, simply add it to the row
session.post(f'https://{host}/logindisclaimer', | ||
data=f'confirm=1&redir=/ng', | ||
session.post( | ||
f'https://{host}/logindisclaimer', | ||
data='confirm=1&redir=/ng', | ||
verify=False, | ||
timeout=10) | ||
timeout=10, | ||
) | ||
|
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 f_login
refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 1.39%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
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!