]> mj.ucw.cz Git - moe.git/commitdiff
Do not try to distinguish between single and double quotes
authorMartin Mares <mj@ucw.cz>
Sun, 9 Aug 2009 11:05:27 +0000 (13:05 +0200)
committerMartin Mares <mj@ucw.cz>
Sun, 9 Aug 2009 11:05:27 +0000 (13:05 +0200)
They are the same in Python.

t/moe/config.py
t/moe/meta.py

index 2a8443f10db9e515c9ef42a96e686d858eec19ce..909730321245e636ba4bc202968f926472257481 100644 (file)
@@ -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 = {}
index f565904eca94d8c46f18de683043dbf92f9f5878..231b8dfadd9d0b4f23c9f1c12c7fe4f89168c989 100644 (file)
@@ -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: