X-Git-Url: https://git.distorted.org.uk/~mdw/hippotat/blobdiff_plain/300fe4ed2e3210ad3d90a8f4f5937224300691ac..b8c38e6610bd82820e028e8b38e6275bb032bee1:/hippotatlib/__init__.py diff --git a/hippotatlib/__init__.py b/hippotatlib/__init__.py index ce94a86..b06d225 100644 --- a/hippotatlib/__init__.py +++ b/hippotatlib/__init__.py @@ -126,7 +126,7 @@ class LogNotBoringTwisted: #---------- default config ---------- defcfg = ''' -[DEFAULT] +[COMMON] max_batch_down = 65536 max_queue_time = 10 target_requests_outstanding = 3 @@ -386,11 +386,20 @@ def _cfg_process_putatives(): 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]" + log_debug_config('putatives: section [%s]...' % (cs)) + + def log_ignore(why): + log_debug_config('putatives: section [%s] X ignore: %s' % (cs, why)) + print('warning: ignoring config section [%s] (%s)' % (cs, why), + file=sys.stderr) + + if cs == 'LIMIT' or cs == 'COMMON': + # plan A "[LIMIT]" or "[COMMON]" + log_debug_config('putatives: section [%s] A ignore' % (cs)) continue try: @@ -400,6 +409,7 @@ def _cfg_process_putatives(): if server_re.fullmatch(cs): # plan C "[]" + log_debug_config('putatives: section [%s] C ' % (cs)) putative(servers, cs, cs) continue @@ -409,25 +419,28 @@ def _cfg_process_putatives(): if pcs == 'LIMIT': # plan E "[ LIMIT]" + log_debug_config('putatives: section [%s] E LIMIT' % (cs)) continue try: # plan D "[ ]" part 2 - ci = ipaddr(pc) + ci = ipaddr(pcs) except AddressValueError: # plan F "[]" - # well, we ignore this - print('warning: ignoring config section %s' % cs, file=sys.stderr) + log_ignore('bad-addr') continue else: # no AddressValueError - # plan D "[ ]" part 3 + log_debug_config('putatives: section [%s] D ' + % (cs)) putative(clients, ci, pcs) putative(servers, pss, pss) continue else: # no AddressValueError # plan B "[" part 2 + log_debug_config('putatives: section [%s] B ' % (cs)) putative(clients, ci, cs) continue @@ -492,11 +505,12 @@ def cfg_search(getter,key,sections): 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) @@ -510,7 +524,7 @@ def cfg_process_client_common(cc,ss,cs,ci): sections = ['%s %s' % (ss,cs), cs, ss, - 'DEFAULT'] + 'COMMON'] try: pwsection = cfg_search_section('password', sections) except NoOptionError: return None