Skip to content

Commit

Permalink
Merge 849e48b into bb51e3e
Browse files Browse the repository at this point in the history
  • Loading branch information
R4H33M committed Oct 8, 2019
2 parents bb51e3e + 849e48b commit 19aa9fb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pastepwn/core/pastepwn.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(self, database=None, proxies=None, store_all_pastes=True):
self.paste_queue = Queue()
self.action_queue = Queue()
self.error_handlers = list()
self.onstart_handlers = list()
self.__exception_event = Event()
self.__request = Request(proxies) # initialize singleton

Expand Down Expand Up @@ -89,6 +90,13 @@ def add_error_handler(self, error_handler):

self.error_handlers.append(error_handler)

def add_onstart_handler(self, onstart_handler):
if not callable(onstart_handler):
self.logger.error("The onstart handler you passed is not a function!")
return

self.onstart_handlers.append(onstart_handler)

def start(self):
"""Starts the pastepwn instance"""
if self.__exception_event.is_set():
Expand All @@ -102,6 +110,12 @@ def start(self):
self.paste_dispatcher.start()
self.action_handler.start()

for onstart_handler in self.onstart_handlers:
try:
onstart_handler()
except Exception as e:
self.logger.error("Onstart hander %s failed with error: %s. Pastepwn is still running." % (onstart_handler.__name__, e))

def stop(self):
"""Stops the pastepwn instance"""
self.scraping_handler.stop()
Expand Down

0 comments on commit 19aa9fb

Please sign in to comment.