#---------- default config ----------
defcfg = '''
-[DEFAULT]
+[COMMON]
max_batch_down = 65536
max_queue_time = 10
target_requests_outstanding = 3
server_pat = r'[-.0-9A-Za-z]+'
client_pat = r'[.:0-9a-f]+'
server_re = regexp.compile(server_pat)
- serverclient_re = regexp.compile(server_pat + r' ' + client_pat)
+ serverclient_re = regexp.compile(
+ server_pat + r' ' + '(?:' + client_pat + '|LIMIT)')
for cs in cfg.sections():
- if cs == 'LIMIT':
- # plan A "[LIMIT]"
+ def dbg(m):
+ log_debug_config('putatives: section [%s] %s' % (cs, m))
+
+ def log_ignore(why):
+ dbg('X ignore: %s' % (why))
+ print('warning: ignoring config section [%s] (%s)' % (cs, why),
+ file=sys.stderr)
+
+ if cs == 'LIMIT' or cs == 'COMMON':
+ # plan A "[LIMIT]" or "[COMMON]"
+ dbg('A ignore')
continue
try:
if server_re.fullmatch(cs):
# plan C "[<servername>]"
+ dbg('C <server>')
putative(servers, cs, cs)
continue
if pcs == 'LIMIT':
# plan E "[<servername> LIMIT]"
+ dbg('E <server> LIMIT')
continue
try:
# plan D "[<servername> <client>]" part 2
- ci = ipaddr(pc)
+ ci = ipaddr(pcs)
except AddressValueError:
- # plan F "[<some thing we do not understand>]"
- # well, we ignore this
- print('warning: ignoring config section %s' % cs, file=sys.stderr)
+ # plan F branch 1 "[<some thing we do not understand>]"
+ log_ignore('bad-addr')
continue
else: # no AddressValueError
- # plan D "[<servername> <client]" part 3
+ # plan D "[<servername> <client>]" part 3
+ dbg('D <server> <client>')
putative(clients, ci, pcs)
putative(servers, pss, pss)
continue
+ else:
+ # plan F branch 2 "[<some thing we do not understand>]"
+ log_ignore('nomatch '+ repr(serverclient_re))
else: # no AddressValueError
# plan B "[<client>" part 2
+ dbg('B <client>')
putative(clients, ci, cs)
continue
section = cfg_search_section(key,sections)
return getter(section, key)
-def cfg1get(*args, **kwargs):
- return cfg.get(*args, **kwargs)
+def cfg1get(section,key, getter=cfg.get,**kwargs):
+ section = cfg_search_section(key,[section,'COMMON'])
+ return getter(section,key,**kwargs)
-def cfg1getint(*args, **kwargs):
- return cfg.getint(*args, **kwargs)
+def cfg1getint(section,key, **kwargs):
+ return cfg1get(section,key, getter=cfg.getint,**kwargs);
def cfg_process_client_limited(cc,ss,sections,key):
val = cfg_search(cfg1getint, key, sections)
sections = ['%s %s' % (ss,cs),
cs,
ss,
- 'DEFAULT']
+ 'COMMON']
try: pwsection = cfg_search_section('password', sections)
except NoOptionError: return None