Re: Feedback Needed! Changing how Cheetah handles imports
"R. Tyler Ballance" <[email protected]>
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Apr 16, 2009 at 02:34:21PM -0700, R. Tyler Ballance wrote:
> Since this issue has come up (see thread started by Martin Skott) with
> regards to how newer versions of Cheetah are handling the #import
> statement.
>
> In CVS versions of Cheetah (i.e. v2.0.1 and earlier), all #import
> directives were collected and *moved* to the top of the generated Python
> code for the template. This means things like this:
The middle-ground I'm going to settle on for the release of v2.1.1 is
the introduction of a new compiler setting: useLegacyImportMode
In 2.1.1 this will be defaulted to True, this means that in order to
handle inline imports, you should compile your code with
"useLegacyImportMode=False".
WARNING: In future versions of Cheetah, I *will* be switching this
setting to default to False.
Tests are passing, I'm tagging the v2.1.1 release
>
> #import sys
> ## This is a crazy template
> #set $foo = 'bar'
> #import cjson
>
> #def method()
> #import simplejson
> #return simplejson.dumps({'foo' : 'bar'})
> #end def
>
> Generates code like this:
>
> import sys
> import cjson
> import simplejson
>
> class test(Template):
> def writeBody(self):
> ## This is a crazy template
> foo = 'bar'
>
> def method(self):
> return simplejson.dumps({'foo' : 'bar'})
>
>
> In Cheetah v2.1.xx this behavior has been changed to support proper
> inline imports (I think the "magic global import namespace" is a bad
> idea and restricts the power of what you can do within Cheetah)
>
> The code above would generate something like this instead:
>
> import sys
>
> class test(Template):
> def writeBody(self):
> ## This is a crazy template
> foo = 'bar'
> import cjson
>
> def method(self):
> import simplejson
> return simplejson.dumps({'foo' : 'bar'})
>
>
>
> There are a couple things at play here, firstly anything outside of a
> defined function, effectively falls into the "default method" which is
> writeBody(). Secondly I think it's important to support inline imports
> the same way Cheetah supports generate scoping of variables.
>
>
> I think the only solution we have is to use a compile-time setting for
> this, it's quite the "damned if you do, damned if you don't" scenario.
>
> The decision to be made between "us" as the community is which we want
> to be the *default* behavior:
> 1: Non-scoping import behavior (2.0.1 and earlier)
> 2: Scoping/inline import behavior.(2.1.0 and later)
>
>
> My personal vote is for #2 being the default behavior since it follows
> Python importing semantics closely (we also have updated our templates
> at Slide to avoid the issue Martin Skott describes).
>
>
> What say ye all? :)
>
> --
> -R. Tyler Ballance
> Slide, Inc.
> ------------------------------------------------------------------------------
> Stay on top of everything new and different, both inside and
> around Java (TM) technology - register by April 22, and save
> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
> 300 plus technical and hands-on sessions. Register today.
> Use priority code J9JMT32. http://p.sf.net/sfu/p
> _______________________________________________
> Cheetahtemplate-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
--
-R. Tyler Ballance
Slide, Inc.
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
signature.asc
(application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAknoCpwACgkQFCbH3D9R4W/4CgCcCn0IEP9xpSs18D4rQeiG5Mm7 NjMAoIM7gnsksiTDNfX9oXeVq5A+12hn =JdS8 -----END PGP SIGNATURE-----