-
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 Starbot ⭐ refactored TonyJabbour/ail-framework #2
base: master
Are you sure you want to change the base?
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.
Sourcery timed out performing refactorings.
Due to GitHub API limits, only the first 60 comments can be shown.
iban_numb_check = iban_number(iban[:2] + '00' + iban[4:]) | ||
iban_numb_check = iban_number(f'{iban[:2]}00{iban[4:]}') |
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 is_valid_iban
refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
print('checking '+iban) | ||
print(f'checking {iban}') | ||
if is_valid_iban(iban): | ||
print('------') | ||
nb_valid_iban = nb_valid_iban + 1 | ||
server_statistics.hincrby('iban_by_country:'+date, iban[0:2], 1) | ||
server_statistics.hincrby(f'iban_by_country:{date}', iban[:2], 1) | ||
|
||
if(nb_valid_iban > 0): | ||
to_print = 'Iban;{};{};{};'.format(Item.get_source(obj_id), Item.get_item_date(obj_id), Item.get_basename(obj_id)) | ||
publisher.warning('{}Checked found {} IBAN;{}'.format( | ||
to_print, nb_valid_iban, obj_id)) | ||
msg = 'infoleak:automatic-detection="iban";{}'.format(obj_id) | ||
if (nb_valid_iban > 0): | ||
to_print = f'Iban;{Item.get_source(obj_id)};{Item.get_item_date(obj_id)};{Item.get_basename(obj_id)};' | ||
|
||
publisher.warning(f'{to_print}Checked found {nb_valid_iban} IBAN;{obj_id}') | ||
msg = f'infoleak:automatic-detection="iban";{obj_id}' |
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_all_iban
refactored with the following changes:
- 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
) - Replace call to format with f-string [×3] (
use-fstring-for-formatting
)
with open(os.environ['AIL_BIN']+'/torcrawler/blacklist_{}.txt'.format(service_type), 'r') as f: | ||
redis_crawler.delete('blacklist_{}'.format(service_type)) | ||
with open(os.environ['AIL_BIN'] + f'/torcrawler/blacklist_{service_type}.txt', 'r') as f: | ||
redis_crawler.delete(f'blacklist_{service_type}') | ||
lines = f.read().splitlines() | ||
for line in lines: | ||
redis_crawler.sadd('blacklist_{}'.format(service_type), line) | ||
redis_crawler.sadd(f'blacklist_{service_type}', line) |
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 load_blacklist
refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting
)
redis_crawler.sadd('{}_crawler_priority_queue'.format(type), mess) | ||
redis_crawler.sadd(f'{type}_crawler_priority_queue', mess) |
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 update_auto_crawler
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
url= 'http://{}'.format(url_lower_case) | ||
url = f'http://{url_lower_case}' |
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 unpack_url
refactored with the following changes:
- Replace call to format with f-string [×5] (
use-fstring-for-formatting
)
f = open(dump_file, 'a') | ||
while message is not None: | ||
print(message) | ||
date = datetime.datetime.now() | ||
if message is not None: | ||
f.write(date.isoformat() + ' ' + message + '\n') | ||
else: | ||
break | ||
message = p.get_from_set() | ||
f.close() | ||
with open(dump_file, 'a') as f: | ||
while message is not None: | ||
print(message) | ||
date = datetime.datetime.now() | ||
if message is not None: | ||
f.write(f'{date.isoformat()} {message}' + '\n') | ||
else: | ||
break | ||
message = p.get_from_set() |
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 24-33
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
p.send('{} {}'.format(channel, m['message'])) | ||
p.send(f"{channel} {m['message']}") |
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 PubSub.publish
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
in_set = self.subscriber_name + 'in' | ||
in_set = f'{self.subscriber_name}in' | ||
self.r_temp.sadd(in_set, msg) | ||
self.r_temp.hset('queues', self.subscriber_name, | ||
int(self.r_temp.scard(in_set))) | ||
else: | ||
print('{} has no subscriber'.format(self.subscriber_name)) | ||
print(f'{self.subscriber_name} has no subscriber') |
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 Process.populate_set_in
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace call to format with f-string (
use-fstring-for-formatting
)
in_set = self.subscriber_name + 'in' | ||
in_set = f'{self.subscriber_name}in' |
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 Process.get_from_set
refactored with the following changes:
- Use f-string instead of string concatenation [×22] (
use-fstring-for-concatenation
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
) - Replace if statement with if expression (
assign-if-exp
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
) - Remove unnecessary calls to
str()
from formatted values in f-strings [×2] (remove-str-from-fstring
)
msg.update({'channel': channel}) | ||
msg['channel'] = channel | ||
|
||
# bytes64 encode bytes to ascii only bytes | ||
j = json.dumps(msg) | ||
self.r_temp.sadd(self.subscriber_name + 'out', j) | ||
self.r_temp.sadd(f'{self.subscriber_name}out', j) |
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 Process.populate_set_out
refactored with the following changes:
- Add single value to dictionary directly rather than using update() (
simplify-dictionary-update
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
message = self.r_temp.spop(self.subscriber_name + 'out') | ||
message = self.r_temp.spop(f'{self.subscriber_name}out') |
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 Process.publish
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
self.serv_statistics.hincrby(curr_date.strftime("%Y%m%d"),'paste_by_modules_timeout:'+self.subscriber_name, 1) | ||
self.serv_statistics.hincrby( | ||
curr_date.strftime("%Y%m%d"), | ||
f'paste_by_modules_timeout:{self.subscriber_name}', | ||
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 Process.incr_module_timeout_statistic
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
for network in ip_networks: | ||
if address in network: | ||
matching_ips.append(address) | ||
|
||
if len(matching_ips) > 0: | ||
print('{} contains {} IPs'.format(paste.p_name, len(matching_ips))) | ||
publisher.warning('{} contains {} IPs'.format(paste.p_name, len(matching_ips))) | ||
matching_ips.extend(address for network in ip_networks if address in network) | ||
if matching_ips: | ||
print(f'{paste.p_name} contains {len(matching_ips)} IPs') | ||
publisher.warning(f'{paste.p_name} contains {len(matching_ips)} IPs') | ||
|
||
#Tag message with IP | ||
msg = 'infoleak:automatic-detection="ip";{}'.format(message) | ||
msg = f'infoleak:automatic-detection="ip";{message}' |
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 search_ip
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
) - Simplify sequence length comparison (
simplify-len-comparison
) - Replace call to format with f-string [×3] (
use-fstring-for-formatting
)
publisher.debug("{} queue is empty, waiting".format(config_section)) | ||
publisher.debug(f"{config_section} queue is empty, waiting") |
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 86-86
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
publisher.debug("{} queue is empty, waiting".format(config_section)) | ||
publisher.debug(f"{config_section} queue is empty, waiting") |
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-25
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
redis_progression_name_set = 'top_'+ module +'_set_' + paste_date | ||
redis_progression_name_set = f'top_{module}_set_{paste_date}' | ||
|
||
# Add/Update in Redis | ||
self.r_serv_trend.hincrby(paste_date, module+'-'+keyword, int(num)) | ||
self.r_serv_trend.hincrby(paste_date, f'{module}-{keyword}', int(num)) | ||
|
||
# Compute Most Posted | ||
date = self.get_date_range(0)[0] | ||
# check if this keyword is eligible for progression | ||
keyword_total_sum = 0 | ||
|
||
curr_value = self.r_serv_trend.hget(date, module+'-'+keyword) | ||
keyword_total_sum += int(curr_value) if curr_value is not None else 0 | ||
|
||
curr_value = self.r_serv_trend.hget(date, f'{module}-{keyword}') | ||
keyword_total_sum = 0 + (int(curr_value) if curr_value is not None 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.
Function ModuleStats.compute_most_posted
refactored with the following changes:
- Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign
) - Use f-string instead of string concatenation [×16] (
use-fstring-for-concatenation
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
This removes the following comments ( why? ):
# check if this keyword is eligible for progression
redis_sum_size_set = 'top_size_set_' + paste_date | ||
redis_avg_size_name_set = 'top_avg_size_set_' + paste_date | ||
redis_providers_name_set = 'providers_set_' + paste_date | ||
redis_sum_size_set = f'top_size_set_{paste_date}' | ||
redis_avg_size_name_set = f'top_avg_size_set_{paste_date}' | ||
redis_providers_name_set = f'providers_set_{paste_date}' | ||
|
||
# Add/Update in Redis | ||
self.r_serv_trend.sadd(redis_all_provider, paste_provider) | ||
|
||
num_paste = int(self.r_serv_trend.hincrby(paste_provider+'_num', paste_date, 1)) | ||
sum_size = float(self.r_serv_trend.hincrbyfloat(paste_provider+'_size', paste_date, paste_size)) | ||
new_avg = float(sum_size) / float(num_paste) | ||
self.r_serv_trend.hset(paste_provider +'_avg', paste_date, new_avg) | ||
num_paste = int( | ||
self.r_serv_trend.hincrby(f'{paste_provider}_num', paste_date, 1) | ||
) | ||
|
||
sum_size = float( | ||
self.r_serv_trend.hincrbyfloat( | ||
f'{paste_provider}_size', paste_date, paste_size | ||
) | ||
) | ||
|
||
new_avg = sum_size / float(num_paste) | ||
self.r_serv_trend.hset(f'{paste_provider}_avg', paste_date, new_avg) |
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 ModuleStats.compute_provider_info
refactored with the following changes:
- Use f-string instead of string concatenation [×22] (
use-fstring-for-concatenation
) - Remove unnecessary casts to int, str, float or bool [×2] (
remove-unnecessary-cast
) - Remove unnecessary calls to
str()
from formatted values in f-strings (remove-str-from-fstring
)
if event.buttons != 0: | ||
if (len(self._options) > 0 and | ||
self.is_mouse_over(new_event, include_label=False)): | ||
# Use property to trigger events. | ||
self._line = min(new_event.y - self._y, | ||
len(self._options) - 1) | ||
self.value = self._options[self._line][1] | ||
# If clicked on button <k>, kill the queue | ||
if self._x+2 <= new_event.x < self._x+4: | ||
if self.queue_name in ["running", "idle"]: | ||
kill_module(PID_NAME_DICO[int(self.value)], self.value) | ||
else: | ||
restart_module(self.value) | ||
|
||
return | ||
if event.buttons != 0 and ( | ||
len(self._options) > 0 | ||
and self.is_mouse_over(new_event, include_label=False) | ||
): | ||
# Use property to trigger events. | ||
self._line = min(new_event.y - self._y, | ||
len(self._options) - 1) | ||
self.value = self._options[self._line][1] | ||
# If clicked on button <k>, kill the queue | ||
if self._x+2 <= new_event.x < self._x+4: | ||
if self.queue_name in ["running", "idle"]: | ||
kill_module(PID_NAME_DICO[int(self.value)], self.value) | ||
else: | ||
restart_module(self.value) | ||
|
||
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 CListBox.process_event
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
)
self._x += max(0, (self._w - self._offset - len(self._text)) // 2) if not self.listTitle else 0 | ||
self._x += ( | ||
0 | ||
if self.listTitle | ||
else max(0, (self._w - self._offset - len(self._text)) // 2) | ||
) | ||
|
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 CLabel.set_layout
refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression
)
colour = Screen.COLOUR_YELLOW if not self.listTitle else colour | ||
colour = colour if self.listTitle else Screen.COLOUR_YELLOW |
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 CLabel.update
refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression
)
action = current_selected_action if current_selected_action == "KILL" else current_selected_action +" "+ str(current_selected_amount) + "x" | ||
action = ( | ||
current_selected_action | ||
if current_selected_action == "KILL" | ||
else f"{current_selected_action} {str(current_selected_amount)}x" | ||
) | ||
|
||
modulename = PID_NAME_DICO[int(current_selected_value)] | ||
pid = current_selected_value | ||
else: | ||
action = current_selected_action + " " + str(current_selected_amount) + "x" | ||
action = f"{current_selected_action} {str(current_selected_amount)}x" |
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 Confirm._setValue
refactored with the following changes:
- Use f-string instead of string concatenation [×6] (
use-fstring-for-concatenation
)
self.label_list += [Label("THE PASTE CONTENT " + str(i))] | ||
self.label_list += [Label(f"THE PASTE CONTENT {str(i)}")] |
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 Show_paste.__init__
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
old_content = paste.get_p_content()[0:4000] # Limit number of char to be displayed | ||
old_content = paste.get_p_content()[:4000] |
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 Show_paste._setValue
refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
) - Hoist repeated code outside conditional statement (
hoist-statement-from-if
)
This removes the following comments ( why? ):
# Limit number of char to be displayed
p = Popen([command_search_pid.format(module+".py")], stdin=PIPE, stdout=PIPE, bufsize=1, shell=True) | ||
p = Popen( | ||
[command_search_pid.format(f"{module}.py")], | ||
stdin=PIPE, | ||
stdout=PIPE, | ||
bufsize=1, | ||
shell=True, | ||
) | ||
|
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 getPid
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
moduleCommand = "./"+moduleName + ".py" | ||
moduleCommand2 = moduleName + ".py" | ||
moduleCommand = f"./{moduleName}.py" | ||
moduleCommand2 = f"{moduleName}.py" |
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 cleanRedis
refactored with the following changes:
- Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation
)
This removes the following comments ( why? ):
#Error due to resize, interrupted sys call
to_send = "{0} {1}".format(paste_name, gzip64encoded) | ||
return to_send | ||
return "{0} {1}".format(paste_name, gzip64encoded) |
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 do_something
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
publisher.debug("{} queue is empty, waiting".format(config_section)) | ||
publisher.debug(f"{config_section} queue is empty, waiting") |
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 50-50
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
if len(releases) == 0: | ||
if not releases: | ||
continue | ||
|
||
to_print = 'Release;{};{};{};{} releases;{}'.format(paste.p_source, paste.p_date, paste.p_name, len(releases), paste.p_rel_path) | ||
print(to_print) | ||
if len(releases) > 30: | ||
publisher.warning(to_print) | ||
else: | ||
publisher.info(to_print) |
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 54-62
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
) - Remove unreachable code (
remove-unreachable-code
)
if len(match_set) == 0: | ||
if not match_set: | ||
continue | ||
|
||
to_print = 'SourceCode;{};{};{};{}'.format(paste.p_source, paste.p_date, paste.p_name, message) | ||
to_print = f'SourceCode;{paste.p_source};{paste.p_date};{paste.p_name};{message}' | ||
|
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 47-50
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
) - Replace call to format with f-string (
use-fstring-for-formatting
)
regex = tool_dict['regex{}'.format(regex_index)] | ||
regex = tool_dict[f'regex{regex_index}'] |
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 search_tools
refactored with the following changes:
- Replace call to format with f-string [×8] (
use-fstring-for-formatting
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run: