def P_config(self, request): """ Request handler for the `config` endpoint. Args: request (twisted.web.server.Request): HTTP request object Returns: HTTP response with headers """ section = "usage" if "section" in request.args.keys(): section = request.args["section"][0] return getConfigs(section)
def P_config(self, request): def RepresentsInt(s): try: int(s) return True except ValueError: return False setcs = getConfigsSections() if request.path == '/api/config': return setcs else: try: sect = request.path.split('/') if len(sect) == 4: cfgs = getConfigs(sect[3]) resultcfgs = [] for cfg in cfgs['configs']: min = -1 kv=[] data = cfg['data'] if data.has_key('choices'): for ch in data['choices']: if type(ch).__name__ == 'tuple' and len(ch)==2 and ch[0] == ch[1]: if RepresentsInt(ch[0]): kv.append(int(ch[0])) else: kv=[] break else: kv=[] break if len(kv) > 1: if kv[1] == (kv[0]+1): min = kv[0] max = kv[len(kv)-1] if min > -1: data['min'] = min data['max'] = max del data['choices'] cfg['data'] = data resultcfgs.append(cfg) else: resultcfgs.append(cfg) return { 'configs' : resultcfgs } except Exception, e: #TODO show exception pass
def P_config(self, request): def RepresentsInt(s): try: int(s) return True except ValueError: return False setcs = getConfigsSections() if request.path == '/api/config': return setcs else: try: sect = request.path.split('/') if len(sect) == 4: cfgs = getConfigs(sect[3]) resultcfgs = [] for cfg in cfgs['configs']: min = -1 kv=[] data = cfg['data'] if data.has_key('choices'): for ch in data['choices']: if type(ch).__name__ == 'tuple' and len(ch)==2 and ch[0] == ch[1]: if RepresentsInt(ch[0]): kv.append(int(ch[0])) else: kv=[] break else: kv=[] break if len(kv) > 1: if kv[1] == (kv[0]+1): min = kv[0] max = kv[len(kv)-1] if min > -1: data['min'] = min data['max'] = max del data['choices'] cfg['data'] = data resultcfgs.append(cfg) else: resultcfgs.append(cfg) return { 'configs' : resultcfgs } except Exception, e: #TODO show exception pass
def P_config(self, request): section = "usage" if "section" in request.args.keys(): section = request.args["section"][0] return getConfigs(section)
def P_config(self, request): section = "usage" if "section" in request.args.keys(): section = request.args["section"][0] return getConfigs(section)