comparison MoinMoin/wikiutil.py @ 2455:fe71235f1f7c

ParameterParser: changed to return fixed_count, arg_dict, putting positional args into arg_dict[pos], more tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 21 Jul 2007 23:00:25 +0200
parents adf5ec4874ed
children 15502589ece6
comparison
equal deleted inserted replaced
2454:18c71299e2bb 2455:fe71235f1f7c
1357 parameter_dict = dict([(key, None) for key in self.param_dict]) 1357 parameter_dict = dict([(key, None) for key in self.param_dict])
1358 check_list = [0] * len(self.param_list) 1358 check_list = [0] * len(self.param_list)
1359 1359
1360 i = 0 1360 i = 0
1361 start = 0 1361 start = 0
1362 fixed_count = 0
1362 named = False 1363 named = False
1363 1364
1364 while start < len(params): 1365 while start < len(params):
1365 match = re.match(self.param_re, params[start:]) 1366 match = re.match(self.param_re, params[start:])
1366 if not match: 1367 if not match:
1382 value = match.group("name_param") 1383 value = match.group("name_param")
1383 type = 'n' 1384 type = 'n'
1384 else: 1385 else:
1385 raise ValueError("Parameter parser code does not fit param_re regex") 1386 raise ValueError("Parameter parser code does not fit param_re regex")
1386 1387
1387 parameter_list.append(value) 1388 #parameter_list.append(value)
1388 name = match.group("name") 1389 name = match.group("name")
1389 if name: 1390 if name:
1390 if name not in self.param_dict: 1391 if name not in self.param_dict:
1391 # TODO we should think on inheritance of parameters 1392 # TODO we should think on inheritance of parameters
1392 raise ValueError("unknown parameter name '%s'" % name) 1393 raise ValueError("unknown parameter name '%s'" % name)
1400 named = True 1401 named = True
1401 elif named: 1402 elif named:
1402 raise ValueError("only named parameters allowed after first named parameter") 1403 raise ValueError("only named parameters allowed after first named parameter")
1403 else: 1404 else:
1404 nr = i 1405 nr = i
1406 if nr not in self.param_dict.values():
1407 fixed_count = nr + 1
1405 parameter_list[nr] = value 1408 parameter_list[nr] = value
1406 1409
1407 # Let's populate and map our dictionary to what's been found 1410 # Let's populate and map our dictionary to what's been found
1408 for name in self.param_dict: 1411 for name in self.param_dict:
1409 tmp = self.param_dict[name] 1412 tmp = self.param_dict[name]
1410 parameter_dict[name] = parameter_list[tmp] 1413 parameter_dict[name] = parameter_list[tmp]
1411 1414
1412 i += 1 1415 i += 1
1413 1416
1414 return parameter_list, parameter_dict 1417 for i in range(fixed_count):
1418 parameter_dict[i] = parameter_list[i]
1419
1420 return fixed_count, parameter_dict
1415 1421
1416 """ never used: 1422 """ never used:
1417 def _check_type(value, type, format): 1423 def _check_type(value, type, format):
1418 if type == 'n' and 's' in format: # n as s 1424 if type == 'n' and 's' in format: # n as s
1419 return value 1425 return value