def test_layout2(self): template=""" <:slot head:> <:slot main:> <:slot foot:> """ tp=S.getTemplatePath() translated=translate_path(Cfg.componentRoot, tp) os.makedirs(os.path.dirname(translated)) open(translated, 'w').write(template) d=os.path.join(Cfg.componentRoot, '/nougat') os.mkdir(translate_path(Cfg.componentRoot, d)) fp=open(os.path.join(translate_path(Cfg.componentRoot, d), 'slotconf.pydcmp'), 'w') fp.write("raise ReturnValue(dict(head='HEAD', main='MAIN', foot='FOOT'))\n") fp.close() fp=C.docroot_open('/nougat/frenchie.stml', 'w') fp.write("<:calltemplate:>") fp.close() res=C.stringcomp('/nougat/frenchie.stml') assert 'HEAD' in res assert 'MAIN' in res assert 'FOOT' in res
def testComp15(self): fd, fname=tempfile.mkstemp(suffix=".inc") dfd, dfname=tempfile.mkstemp(suffix='.pydcmp') try: f=os.fdopen(fd, 'w') df=os.fdopen(dfd, 'w') f.write(""" Hello from me! <:datacomp x `dcompname`:> """) f.close() df.write("raise ReturnValue, 33\n") df.close() self.f.write(""" I'm going to call a component now. <:include `compname`:> x is <:val `x`:>. Done. """) self.f.close() res=C.stringcomp(self.fname, compname=fname, dcompname=dfname) self.failUnless('Hello from me!\n' in res) self.failUnless("x is 33" in res) finally: os.unlink(fname) os.unlink(dfname)
def testComp14(self): fd, fname=tempfile.mkstemp(suffix=".inc") try: f=os.fdopen(fd, 'w') f.write(""" Hello from me! <:set x `33`:> """) f.close() self.f.write(""" I'm going to call a component now. <:include `compname`:> x is <:val `x`:>. Done. """) self.f.close() suffixes=C.DEFAULT_FILE_COMPONENT_SUFFIX_MAP.copy() suffixes['.comp']=('string', S.STMLFileComponent) suffixes['.inc']=('include', S.STMLFileComponent) Configuration.load_dict(dict(componentFileSuffixMap=suffixes)) res=C.stringcomp(self.fname, compname=fname) print res self.failUnless('Hello from me!\n' in res) self.failUnless("x is 33" in res) finally: os.unlink(fname)
def test_layout1(self): template='<:compargs SLOTS=`{}`:><:for `"first second third".split()` name:><:slot `name`:><:/for:>' templatePath=S.getTemplatePath() translated=translate_path(Cfg.componentRoot, templatePath) d=os.path.dirname(translated) os.makedirs(d) open(translated, 'w').write(template) res=C.stringcomp(templatePath).strip() assert res=='', "expected empty, got %s" % res
def testLog2(self): self.f.write('hi there <:info "ding dong %s" `4`:>') self.f.close() logger=getUserLogger() logger.setLevel(logging.DEBUG) sio=cStringIO.StringIO() logger.addHandler(logging.StreamHandler(sio)) res=C.stringcomp(self.fname) self.failUnless('hi there' in res) v=sio.getvalue() self.failUnless('ding dong 4' in v)
def testLog1(self): self.f.write('hi there <:debug "about to compile the borkoscape":>') self.f.close() logger=getUserLogger() logger.setLevel(logging.DEBUG) sio=cStringIO.StringIO() logger.addHandler(logging.StreamHandler(sio)) res=C.stringcomp(self.fname) self.failUnless('hi there' in res) v=sio.getvalue() self.failUnless('borkoscape' in v)
def testArgsTag1(self): self.f.write("<:args x=`int` y z=`(int,12)`:>\n") self.f.write("x: <:val `str(x)`:>\n") self.f.write("y: <:val `str(y)`:>\n") self.f.write("z: <:val `z+0`:>\n") self.f.close() request=webob.Request.blank('/foo') res=C.stringcomp(self.fname, REQUEST=request) print res self.failUnless('x: None' in res) self.failUnless('y: None' in res) self.failUnless('z: 12' in res)
def testLog3(self): self.f.write('hi there <:try:><:raise `ValueError`:><:except:><:exception "ding dong %s" `4`:><:/try:>') self.f.close() logger=getUserLogger() logger.setLevel(logging.DEBUG) sio=cStringIO.StringIO() logger.addHandler(logging.StreamHandler(sio)) res=C.stringcomp(self.fname) self.failUnless('hi there' in res) v=sio.getvalue() print v self.failUnless('ding dong 4' in v)
def testPre01(self): self.f.write("""<:?pre off?:> <:call ` def foo(x): return x + 100 `:> <:val `foo(100)`:> """) self.f.close() res=C.stringcomp(self.fname) self.failUnless(res=='200')
def serve_stml(path, realpath, statinfo, request): """ handler for stml and Component files. """ try: response = Context.response except AttributeError: response = webob.Response(content_type=Configuration.defaultContentType, charset=Configuration.defaultCharset) body = stringcomp(path, REQUEST=request, RESPONSE=response) # if you set the body of the response yourself, that will # replace anything output by the component. Normally you # won't be doing that in this context. if not response.body: response.body = body return response
def testComp13(self): self.f.write("Hello from me!\n") self.f.close() fd, fname=tempfile.mkstemp(suffix=".comp") try: f=os.fdopen(fd, 'w') f.write(""" I'm going to call a component now. <:component `compname`:> Done. """) f.close() suffixes=C.DEFAULT_FILE_COMPONENT_SUFFIX_MAP.copy() suffixes['.comp']=('string', S.STMLFileComponent) Configuration.load_dict(dict(componentFileSuffixMap=suffixes)) res=C.stringcomp(fname, compname=self.fname) print res self.failUnless('Hello from me!\n' in res) finally: os.unlink(fname)
def render(self, context): data=context_to_dict(context) return stringcomp(self._path, **data)
def html_body(self, environ): tb = self.get_traceback() if Configuration.errorPage: return stringcomp(Configuration.errorPage, traceback=tb) else: return self.default_500_body(tb)
def html_body(self, environ): if Configuration.notFoundPage: return stringcomp(Configuration.notFoundPage, detail=self.detail, comment=self.comment) else: return super(NotFound, self).html_body(environ)
def testPre02(self): self.f.write("<:?pre off?:>\n\n\n\nhi\n\n\n") self.f.close() res=C.stringcomp(self.fname) self.failUnless(res=='hi')