comparison mercurial/templater.py @ 28630:bf35644b9f3a

templater: relax unquotestring() to fall back to bare string This is convenient for our use case where quotes are optional except in a map file.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 26 Mar 2016 18:12:12 +0900
parents ed1d90f6e921
children 29c249dfb4ef
comparison
equal deleted inserted replaced
28629:d6f8a1535224 28630:bf35644b9f3a
865 elif i is not None: 865 elif i is not None:
866 for j in _flatten(i): 866 for j in _flatten(i):
867 yield j 867 yield j
868 868
869 def unquotestring(s): 869 def unquotestring(s):
870 '''unwrap quotes''' 870 '''unwrap quotes if any; otherwise returns unmodified string'''
871 if len(s) < 2 or s[0] != s[-1]: 871 if len(s) < 2 or s[0] != s[-1]:
872 raise SyntaxError(_('unmatched quotes')) 872 return s
873 return s[1:-1] 873 return s[1:-1]
874 874
875 class engine(object): 875 class engine(object):
876 '''template expansion engine. 876 '''template expansion engine.
877 877
978 978
979 for key, val in conf[''].items(): 979 for key, val in conf[''].items():
980 if not val: 980 if not val:
981 raise error.ParseError(_('missing value'), conf.source('', key)) 981 raise error.ParseError(_('missing value'), conf.source('', key))
982 if val[0] in "'\"": 982 if val[0] in "'\"":
983 try: 983 if val[0] != val[-1]:
984 self.cache[key] = unquotestring(val) 984 raise error.ParseError(_('unmatched quotes'),
985 except SyntaxError as inst: 985 conf.source('', key))
986 raise error.ParseError(inst.args[0], conf.source('', key)) 986 self.cache[key] = unquotestring(val)
987 else: 987 else:
988 val = 'default', val 988 val = 'default', val
989 if ':' in val[1]: 989 if ':' in val[1]:
990 val = val[1].split(':', 1) 990 val = val[1].split(':', 1)
991 self.map[key] = val[0], os.path.join(self.base, val[1]) 991 self.map[key] = val[0], os.path.join(self.base, val[1])