Re: how do we get psp style tags working in cheetah
"R. Tyler Ballance" <[email protected]> Sat, 19 Dec 2009 14:16:25 -0800
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
On Sat, 19 Dec 2009, [email protected] wrote: > <% > me = self.getVar('me') > tmpsave = False > if me.health<0: > me.health = 10 > tmpsave = True > if me.bucks<=0: > me.bucks=100 > tmpsave = True > if tmpsave:me.save() > %> I'm not sure if the error you've been getting has something to do with Cheetah so much as it has to do with the __setattr__ hackery you're doing in "ffa.py" I've written the following testcase which passes just fine: class PSPTest(unittest.TestCase): def runTest(self): template = '''This is my template <% me = self.getVar('me') if isinstance(me, int): write('Bork') else: write('Nork') %>''' tmpl = Template.Template.compile(template) assert isinstance(tmpl, type) tmpl = tmpl(searchList=[{'me' : 1}]) assert isinstance(tmpl, Template.Template) self.assertEquals('This is my template\nBork', unicode(tmpl)) When you're delving into overwriting __setattr__, beware, there be monsters ;) Cheers, -R. Tyler Ballance -------------------------------------- Jabber: [email protected] GitHub: http://github.com/rtyler Twitter: http://twitter.com/agentdero Blog: http://unethicalblogger.com > On Sat, Dec 19, 2009 at 12:28 AM, R. Tyler Ballance <[email protected]>wrote: > > > > > On Fri, 18 Dec 2009, [email protected] wrote: > > > > > File "/home/mark/work/common/web/cheetah.py", line 104, in render > > > return str(compiled_tmpl) > > > File > > > > > "/usr/lib/python2.5/site-packages/Cheetah-2.0.1-py2.5-linux-x86_64.egg/Cheetah/Template.py", > > > line 982, in __str__ > > > def __str__(self): return getattr(self, mainMethName)() > > > File "<string>", line 2480, in respond > > > File "/home/mark/work/ffa.py", line 112, in __setattr__ > > > object.__setattr__(self,key,value) > > > AttributeError: can't set attribute" while reading upstream, > > > > > > *doesnt work* > > > > What code are you running to produce this? > > > > > > On Wed, Dec 16, 2009 at 12:50 PM, <[email protected]> wrote: > > > > > > > *This doesnt work* > > > > <% > > > > tmpsave = False > > > > if me.health<0: > > > > me.health = 10 > > > > tmpsave = True > > > > if me.bucks<=0: > > > > me.bucks=100 > > > > tmpsave = True > > > > if tmpsave:me.save() > > > > > > > > %> > > > > > > > > *error global variable me not found* > > > > * > > > > * > > > > * > > > > * > > > > *This works* > > > > > > > > #set tmpsave = False > > > > #if $me.health<0 > > > > #set $me.health = 10 > > > > #set tmpsave = True > > > > #end if > > > > if me.bucks<=0 > > > > #set me.bucks=100 > > > > #set tmpsave = True > > > > #end if > > > > #if tmpsave > > > > $me.save() > > > > #end if > > > > ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Cheetahtemplate-discuss mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.12 (GNU/Linux) iEYEARECAAYFAkstULgACgkQFCbH3D9R4W88nQCcCfVbFG2lIFisO0KIw17+2EVr X5sAoJSu0eulfj16LUGTxmXTKWQzg39+ =EcvL -----END PGP SIGNATURE-----