Re: NameMapper issues with Google App Engine db.Model objects
"R. Tyler Ballance" <[email protected]> Sat, 14 Aug 2010 13:51:04 -0700
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <20100814205104.GB6853@kiwi> |
On Sat, 14 Aug 2010, Chad George wrote: > In AppEngine, db.Model objects unfortunately implement a "has_key()" > method that checks if a model instance has had a key assigned to it > yet. > > This causes NameMapper.py to determine that it should use dictionary > style access instead of getattr(). I /think/ you can circumvent this functionality by disabling autocalling, I've not used AppEngine, but you might try that: http://cheetahtemplate.org/docs/users_guide_html_multipage/language.namemapper.autocalling.html > > I think there are two possible solutions: > 1. use hasattr(obj, "keys") instead of hasattr(obj, "has_key") > 2. try to use hasattr()/getattr() ... before trying dictionary access > > I tested #1 and it seems to work...but I'm too new to Cheetah to know > if there are unintended consequences > > For #2 the biggest issue I see is in _valueForName() ... you > definitely don't want to hit the exception on every access to a > dictionary, so you'd need another call to hasattr() ... which > presumably was just done before getting to _valueForName() in the > first place. > > Probably not a big deal either way. I'm not sure if there was a > pre-existing design decision to try dictionary access before attribute > access. > > - Chad > > ------------------------------------------------------------------------------ > This SF.net email is sponsored by > > Make an app they can't live without > Enter the BlackBerry Developer Challenge > http://p.sf.net/sfu/RIM-dev2dev > _______________________________________________ > Cheetahtemplate-discuss mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss Cheers, -R. Tyler Ballance -------------------------------------- GitHub: http://github.com/rtyler Twitter: http://twitter.com/agentdero ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-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.16 (GNU/Linux) iEYEARECAAYFAkxnAbgACgkQFCbH3D9R4W/swgCfbLlH7H8BvftrCBwljZAzGZdL o2wAoKJcgb3vt94Lj0ni/vcf58QhWWf0 =8UdL -----END PGP SIGNATURE-----