mirror of
https://github.com/mirror/wget.git
synced 2025-01-18 08:10:42 +08:00
8b83306d54
This is a squashed commit of the following from parallel-wget:ecd6977
Refactor mainly the test cases classesd26c8eb
Create package test for test case classes507383d
Move server classes to package server.protocol195393b
Create package conf where rules and hooks are put42e482a
Create package exc and move TestFailed to exc82f44f3
Fix a typo in Test-Proto.py31e5f33
From WgetTest.py move WgetFile to misc422171d
Create package misc, move ColourTerm.py to misc
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
import os
|
|
|
|
# this file implements the mechanism of conf class auto-registration,
|
|
# don't modify this file if you have no idea what you're doing
|
|
|
|
def gen_hook():
|
|
hook_table = {}
|
|
|
|
class Wrapper:
|
|
"""
|
|
Decorator class which implements the conf class registration.
|
|
"""
|
|
def __init__(self, alias=None):
|
|
self.alias = alias
|
|
|
|
def __call__(self, cls):
|
|
# register the class object with the name of the class
|
|
hook_table[cls.__name__] = cls
|
|
if self.alias:
|
|
# also register the alias of the class
|
|
hook_table[self.alias] = cls
|
|
|
|
return cls
|
|
|
|
def find_hook(name):
|
|
if name in hook_table:
|
|
return hook_table[name]
|
|
else:
|
|
raise AttributeError
|
|
|
|
return Wrapper, find_hook
|
|
|
|
_register, find_conf = gen_hook()
|
|
hook = rule = _register
|
|
|
|
__all__ = ['hook', 'rule']
|
|
|
|
for module in os.listdir(os.path.dirname(__file__)):
|
|
# import every module under this package except __init__.py,
|
|
# so that the decorator `register` applies
|
|
# (nothing happens if the script is not loaded)
|
|
if module != '__init__.py' and module.endswith('.py'):
|
|
module_name = module[:-3]
|
|
mod = __import__('%s.%s' % (__name__, module_name),
|
|
globals(),
|
|
locals())
|
|
__all__.append(module_name)
|