2012-06-28 11:08:05 +02:00
|
|
|
import pkgutil
|
2011-08-31 15:38:32 +02:00
|
|
|
|
2012-06-28 11:08:05 +02:00
|
|
|
# autoimport all modules in this directory and append them to handlers list
|
|
|
|
handlers = []
|
|
|
|
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
|
|
|
module = loader.find_module(module_name).load_module(module_name)
|
|
|
|
handlers.append(module)
|
|
|
|
|
|
|
|
# sort handlers by priority (e.g.: generic should be run lastly)
|
|
|
|
handlers = sorted(
|
|
|
|
handlers,
|
|
|
|
key=lambda handler: handler.PRIORITY,
|
|
|
|
reverse=True
|
|
|
|
)
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
|
|
|
|
def find_best_handler(cpv, url):
|
|
|
|
for handler in handlers:
|
|
|
|
if handler.can_handle(cpv, url):
|
|
|
|
return handler
|
|
|
|
return None
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
def scan(cpv, url):
|
|
|
|
handler = find_best_handler(cpv, url)
|
|
|
|
if handler:
|
|
|
|
return handler.scan(cpv, url)
|
|
|
|
return []
|
|
|
|
|
2012-04-28 18:16:05 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
def brute_force(cpv, url):
|
|
|
|
handler = find_best_handler(cpv, url)
|
|
|
|
if handler:
|
|
|
|
return handler.brute_force(cpv, url)
|
|
|
|
return []
|