From: Martin Mares Date: Sun, 9 Aug 2009 11:05:27 +0000 (+0200) Subject: Do not try to distinguish between single and double quotes X-Git-Tag: python-dummy-working~93 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=2c4186720e4f04fd83847e8a74d42e74b45f09e8;p=moe.git Do not try to distinguish between single and double quotes They are the same in Python. --- diff --git a/t/moe/config.py b/t/moe/config.py index 2a8443f..9097303 100644 --- a/t/moe/config.py +++ b/t/moe/config.py @@ -3,8 +3,8 @@ import re import sys -key_pattern = re.compile('^[A-Za-z0-9_-]+$') -ref_pattern = re.compile('^[A-Za-z0-9_-]+') +key_pattern = re.compile("^[A-Za-z0-9_-]+$") +ref_pattern = re.compile("^[A-Za-z0-9_-]+") class MoeConfigInvalid(Exception): pass @@ -21,21 +21,21 @@ class MoeConfig: self.load(file) elif name is not None: self.name = name - self.load(open(name, 'r')) + self.load(open(name, "r")) def parse_line(self, x): x = x.rstrip("\n").lstrip(" \t") - if x=='' or x.startswith('#'): + if x=="" or x.startswith("#"): pass else: - sep = x.find('=') + sep = x.find("=") if sep >= 0: k = x[:sep] v = x[sep+1:] if k.endswith("+"): k = k[:-1] if not self.vars.has_key(k): - self.vars[k] = [('a','')]; + self.vars[k] = [("a","")]; else: self.vars[k] = [] if not key_pattern.match(k): @@ -44,7 +44,7 @@ class MoeConfig: v=v[1:] if not v.endswith("'"): raise MoeConfigInvalid, "Misquoted string" - self.vars[k].append(('s', v[:-1])) + self.vars[k].append(("s", v[:-1])) elif v.startswith('"'): v=v[1:] if not v.endswith('"'): @@ -62,17 +62,17 @@ class MoeConfig: try: self.parse_line(x) except MoeConfigInvalid, x: - msg = x.message + ' at line ' + str(lino) - if hasattr(self, 'name'): - msg += ' of ' + self.name + msg = x.message + " at line " + str(lino) + if hasattr(self, "name"): + msg += " of " + self.name raise MoeConfigInvalid, msg def parse_interpolated(self, list, s): - while s<>'': - if s.startswith('$'): + while s<>"": + if s.startswith("$"): s = s[1:] - if s.startswith('{'): - p = s.find('}') + if s.startswith("{"): + p = s.find("}") if not p: raise MoeConfigInvalid, "Unbalanced braces" k, s = s[1:p], s[p+1:] @@ -84,25 +84,25 @@ class MoeConfig: k, s = s[:m.end()], s[m.end():] else: raise MoeConfigInvalid, "Invalid variable reference" - list.append(('i', k)) + list.append(("i", k)) else: - p = s.find('$') + p = s.find("$") if p < 0: p = len(s) - list.append(('s', s[:p])) + list.append(("s", s[:p])) s = s[p:] def dump(self, file=sys.stdout): for k,v in self.vars.items(): file.write(k) - if len(v) > 0 and v[0][0] == 'a': - file.write('+') + if len(v) > 0 and v[0][0] == "a": + file.write("+") v = v[1:] - file.write('=') + file.write("=") for t,w in v: - if t == 's': + if t == "s": file.write("'" + w + "'") - elif t == 'i': + elif t == "i": file.write('"$' + w + '"') file.write("\n") @@ -141,18 +141,18 @@ class MoeConfigStack: cfg = self.stk[pos] if cfg.vars.has_key(k): new = cfg.vars[k] - if new[0][0] == 'a': + if new[0][0] == "a": v = self.do_get(k, pos-1) else: - v = '' + v = "" for op,arg in new: - if op == 's': + if op == "s": v = v + arg - elif op == 'i': + elif op == "i": v = v + self[arg] return v pos -= 1 - return '' + return "" def keys(self): seen = {} diff --git a/t/moe/meta.py b/t/moe/meta.py index f565904..231b8df 100644 --- a/t/moe/meta.py +++ b/t/moe/meta.py @@ -4,7 +4,7 @@ import sys import types import re -key_pattern = re.compile('^[A-Za-z0-9_-]+$') +key_pattern = re.compile("^[A-Za-z0-9_-]+$") class MoeMetaInvalid(Exception): pass @@ -37,7 +37,7 @@ class MoeMeta: def write(self, file=None, name=None): if file is None: if name is not None: - file = open(name, 'w') + file = open(name, "w") else: file = sys.stdout self.write_nested(file, 0) @@ -52,12 +52,12 @@ class MoeMeta: w.write_nested(file, indent+1); file.write("\t" * indent + ")\n") else: - file.write("\t" * indent + k + ':' + str(w) + "\n") + file.write("\t" * indent + k + ":" + str(w) + "\n") def read(self, file=None, name=None): if file is None: if name is not None: - file = open(name, 'r') + file = open(name, "r") else: file = sys.stdin self.meta = {} @@ -77,21 +77,21 @@ class MoeMeta: this = self for x in file.readlines(): x = x.rstrip("\n").lstrip(" \t") - if x=='' or x.startswith('#'): + if x=="" or x.startswith("#"): pass else: - sep = x.find(':') + sep = x.find(":") if sep >= 0: k = x[:sep] v = x[sep+1:] this.read_val(k, v) - elif x.endswith('('): + elif x.endswith("("): k = x[:-1] new = MoeMeta() this.read_val(k, new) stk.append(this) this = new - elif x == ')': + elif x == ")": if len(stk) == 0: raise MoeMetaInvalid, "Parse error: incorrect nesting" else: