def __init__(self, path = None, rootPath = None, caduceusPath = None): CaduceusTemplateEntity.__init__(self) self._path = path self._rootPath = rootPath self._caduceusPath = caduceusPath self._refHeadTag = None self._refHtmlTag = None
def _loopFor(self, varName, listName, dictGlob, dictLoc, tmplResults): content = "" listName = listName.rstrip(":") list = eval(listName, dictGlob, dictLoc) for i in list: dictLoc[varName] = i content += CaduceusTemplateEntity.render(self, dictGlob, dictLoc, tmplResults) return content
def _setVariable(self, variable, dictGlob, dictLoc, tmplResults): # Get variable value (ie: render childs) content = CaduceusTemplateEntity.render(self, dictGlob, dictLoc, tmplResults) pythonStmt = '%s = "%s"' % (variable, content) try: exec pythonStmt in dictGlob, dictLoc except Exception, excep: traceback.print_exc() tagId = tmplResults.addExceptionsError(traceback.format_exc()) return '<span id="%s" class="failure"><pre class="exception">%s</pre></span>' % (tagId, traceback.format_exc())
def render(self, dictGlob, dictLoc, results): htmlAttribs = "" for attr in self._attribs: htmlAttribs += ' %s="%s"' % (attr[0], attr[1]) if self._isEmptyTag: return "<%s%s />" % (self._tag, htmlAttribs) else: content = CaduceusTemplateEntity.render(self, dictGlob, dictLoc, results) if self._tag == "title": results.setTitle(content) return "<%s%s>%s</%s>" % (self._tag, htmlAttribs, content, self._tag)
def render(self, dictGlob, dictLoc, results): if self._caduceusPath: # Template is document root (ie: not a partial) cssPath = CaduceusHelper.getHtmlPathToResource(self._path, self._rootPath, "caduceus.css") stylesheetToken = CaduceusTemplateHtmlTag("link", [ ("rel", "stylesheet"), ("href", cssPath), ("type", "text/css")], True) if self._refHeadTag: # Insert Caduceus style sheet as first child self._refHeadTag.addTokenFirst(stylesheetToken) elif self._refHtmlTag: head = self._refHeadTag.addTokenFirst(CaduceusTemplateHtmlTag("head", [])) head.addTokenFirst(stylesheetToken) return "<!-- Generated By Caduceus (%s) -->\n\n%s" % \ ( strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()), CaduceusTemplateEntity.render(self, dictGlob, dictLoc, results)) return CaduceusTemplateEntity.render(self, dictGlob, dictLoc, results)
def _exec(self, pythonStmt, dictGlob, dictLoc, tmplResults): # We must eval python code before rendering childs, # except if @ shorcut is in use bRunChilds = True content = "" if '@' in pythonStmt: # Use content to get replacement for @ bRunChilds = False content = CaduceusTemplateEntity.render(self, dictGlob, dictLoc, tmplResults) pythonStmt = pythonStmt.replace("@", '"%s"' % content) try: exec pythonStmt in dictGlob, dictLoc except Exception, excep: traceback.print_exc() tagId = tmplResults.addExceptionsError(traceback.format_exc()) content = '<span id="%s" class="failure"><pre class="exception">%s</pre></span>' % (tagId, traceback.format_exc())
def _assert(self, assertionType, pythonStmt, dictGlob, dictLoc, tmplResults): # Get comparaison text (ie: render childs) content = CaduceusTemplateEntity.render(self, dictGlob, dictLoc, tmplResults) try: result = eval("str(%s)" % pythonStmt, dictGlob, dictLoc) if assertionType == "assertEqual": comparaison = '"%s" == "%s"' % (result, content) else: comparaison = '"%s" != "%s"' % (result, content) if eval(comparaison, dictGlob, dictLoc): tagId = tmplResults.addAssertion(CaduceusTemplateResults.SUCCESS, None) return '<span id="%s" class="success">%s</span>' % (tagId, content) else: tagId = tmplResults.addAssertion(CaduceusTemplateResults.FAILURE, comparaison) return '<span id="%s" class="failure"><span class="expected">%s</span>%s</span>' % (tagId, content, result) except Exception: traceback.print_exc() tagId = tmplResults.addAssertion(CaduceusTemplateResults.ERROR, traceback.format_exc()) return '<span id="%s" class="failure"><span class="expected">%s</span><pre class="exception">%s</pre></span>' % (tagId, content, traceback.format_exc())
def __init__(self, tag, attribs, isEmptyTag = False): CaduceusTemplateEntity.__init__(self) self._tag = tag self._attribs = attribs self._isEmptyTag = isEmptyTag
def render(self, dictGlob, dictLoc, results): return "%s%s" % (self._text, CaduceusTemplateEntity.render(self, dictGlob, dictLoc, results))
def __init__(self, text): CaduceusTemplateEntity.__init__(self) self._text = text
def __init__(self, data, path, rootPath): CaduceusTemplateEntity.__init__(self) # Strip ? and white spaces at end of string self._data = data.rstrip(" ?\n") self._path = path self._rootPath = rootPath
content = "" if '@' in pythonStmt: # Use content to get replacement for @ bRunChilds = False content = CaduceusTemplateEntity.render(self, dictGlob, dictLoc, tmplResults) pythonStmt = pythonStmt.replace("@", '"%s"' % content) try: exec pythonStmt in dictGlob, dictLoc except Exception, excep: traceback.print_exc() tagId = tmplResults.addExceptionsError(traceback.format_exc()) content = '<span id="%s" class="failure"><pre class="exception">%s</pre></span>' % (tagId, traceback.format_exc()) if bRunChilds: return content + CaduceusTemplateEntity.render(self, dictGlob, dictLoc, tmplResults) else: return content def _echo(self, pythonStmt, dictGlob, dictLoc, tmplResults): content = "" try: content = eval(pythonStmt, dictGlob, dictLoc) except Exception, excep: traceback.print_exc() tagId = tmplResults.addExceptionsError(traceback.format_exc()) content = '<span id="%s" class="failure"><pre class="exception">%s</pre></span>' % (tagId, traceback.format_exc()) return content + CaduceusTemplateEntity.render(self, dictGlob, dictLoc, tmplResults) def _setVariable(self, variable, dictGlob, dictLoc, tmplResults):