Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SourceryAI
Copy link

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:

git fetch https://github.com/sourcery-ai-bot/ail-framework master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@SourceryAI SourceryAI left a 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:]}')
Copy link
Author

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:

Comment on lines -60 to +70
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}'
Copy link
Author

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:

Comment on lines -29 to +33
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)
Copy link
Author

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:

redis_crawler.sadd('{}_crawler_priority_queue'.format(type), mess)
redis_crawler.sadd(f'{type}_crawler_priority_queue', mess)
Copy link
Author

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:

url= 'http://{}'.format(url_lower_case)
url = f'http://{url_lower_case}'
Copy link
Author

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:

Comment on lines -24 to +32
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()
Copy link
Author

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:

p.send('{} {}'.format(channel, m['message']))
p.send(f"{channel} {m['message']}")
Copy link
Author

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:

Comment on lines -160 to +165
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')
Copy link
Author

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:

in_set = self.subscriber_name + 'in'
in_set = f'{self.subscriber_name}in'
Copy link
Author

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:

Comment on lines -219 to +235
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)
Copy link
Author

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:

Comment on lines -234 to +246
message = self.r_temp.spop(self.subscriber_name + 'out')
message = self.r_temp.spop(f'{self.subscriber_name}out')
Copy link
Author

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:

Comment on lines -243 to +259
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,
)
Copy link
Author

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:

Comment on lines -38 to +44
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}'
Copy link
Author

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:

Comment on lines -86 to +83
publisher.debug("{} queue is empty, waiting".format(config_section))
publisher.debug(f"{config_section} queue is empty, waiting")
Copy link
Author

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:

publisher.debug("{} queue is empty, waiting".format(config_section))
publisher.debug(f"{config_section} queue is empty, waiting")
Copy link
Author

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:

Comment on lines -70 to +74
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)
Copy link
Author

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:

This removes the following comments ( why? ):

# check if this keyword is eligible for progression

Comment on lines -106 to +119
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)
Copy link
Author

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:

Comment on lines -151 to +166
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
Copy link
Author

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:

Comment on lines -187 to +193
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)
)

Copy link
Author

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:

Comment on lines -192 to +198
colour = Screen.COLOUR_YELLOW if not self.listTitle else colour
colour = colour if self.listTitle else Screen.COLOUR_YELLOW
Copy link
Author

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:

Comment on lines -318 to +333
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"
Copy link
Author

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:

Comment on lines -421 to +432
self.label_list += [Label("THE PASTE CONTENT " + str(i))]
self.label_list += [Label(f"THE PASTE CONTENT {str(i)}")]
Copy link
Author

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:

Comment on lines -447 to +458
old_content = paste.get_p_content()[0:4000] # Limit number of char to be displayed
old_content = paste.get_p_content()[:4000]
Copy link
Author

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:

This removes the following comments ( why? ):

# Limit number of char to be displayed

Comment on lines -504 to +523
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,
)

Copy link
Author

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:

Comment on lines -528 to +548
moduleCommand = "./"+moduleName + ".py"
moduleCommand2 = moduleName + ".py"
moduleCommand = f"./{moduleName}.py"
moduleCommand2 = f"{moduleName}.py"
Copy link
Author

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:

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)
Copy link
Author

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:

Comment on lines -50 to +49
publisher.debug("{} queue is empty, waiting".format(config_section))
publisher.debug(f"{config_section} queue is empty, waiting")
Copy link
Author

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:

Comment on lines -54 to -62
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)
Copy link
Author

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:

Comment on lines -47 to +51
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}'

Copy link
Author

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:

regex = tool_dict['regex{}'.format(regex_index)]
regex = tool_dict[f'regex{regex_index}']
Copy link
Author

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant