def get_source(self, exc_type, exc_value, exc_info, tb): from uliweb.core.template import Template t = Template('', self.vars, self.env, self.dirs) t.set_filename(self.tmpfilename) use_temp_flag, filename, text = t.get_parsed_code() if exc_type is SyntaxError: import re r = re.search(r'line (\d+)', str(exc_value)) lineno = int(r.group(1)) else: lineno = tb.tb_frame.f_lineno return self.tmpfilename, lineno, text
def _find_template(self, template, tree): """ If tree is true, then will display the track of template extend or include """ from uliweb import application from uliweb.core.template import Template filename = None if not tree: for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): print filename.replace('\\', '/') else: def get_rel_filename(filename, path): f1 = os.path.splitdrive(filename)[1] f2 = os.path.splitdrive(path)[1] f = os.path.relpath(f1, f2).replace('\\', '/') if f.startswith('..'): return filename.replace('\\', '/') else: return f tree_ids = {} nodes = {} def make_tree(alist): parents = [] for p, c, prop in alist: _ids = tree_ids.setdefault(p, []) _ids.append(c) nodes[c] = {'id':c, 'prop':prop} parents.append(p) d = list(set(parents) - set(nodes.keys())) for x in d: nodes[x] = {'id':x, 'prop':''} return d def print_tree(subs, cur=None, level=1, indent=4): for x in subs: n = nodes[x] caption = ('(%s)' % n['prop']) if n['prop'] else '' if cur == n['id']: print '-'*(level*indent-1)+'>', '%s%s' % (caption, n['id']) else: print ' '*level*indent, '%s%s' % (caption, n['id']) print_tree(tree_ids.get(x, []), cur=cur, level=level+1, indent=indent) templates = [] path = os.getcwd() for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): print get_rel_filename(filename, path) print print '-------------- Tree --------------' break if filename: def see(action, cur_filename, filename): #templates(get_rel_filename(filename, path), cur_filename, action) if action == 'extend': templates.append((get_rel_filename(filename, path), get_rel_filename(cur_filename, path), action)) else: templates.append((get_rel_filename(cur_filename, path), get_rel_filename(filename, path), action)) t = Template(open(filename, 'rb').read(), vars={}, dirs=application.template_dirs, see=see) t.set_filename(filename) t.get_parsed_code() print_tree(make_tree(templates), get_rel_filename(filename, path))
def _find_template(self, template, tree, blocks, with_filename): """ If tree is true, then will display the track of template extend or include """ from uliweb import application from uliweb.core.template import Template, BaseBlockNode def get_rel_filename(filename, path): f1 = os.path.splitdrive(filename)[1] f2 = os.path.splitdrive(path)[1] f = os.path.relpath(f1, f2).replace('\\', '/') if f.startswith('..'): return filename.replace('\\', '/') else: return f filename = None template_file = None if not tree: for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): if not template_file: template_file = filename print filename.replace('\\', '/') else: tree_ids = {} nodes = {} def make_tree(alist): parents = [] for p, c, prop in alist: _ids = tree_ids.setdefault(p, []) _ids.append(c) nodes[c] = {'id':c, 'prop':prop} parents.append(p) d = list(set(parents) - set(nodes.keys())) for x in d: nodes[x] = {'id':x, 'prop':''} return d def print_tree(subs, cur=None, level=1, indent=4): for x in subs: n = nodes[x] caption = ('(%s)' % n['prop']) if n['prop'] else '' if cur == n['id']: print '-'*(level*indent-1)+'>', '%s%s' % (caption, n['id']) else: print ' '*level*indent, '%s%s' % (caption, n['id']) print_tree(tree_ids.get(x, []), cur=cur, level=level+1, indent=indent) templates = [] path = os.getcwd() for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): if not template_file: template_file = filename print get_rel_filename(filename, path) print print '-------------- Tree --------------' break if filename: def see(action, cur_filename, filename): #templates(get_rel_filename(filename, path), cur_filename, action) if action == 'extend': templates.append((get_rel_filename(filename, path), get_rel_filename(cur_filename, path), action)) else: templates.append((get_rel_filename(cur_filename, path), get_rel_filename(filename, path), action)) t = Template(open(filename, 'rb').read(), vars={}, dirs=application.template_dirs, see=see) t.set_filename(filename) t.get_parsed_code() print_tree(make_tree(templates), get_rel_filename(filename, path)) if template_file and blocks: print print '-------------- Blocks --------------' t = Template(open(template_file, 'rb').read(), vars={}, dirs=application.template_dirs) t.set_filename(template) t.get_parsed_code() path = os.getcwd() def p(node, tab=4): for x in node.nodes: if isinstance(x, BaseBlockNode): if x.name in t.content.root.block_vars: x = t.content.root.block_vars[x.name][-1] _file = x.template_file else: _file = x.template_file f = get_rel_filename(_file, path) if with_filename: print ' '*tab + x.name, ' ('+f+')' else: print ' '*tab + x.name p(x, tab+4) p(t.content)
def _find_template(self, template, tree): """ If tree is true, then will display the track of template extend or include """ from uliweb import application from uliweb.core.template import Template filename = None if not tree: for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): print filename.replace('\\', '/') else: print "Not found" else: def get_rel_filename(filename, path): f = os.path.relpath(filename, path).replace('\\', '/') if f.startswith('..'): return filename.replace('\\', '/') else: return f tree_ids = {} nodes = {} def make_tree(alist): parents = [] for p, c, prop in alist: _ids = tree_ids.setdefault(p, []) _ids.append(c) nodes[c] = {'id':c, 'prop':prop} parents.append(p) d = list(set(parents) - set(nodes.keys())) for x in d: nodes[x] = {'id':x, 'prop':''} return d def print_tree(subs, cur=None, level=1, indent=4): for x in subs: n = nodes[x] caption = ('(%s)' % n['prop']) if n['prop'] else '' if cur == n['id']: print '-'*(level*indent-1)+'>', '%s%s' % (caption, n['id']) else: print ' '*level*indent, '%s%s' % (caption, n['id']) print_tree(tree_ids.get(x, []), cur=cur, level=level+1, indent=indent) templates = [] path = os.getcwd() for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): print get_rel_filename(filename, path) print print '-------------- Tree --------------' break if filename: def see(action, cur_filename, filename): #templates(get_rel_filename(filename, path), cur_filename, action) if action == 'extend': templates.append((get_rel_filename(filename, path), get_rel_filename(cur_filename, path), action)) else: templates.append((get_rel_filename(cur_filename, path), get_rel_filename(filename, path), action)) t = Template(open(filename, 'rb').read(), vars={}, dirs=application.template_dirs, see=see) t.set_filename(filename) t.get_parsed_code() print_tree(make_tree(templates), get_rel_filename(filename, path))
def _find_template(self, template, tree, blocks, with_filename): """ If tree is true, then will display the track of template extend or include """ from uliweb import application from uliweb.core.template import Template, BaseBlockNode def get_rel_filename(filename, path): f1 = os.path.splitdrive(filename)[1] f2 = os.path.splitdrive(path)[1] f = os.path.relpath(f1, f2).replace("\\", "/") if f.startswith(".."): return filename.replace("\\", "/") else: return f filename = None template_file = None if not tree: for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): if not template_file: template_file = filename print filename.replace("\\", "/") else: tree_ids = {} nodes = {} def make_tree(alist): parents = [] for p, c, prop in alist: _ids = tree_ids.setdefault(p, []) _ids.append(c) nodes[c] = {"id": c, "prop": prop} parents.append(p) d = list(set(parents) - set(nodes.keys())) for x in d: nodes[x] = {"id": x, "prop": ""} return d def print_tree(subs, cur=None, level=1, indent=4): for x in subs: n = nodes[x] caption = ("(%s)" % n["prop"]) if n["prop"] else "" if cur == n["id"]: print "-" * (level * indent - 1) + ">", "%s%s" % (caption, n["id"]) else: print " " * level * indent, "%s%s" % (caption, n["id"]) print_tree(tree_ids.get(x, []), cur=cur, level=level + 1, indent=indent) templates = [] path = os.getcwd() for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): if not template_file: template_file = filename print get_rel_filename(filename, path) print print "-------------- Tree --------------" break if filename: def see(action, cur_filename, filename): # templates(get_rel_filename(filename, path), cur_filename, action) if action == "extend": templates.append( (get_rel_filename(filename, path), get_rel_filename(cur_filename, path), action) ) else: templates.append( (get_rel_filename(cur_filename, path), get_rel_filename(filename, path), action) ) t = Template(open(filename, "rb").read(), vars={}, dirs=application.template_dirs, see=see) t.set_filename(filename) t.get_parsed_code() print_tree(make_tree(templates), get_rel_filename(filename, path)) if template_file and blocks: print print "-------------- Blocks --------------" t = Template(open(template_file, "rb").read(), vars={}, dirs=application.template_dirs) t.set_filename(template) t.get_parsed_code() path = os.getcwd() def p(node, tab=4): for x in node.nodes: if isinstance(x, BaseBlockNode): if x.name in t.content.root.block_vars: x = t.content.root.block_vars[x.name][-1] _file = x.template_file else: _file = x.template_file f = get_rel_filename(_file, path) if with_filename: print " " * tab + x.name, " (" + f + ")" else: print " " * tab + x.name p(x, tab + 4) p(t.content)
def _find_template(self, template, tree): """ If tree is true, then will display the track of template extend or include """ from uliweb import application from uliweb.core.template import Template filename = None if not tree: for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): print filename.replace("\\", "/") else: print "Not found" else: def get_rel_filename(filename, path): f = os.path.relpath(filename, path).replace("\\", "/") if f.startswith(".."): return filename.replace("\\", "/") else: return f tree_ids = {} nodes = {} def make_tree(alist): parents = [] for p, c, prop in alist: _ids = tree_ids.setdefault(p, []) _ids.append(c) nodes[c] = {"id": c, "prop": prop} parents.append(p) d = list(set(parents) - set(nodes.keys())) for x in d: nodes[x] = {"id": x, "prop": ""} return d def print_tree(subs, cur=None, level=1, indent=4): for x in subs: n = nodes[x] caption = ("(%s)" % n["prop"]) if n["prop"] else "" if cur == n["id"]: print "-" * (level * indent - 1) + ">", "%s%s" % (caption, n["id"]) else: print " " * level * indent, "%s%s" % (caption, n["id"]) print_tree(tree_ids.get(x, []), cur=cur, level=level + 1, indent=indent) templates = [] path = os.getcwd() for dir in application.template_dirs: filename = os.path.join(dir, template) if os.path.exists(filename): print get_rel_filename(filename, path) print print "-------------- Tree --------------" break if filename: def see(action, cur_filename, filename): # templates(get_rel_filename(filename, path), cur_filename, action) if action == "extend": templates.append( (get_rel_filename(filename, path), get_rel_filename(cur_filename, path), action) ) else: templates.append( (get_rel_filename(cur_filename, path), get_rel_filename(filename, path), action) ) t = Template(open(filename, "rb").read(), vars={}, dirs=application.template_dirs, see=see) t.set_filename(filename) t.get_parsed_code() print_tree(make_tree(templates), get_rel_filename(filename, path))