h@41: # 2.6.1 backend h@41: h@41: # written by VB. h@41: h@41: import re, codecs h@41: import fileinput h@41: import sys, traceback, os h@41: from xml.sax.saxutils import escape, quoteattr h@41: from copy import copy, deepcopy h@41: from glob import glob h@41: from .pyPEG import code, parse, parseLine, u, Symbol vb@72: from .grammar import ymlCStyle, comment, _inner h@41: h@41: ymlFunc, pointers, pythonFunc = {}, {}, {} h@41: in_ns = "" h@41: operator = [] h@41: included = "" h@41: includePath = [] h@41: emitlinenumbers = False h@41: encoding = "utf-8" h@41: h@41: first = True h@41: enable_tracing = False h@41: h@41: ymlFunc["decl"] = "#error" h@41: ymlFunc["define"] = "#error" h@41: ymlFunc["operator"] = "#error" h@41: h@41: def clearAll(): h@41: global ymlFunc, pointers, pythonFunc, in_ns, operator, included h@41: ymlFunc, pointers, pythonFunc = {}, {}, {} h@41: in_ns = "" h@41: operator = [] h@41: included = "" h@41: h@41: lq = re.compile(r"\|(\>*)(.*)") h@41: sq = re.compile(r"(\d*)\>(.*)") h@41: ts = re.compile(r'(\|\|(?P\>*)\s*\n(?P.*?)\n(?P\s*)\|\|)|("""(?P.*?)""")|(\>\>(?P.*?)\>\>)', re.S) h@41: tq = re.compile(r"(\]|\<)\s*(.*)") h@41: bq = re.compile(r"\`(.*?)\`", re.S) h@41: bqq = re.compile(r"\s*\`\`(.*)") h@41: all = re.compile(r".*", re.S) h@41: h@41: line = 1 h@41: h@41: def pointer(name): h@41: try: h@41: return u(pointers[name[1:]]) h@41: except: h@41: if name == "*_trace_info": h@41: return '""' h@41: if included: h@41: raise LookupError("in " + included + ":" + u(line) + ": pointer " + name) h@41: else: h@41: raise LookupError("in " + u(line) + ": pointer " + name) h@41: h@41: def evalPython(expr): h@41: try: h@41: result = eval(u(expr), pythonFunc) h@41: if type(result) is bytes: h@41: return codecs.decode(result, encoding) h@41: else: h@41: return result h@41: except: h@41: name, parm, tb = sys.exc_info() h@41: msg = "in python expression: " + u(parm) h@41: if name is SyntaxError: h@41: tbl = traceback.format_exception(name, parm, tb) h@41: msg += "\n" + tbl[-3] + tbl[-2] h@41: else: h@41: msg += ": " + expr + "\n" h@41: if included: h@41: raise name("in " + included + ":" + u(line) + ": " + msg) h@41: else: h@41: raise name("in " + u(line) + ": " + msg) h@41: h@41: def execPython(script): h@41: try: h@41: if type(script) is str: h@41: exec(script, pythonFunc) h@41: else: h@41: exec(codecs.decode(script, encoding), pythonFunc) h@41: except: h@41: name, parm, tb = sys.exc_info() h@41: msg = "in python script: " + u(parm) h@41: if name is SyntaxError: h@41: tbl = traceback.format_exception(name, parm, tb) h@41: msg += "\n" + tbl[-3] + tbl[-2] h@41: else: h@41: msg += ": " + expr + "\n" h@41: if included: h@41: raise name("in " + included + ":" + u(line) + ": " + msg) h@41: else: h@41: raise name("in " + u(line) + ": " + msg) h@41: h@41: def textOut(text): h@41: if not text: h@41: return "" h@41: if type(text) is not str: h@41: text = codecs.decode(text, encoding) h@41: text = text.replace(r'\"', r'\\"') h@41: text = '"""' + text.replace('"', r'\"') + '"""' h@41: try: h@41: textFunc = ymlFunc["text"] h@41: parms = ['text', ('parm', [text])] h@41: c, result = textFunc(parms) h@41: if c: h@41: if type(textFunc.alias) is str: h@41: result += "" h@41: else: h@41: result += "" h@41: return result h@41: except: h@41: return escape(eval(text)) h@41: h@41: def strRepl(text): h@41: if not text: h@41: return "" h@41: if type(text) is not str: h@41: text = codecs.decode(text, encoding) h@41: text = text.replace(r'\"', r'\\"') h@41: text = '"""' + text.replace('"', r'\"') + '"""' h@41: if type(text) is str: h@41: return escape(eval(text)) h@41: h@41: def applyMacros(macros, text): h@41: result = text h@41: for key, value in macros.items(): h@41: result = result.replace(key, value) h@41: return result h@41: h@41: class YF: h@41: def __init__(self, name): h@41: self.name = name h@41: self.parms = [] h@41: self.descends = [] h@41: self.values = {} h@41: self.content = None h@41: self.pointers = {} h@41: self.macros = {} h@41: if in_ns: h@41: self.alias = in_ns + ":" + name.replace("_", "-") h@41: else: h@41: self.alias = name.replace("_", "-") h@41: pythonFunc["yml_" + name] = self h@41: if emitlinenumbers: h@41: self.values["yml:declared"] = u(line) h@41: h@41: def copy(self, newName): h@41: yf = YF(newName) h@41: yf.parms.extend(self.parms) h@41: yf.descends.extend(self.descends) h@41: yf.values = self.values.copy() h@41: yf.content = self.content h@41: yf.pointers = self.pointers.copy() h@41: yf.macros = self.macros.copy() h@41: yf.alias = self.alias h@41: return yf h@41: h@41: def patch(self, second): h@41: self.parms.extend(second.parms) h@41: self.descends.extend(second.descends) h@41: self.values.update(second.values) h@41: if second.content: h@41: self.content = second.content h@41: self.pointers.update(second.pointers) h@41: self.macros.update(second.macros) h@41: h@41: def __call__(self, called_with, hasContent = False, avoidTag = False): h@41: global pointers h@41: parms = [] h@41: vals = {} h@41: if self.pointers: h@41: pointers.update(self.pointers) h@41: h@41: for data in called_with: h@41: if type(data) is tuple or type(data) is Symbol: h@41: if data[0] == "parm": h@41: l = data[1] h@41: parm = l[0] h@41: if parm[0] == "*": h@41: parm = pointer(parm) h@41: if len(l) == 1: h@41: if type(parm) is tuple or type(parm) is Symbol: h@41: if parm[0] == "pyExp": h@41: val = evalPython(parm[1][0]) h@41: parms.append(val) h@41: else: h@41: parms.append(evalPython((parm))) h@41: else: h@41: if type(parm) is tuple or type(parm) is Symbol: h@41: if parm[0] == "pyExp": h@41: parm = evalPython(parm[1][0]) h@41: val = l[1] h@41: if type(val) is tuple or type(val) is Symbol: h@41: if val[0] == "pyExp": h@41: val = evalPython(val[1][0]) h@41: if val[0] == "*": h@41: val = pointer(val) h@41: if u(val)[0] == '"' or u(val)[0] == "'": h@41: vals[parm] = evalPython(u(val)) h@41: else: h@41: vals[parm] = u(val) h@41: elif data[0] == "content": h@41: hasContent = True h@41: h@41: if enable_tracing: h@41: text = u(parms) + ", " + u(vals) h@41: pointers["_trace_info"] = '"' + u(line) + ": " + u(self.name) + " " + text.replace('"', '#') + '"' h@41: h@41: if emitlinenumbers: h@41: global first h@41: if first: h@41: vals["xmlns:yml"] = "http://fdik.org/yml" h@41: first = False h@41: vals["yml:called"] = u(line) h@41: return self.xml(parms, vals, hasContent, avoidTag) h@41: h@41: def addParm(self, parm): h@41: if parm[0] == "%": h@41: for i in range(len(self.parms)): h@41: if self.parms[i][0] != "%": h@41: self.parms.insert(i, parm) h@41: return h@41: self.parms.append(parm) h@41: h@41: def addDescend(self, desc): h@41: if desc[0] == "+" or desc[0] == "@": h@41: self.descends.append(desc[1:]) h@41: else: h@41: self.descends.append(desc) h@41: h@41: def addValue(self, parm, value): h@41: if type(value) is str or type(value) is str: h@41: if value[0] != "'" and value[0] != '"': h@41: self.values[parm] = u(value) h@41: else: h@41: self.values[parm] = u(evalPython(value)) h@41: else: h@41: self.values[parm] = u(evalPython(u(value))) h@41: h@41: def xml(self, callParms, callValues, hasContent, avoidTag = False): h@41: global pointers h@41: extraContent = "" h@41: if self.content: h@41: hasContent = True h@41: resultParms = self.values.copy() h@41: macros = self.macros.copy() h@41: toDelete = [ key for key in resultParms.keys() ] h@41: for key in toDelete: h@41: if key[0] == "*": h@41: del resultParms[key] h@41: for key, value in callValues.items(): h@41: if key[0] == "%": h@41: macros[key] = value h@41: else: h@41: resultParms[key] = value h@41: i = 0 h@41: for cp in callParms: h@41: if i < len(self.parms): h@41: if self.parms[i][0] == "*": h@41: cp = u(cp) h@41: if "'" in cp: h@41: pointers[self.parms[i][1:]] = '"' + cp + '"' h@41: else: h@41: pointers[self.parms[i][1:]] = "'" + cp + "'" h@41: elif self.parms[i][0] == "%": h@41: macros[self.parms[i]] = u(cp) h@41: else: h@41: resultParms[self.parms[i]] = cp h@41: else: h@41: extraContent += u(cp) h@41: hasContent = True h@41: i += 1 h@41: result = "" h@41: for p, v in resultParms.items(): h@41: if p[0] == "'" or p[0] == '"': h@41: p = eval(p) h@41: result += " "+ p + "=" + quoteattr(applyMacros(macros, u(v))) h@41: if hasContent: h@41: if avoidTag: h@41: return True, strRepl(extraContent) h@41: else: h@41: return True, "<" + self.alias + result + ">" + strRepl(extraContent) h@41: else: h@41: if avoidTag: h@41: return False, "" h@41: else: h@41: return False, "<" + self.alias + result + "/>" h@41: h@41: def replaceContent(tree, subtree): h@41: n = 0 h@41: while n < len(tree): h@41: obj = tree[n] h@41: if obj[0] == "func": h@41: l = obj[1] h@41: if l[0] == "content": h@41: d = 1 h@41: if subtree: h@41: for el in subtree: h@41: tree.insert(n+d, el) h@41: d += 1 h@41: del tree[n] h@41: n += d h@41: else: h@41: try: h@41: if l[-1][0] == "content": h@41: replaceContent(l[-1][1], subtree) h@41: except: pass h@41: elif obj[0] == "funclist": h@41: replaceContent(obj[1], subtree) h@41: n += 1 h@41: return tree h@41: h@41: def executeCmd(text): h@41: if type(text) is not str: h@41: text = codecs.decode(text, encoding) h@41: for (regex, pattern) in operator: h@41: match = re.search(regex, text) h@41: while match: h@41: cmd = pattern h@41: opt = match.groups() h@41: for i in range(len(opt)): h@41: cmd = cmd.replace("%" + u(i+1), opt[i]) h@41: text = text[:match.start()] + "`" + cmd + "`"+ text[match.end():] h@41: match = re.search(regex, text) h@41: h@41: result = "" h@41: m = re.search(bq, text) h@41: while text and m: h@41: cmd = m.group(1) h@41: head = textOut(text[:m.start()]) h@41: text = text[m.end():] h@41: try: h@41: r, rest = parseLine(cmd, _inner, [], True, comment) h@41: if rest: raise SyntaxError(cmd) h@41: except SyntaxError: h@41: if included: h@41: raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in executing command: " + cmd.strip()) h@41: else: h@41: raise SyntaxError("in " + u(line) + ": syntax error in executing command: " + cmd.strip()) h@41: inner = _finish(r) h@41: result += head + inner h@41: m = re.search(bq, text) h@41: result += textOut(text) h@41: h@41: return result h@41: h@41: def codegen(obj): h@41: global in_ns, pointers, line, included h@41: ctype = obj[0] h@41: h@41: if type(obj) is code: h@41: return obj h@41: h@41: try: h@41: if ctype.line: line = ctype.line h@41: except: pass h@41: h@41: if ctype == "empty": h@41: return code("") h@41: h@41: if ctype == "in_ns": h@41: in_ns = obj[1][0] h@41: subtree = obj[1] h@41: for sel in subtree: h@41: codegen(sel) h@41: in_ns = "" h@41: return code("") h@41: h@41: elif ctype == "decl": h@41: name = "" h@41: for data in obj[1]: h@41: if type(data) is str: h@41: name = data h@41: try: h@41: yf = ymlFunc[name] h@41: yf.alias h@41: except: h@41: ymlFunc[name] = YF(name) h@41: yf = ymlFunc[name] h@41: if in_ns: h@41: yf.alias = in_ns + ":" + name h@41: if not enable_tracing: h@41: if in_ns == "xsl" and (name == "debug" or name=="assert" or name[:7]=="_trace_"): h@41: yf.alias = "-" h@41: yf.addParm("skip1") h@41: yf.addParm("skip2") h@41: break h@41: elif type(data) is tuple or type(data) is Symbol: h@41: if data[0] == "base": h@41: base = data[1][0] h@41: try: h@41: yf = ymlFunc[name] = ymlFunc[base].copy(name) h@41: except KeyError: h@41: if included: h@41: raise KeyError("in " + included + ":" + u(line) + ": " + base + " as base for " + name) h@41: else: h@41: raise KeyError("in " + u(line) + ": " + base + " as base for " + name) h@41: elif data[0] == "shape": h@41: shape = ymlFunc[data[1]] h@41: try: h@41: yf = ymlFunc[name] h@41: yf.patch(shape) h@41: except KeyError: h@41: if included: h@41: raise KeyError("in " + included + ":" + u(line) + ": " + base + " as shape for " + name) h@41: else: h@41: raise KeyError("in " + u(line) + ": " + base + " as shape for " + name) h@41: elif data[0] == "descend": h@41: yf.addDescend(data[1]) h@41: elif data[0] == "declParm": h@41: l = data[1] h@41: parmName = l[0] h@41: if len(l)==1: h@41: yf.addParm(parmName) h@41: else: h@41: value = l[1] h@41: if parmName[0] != "%": h@41: yf.addValue(parmName, value) h@41: if parmName[0] == "*": h@41: yf.pointers[parmName[1:]] = value h@41: yf.addParm(parmName) h@41: elif parmName[0] == "%": h@41: if type(value) is str: h@41: yf.macros[parmName] = u(evalPython(value)) h@41: else: h@41: yf.macros[parmName] = u(evalPython(u(value))) h@41: yf.addParm(parmName) h@41: elif data[0] == "alias": h@41: if in_ns: h@41: yf.alias = in_ns + ":" + data[1][0] h@41: else: h@41: yf.alias = data[1][0] h@41: elif data[0] == "content": h@41: yf.content = data[1] h@41: h@41: return code("") h@41: h@41: elif ctype == "funclist": h@41: result = "" h@41: for f in obj[1]: h@41: result += codegen(f) h@41: return code(result) h@41: h@41: elif ctype == "parentheses": h@41: if len(obj[1]): h@41: return codegen(('func', ['_parentheses', ('content', [obj[1][0]])])) h@41: else: h@41: return "" h@41: h@41: elif ctype == "fparm": h@41: if len(obj[1]): h@41: return codegen(('func', ['_parm', ('content', [obj[1][0]])])) h@41: else: h@41: return "" h@41: h@41: elif ctype == "generic": h@41: return codegen(('func', ['_generic', ('content', [obj[1][0]])])) h@41: h@41: elif ctype == "xbase": h@41: return codegen(('func', ['_base', ('content', [obj[1][0]])])) h@41: h@41: elif ctype == "func": h@41: avoidTag = False h@41: name = obj[1][0] h@41: h@41: if name == "decl": h@41: if ymlFunc[name] == "#error": h@41: if included: h@41: raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in decl statement") h@41: else: h@41: raise SyntaxError("in " + u(line) + ": syntax error in decl statement") h@41: if name == "define" or name == "operator": h@41: if ymlFunc[name] == "#error": h@41: if included: h@41: raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in define statement") h@41: else: h@41: raise SyntaxError("in " + u(line) + ": syntax error in define statement") h@41: h@41: if name[0] == "&": h@41: avoidTag = True h@41: name = name[1:] h@41: hasContent = False h@41: h@41: if len(name) > 2: h@41: if name[0:2] == "**": h@41: return code(eval(''+pointer(name[1:]))) h@41: h@41: if name[0] == "*": h@41: name = eval(pointer(name)) h@41: if name[0] == "&": h@41: avoidTag = True h@41: name = name[1:] h@41: h@41: try: h@41: ymlFunc[name] h@41: except KeyError: h@41: try: h@41: if ymlFunc["_"].alias != "-": h@41: return codegen(('func', ['_', ('content', [('funclist', [obj])])])) h@41: else: h@41: ymlFunc[name] = copy(ymlFunc["_"]) h@41: ymlFunc[name].alias = name.replace("_", "-") h@41: return codegen(obj) h@41: except KeyError: h@41: ymlFunc[name] = YF(name) h@41: h@41: if ymlFunc[name].alias == "-": avoidTag = True h@41: h@41: to_add = [] h@41: if len(ymlFunc[name].descends): h@41: if obj[1][-1][0] != 'content': h@41: if included: h@41: raise KeyError("in " + included + ":" + u(line) + ": " + name + " has descending attributes, but no descendants are following") h@41: else: h@41: raise KeyError("in " + u(line) + ": " + name + " has descending attributes, but no descendants are following") h@41: h@41: def first_func(obj): h@41: if type(obj) is tuple or type(obj) is Symbol: h@41: if obj[0] == 'func': h@41: return obj h@41: elif obj[0] == 'funclist': h@41: return first_func(obj[1]) h@41: elif obj[0] == 'content': h@41: return first_func(obj[1]) h@41: else: h@41: return None h@41: elif type(obj) == list: h@41: for e in obj: h@41: f = first_func(e) h@41: if f: return f h@41: return None h@41: h@41: def copy_without_first_func(o, found = False): h@41: c = [] h@41: for obj in o: h@41: if found: h@41: c.append(obj) h@41: else: h@41: if obj[0] == 'func': h@41: if obj[1][-1][0] == 'content': h@41: c.extend( obj[1][-1][1] ) h@41: found = True h@41: else: h@41: c.append( ( obj[0], copy_without_first_func(obj[1], False ) ) ) h@41: return c h@41: h@41: def get_parms(obj): h@41: result = [] h@41: for e in obj[1]: h@41: if type(e) is tuple or type(e) is Symbol: h@41: if e[0] == "parm": h@41: result.append( e ) h@41: return result h@41: h@41: try: h@41: add_params = get_parms(obj) h@41: for e in obj[1][-1][1]: h@41: c = e[1] h@41: for dname in ymlFunc[name].descends: h@41: f, c = first_func(c), copy_without_first_func(c) h@41: if dname[0] == "*": h@41: pointers[dname[1:]] = "'" + f[1][0] + "'" h@41: else: h@41: add_params.append( ('parm', [dname, "'" + f[1][0] + "'"]) ) h@41: try: h@41: add_params.extend( get_parms(f) ) h@41: except: pass h@41: h@41: new_things = [ e[1][0] ] h@41: new_things.extend( add_params ) h@41: new_things.append( ('content', c) ) h@41: h@41: to_add.append( ('func', new_things ) ) h@41: except: h@41: if included: h@41: raise KeyError("in " + included + ":" + u(line) + ": " + name + " has descending attributes, and too less descendants are following") h@41: else: h@41: raise KeyError("in " + u(line) + ": " + name + " has descending attributes, and too less descendants are following") h@41: h@41: if not to_add: h@41: to_add = ( obj, ) h@41: h@41: complete = "" h@41: h@41: for obj in to_add: h@41: subtree = None h@41: try: h@41: if obj[1][-1][0] == "content": h@41: subtree = obj[1][-1][1] h@41: except: pass h@41: h@41: if ymlFunc[name].content: h@41: hasContent = True h@41: treetemplate = deepcopy(ymlFunc[name].content) h@41: subtree = replaceContent(treetemplate, subtree) h@41: h@41: if subtree: h@41: hasContent = True h@41: h@41: hasContent, result = ymlFunc[name](obj[1], hasContent, avoidTag) h@41: h@41: if subtree: h@41: for sel in subtree: h@41: result += codegen(sel) h@41: h@41: if hasContent and not(avoidTag): h@41: result += "" h@41: h@41: complete += result h@41: h@41: return code(complete) h@41: h@41: elif ctype == "textsection": h@41: result = '' h@41: ll = obj[1].splitlines() h@41: space = len(ll[-1]) - 2 h@41: for l in ll[1:-1]: h@41: m = re.match(bqq, l) h@41: if m: h@41: cmd = m.group(1) h@41: try: h@41: r, x = parseLine(cmd, _inner, [], True, comment) h@41: if x: raise SyntaxError(cmd) h@41: result += _finish(r) h@41: except SyntaxError: h@41: if included: h@41: raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in executing command: " + cmd.strip()) h@41: else: h@41: raise SyntaxError("in " + u(line) + ": syntax error in executing command: " + cmd.strip()) h@41: else: h@41: result += codegen(Symbol('lineQuote', '| ' + l[space:])) h@41: return code(result) h@41: h@41: elif ctype == "textsectionu": h@41: result = '' h@41: ll = obj[1].splitlines() h@41: space = len(ll[-1]) - 2 h@41: for l in ll[1:-1]: h@41: m = re.match(bqq, l) h@41: if m: h@41: cmd = m.group(1) h@41: try: h@41: r, x = parseLine(cmd, _inner, [], True, comment) h@41: if x: raise SyntaxError(cmd) h@41: result += _finish(r) h@41: except SyntaxError: h@41: if included: h@41: raise SyntaxError("in " + included + ":" + u(line) + ": syntax error in executing command: " + cmd.strip()) h@41: else: h@41: raise SyntaxError("in " + u(line) + ": syntax error in executing command: " + cmd.strip()) h@41: else: h@41: if result != '': result += ' ' h@41: result += codegen(Symbol('quote', ['> ' + l[space:]])) h@41: return code(result) h@41: h@41: elif ctype == "lineQuote" or ctype == "quote": h@41: m, text, base, inds = None, "", 0, 0 h@41: h@41: if ctype == "lineQuote": h@41: text = obj[1] h@41: m = lq.match(text) h@41: if m: h@41: inds = len(m.group(1)) h@41: text = m.group(2)[1:] h@41: else: inds = 0 h@41: elif ctype == "quote": h@41: inds = -1 h@41: text = obj[1][0] h@41: m = sq.match(text) h@41: if m: h@41: if m.group(1): h@41: inds = int(m.group(1)) h@41: text = m.group(2)[1:] h@41: else: h@41: if type(text) is str: h@41: text = u(evalPython(text)) h@41: h@41: ind = "" h@41: if inds > -1: h@41: try: h@41: cmd = evalPython("indent(" + u(inds) + ")") h@41: result, rest = parseLine(u(cmd), _inner, [], True, comment) h@41: if rest: h@41: raise SyntaxError() h@41: ind = _finish(result) h@41: except: pass h@41: h@41: if ctype == "lineQuote": text += "\n" h@41: h@41: hasTextFunc = False h@41: try: h@41: ymlFunc["text"] h@41: hasTextFunc = True h@41: except: pass h@41: h@41: text = executeCmd(text) h@41: return code(ind + text) h@41: h@41: elif ctype == "tagQuote": h@41: m = tq.match(obj[1]) h@41: if m.group(1) == "<": h@41: return code("<" + m.group(2)) h@41: else: h@41: return code(m.group(2)) h@41: h@41: elif ctype == "operator": h@41: operator.append((re.compile(evalPython(obj[1][0])), obj[1][1])) h@41: return code("") h@41: h@41: elif ctype == "constant": h@41: name = obj[1][0] h@41: if name[0] == "*": h@41: name = name[1:] h@41: value = obj[1][1] h@41: pointers[name] = value h@41: return code("") h@41: h@41: elif ctype == "include": h@41: reverse = False h@41: ktext, kxml = False, False h@41: for arg in obj[1]: h@41: if type(arg) is tuple or type(arg) is Symbol: h@41: if arg[0] == "reverse": h@41: reverse = True h@41: elif arg[0] == "ktext": h@41: ktext = True h@41: elif arg[0] == "kxml": h@41: kxml = True h@41: elif type(arg) is str: h@41: filemask = arg h@41: h@41: if filemask[0] == '/' or filemask[0] == '.': h@41: files = sorted(glob(filemask)) h@41: else: h@41: files = [] h@41: for directory in includePath: h@41: path = os.path.join(directory, filemask) h@41: files.extend(sorted(glob(path))) h@41: h@41: if files and reverse: h@41: files = files[-1::-1] h@41: h@41: if not(files): h@41: if included: h@41: raise IOError("in " + included + ":" + u(line) + ": include file(s) '" + filemask + "' not found") h@41: else: h@41: raise IOError("in " + u(line) + ": include file(s) '" + filemask + "' not found") h@41: h@41: includeFile = fileinput.input(files, mode="rU", openhook=fileinput.hook_encoded(encoding)) h@41: _included = included h@41: if ktext or kxml: h@41: text = "" h@41: for line in includeFile: h@41: included = includeFile.filename() h@41: if kxml: h@41: if (not line[:6] == '