euscan-ng/pym/euscan/handlers/__init__.py
volpino 8e08b6a33b euscan: handlers now use a Package object instead of cpv
Signed-off-by: volpino <fox91@anche.no>
2012-07-24 08:56:00 +02:00

36 lines
859 B
Python

import pkgutil
# 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
)
def find_best_handler(pkg, url):
for handler in handlers:
if handler.can_handle(pkg, url):
return handler
return None
def scan(pkg, url):
handler = find_best_handler(pkg, url)
if handler:
return handler.scan(pkg, url)
return []
def brute_force(pkg, url):
handler = find_best_handler(pkg, url)
if handler:
return handler.brute_force(pkg, url)
return []