equal
deleted
inserted
replaced
12 |
12 |
13 def parsestring(s, quoted=True): |
13 def parsestring(s, quoted=True): |
14 '''parse a string using simple c-like syntax. |
14 '''parse a string using simple c-like syntax. |
15 string must be in quotes if quoted is True.''' |
15 string must be in quotes if quoted is True.''' |
16 if quoted: |
16 if quoted: |
17 first = s[0] |
17 if len(s) < 2 or s[0] != s[-1]: |
18 if len(s) < 2: raise SyntaxError(_('string too short')) |
18 raise SyntaxError(_('unmatched quotes')) |
19 if first not in "'\"": raise SyntaxError(_('invalid quote')) |
19 return s[1:-1].decode('string_escape') |
20 if s[-1] != first: raise SyntaxError(_('unmatched quotes')) |
|
21 s = s[1:-1].decode('string_escape') |
|
22 if first in s: raise SyntaxError(_('string ends early')) |
|
23 return s |
|
24 |
20 |
25 return s.decode('string_escape') |
21 return s.decode('string_escape') |
26 |
22 |
27 class templater(object): |
23 class templater(object): |
28 '''template expansion engine. |
24 '''template expansion engine. |