Loading ...
Sorry, an error occurred while loading the content.

[Cheetahtemplate-discuss] [PATCH] Add a test to verify the failure we're seeing with regards to nesting import statements inside of #try/#end try blocks

Expand Messages
  • R. Tyler Ballance
    tyler@grapefruit:~/source/github/cheetah/src python Tests/Template.py TryExceptImportTest
    Message 1 of 3 , Jan 5, 2009
    • 0 Attachment
      tyler@grapefruit:~/source/github/cheetah/src> python Tests/Template.py TryExceptImportTest
      /home/tyler/source/github/cheetah/build/lib.linux-x86_64-2.6/Cheetah/CacheRegion.py:30: DeprecationWarning: the md5 module is deprecated; use hashlib instead
      import md5
      E
      **********************************************************************
      ERROR __main__.TryExceptImportTest.test_FailCase ()
      ----------------------------------------------------------------------
      Traceback (most recent call last):
      File "Tests/Template.py", line 321, in test_FailCase
      klass = Template.compile(source=source)
      File "/home/tyler/source/github/cheetah/build/lib.linux-x86_64-2.6/Cheetah/Template.py", line 779, in compile
      raise parseError
      ParseError:

      Error in the Python code which Cheetah generated for this template:
      ================================================================================

      expected an indented block (DynamicallyCompiledCheetahTemplate.py, line 91)

      Line|Python Code
      ----|-------------------------------------------------------------
      89 |''')
      90 | try: # generated from line 5, col 17
      91 | except ImportError: # generated from line 7, col 17
      ^
      92 | _v = VFFSL(SL,"print",True) # '$print' on line 8, col 21
      93 | if _v is not None: write(_filter(_v, rawExpr='$print')) # from line 8, col 21.
      94 | write(''' "This will never happen!"

      ================================================================================

      Here is the corresponding Cheetah code:

      Line 7, column 17

      Line|Cheetah Code
      ----|-------------------------------------------------------------
      4 | Ahoy!
      5 | #try
      6 | #import sys
      7 | #except ImportError
      ^
      8 | $print "This will never happen!"
      9 | #end try
      10 | #end def

      ----------------------------------------------------------------------
      Ran 1 tests in 0.031s

      FAILED (errors=1)
      tyler@grapefruit:~/source/github/cheetah/src>
      ---
      src/Tests/Template.py | 20 ++++++++++++++++++++
      1 files changed, 20 insertions(+), 0 deletions(-)

      diff --git a/src/Tests/Template.py b/src/Tests/Template.py
      index b97cf5d..d95b507 100644
      --- a/src/Tests/Template.py
      +++ b/src/Tests/Template.py
      @@ -305,6 +305,26 @@ class Preprocessors(TemplateTest):
      assert str(t)==('This is a bit of text that needs translation\n'*2)[:-1]


      +class TryExceptImportTest(TemplateTest):
      + def test_FailCase(self):
      + source = '''
      +
      + #def myFunction()
      + Ahoy!
      + #try
      + #import sys
      + #except ImportError
      + $print "This will never happen!"
      + #end try
      + #end def
      + '''
      + klass = Template.compile(source=source)
      + print klass
      + t = klass(namespaces={'foo' : 1234})
      +
      +
      +
      +
      ##################################################
      ## if run from the command line ##

      --
      1.6.0.2


      ------------------------------------------------------------------------------
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • mobiledreamers@gmail.com
      is this patch applied ... -- Bidegg worlds best auction site http://bidegg.com ... Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
      Message 2 of 3 , Mar 14, 2009
      • 0 Attachment
        is this patch applied

        On 1/5/09, R. Tyler Ballance <tyler@...> wrote:

        Files changed:
               M       src/Compiler.py
               M       src/Tests/Template.py

        The following two patches are meant to fix broken behavior with #import
        particularly when wrapped within #try/#except/#end try blocks in Cheetah
        templates.

        Take the following markup for example:
               #try
                               #import cjson
               #except ImportError
                               #import simplejson
               #end try

        Before the addition of the patch, this is what would be generated:
               import cjson
               import simplejson

               try:
               except ImportError

        Cheetah will now generate this code instead:
               try:
                               import cjson
               except ImportError:
                               import simplejson

        I generated the series of patches against my Git clone of the Cheetah
        CVS tree (https://github.com/rtyler/cheetah/tree) in case anybody is
        interesting in working with Cheetah in Git :)

        I'd appreciate any comments, testing and/or code review any of you
        seasoned Cheetah developers have to offer, as this is clearly my first
        Cheetah patch ;)


        Cheers,
        -R. Tyler Ballance

        ------------------------------------------------------------------------------
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss



        --
        Bidegg worlds best auction site
        http://bidegg.com
      Your message has been successfully submitted and would be delivered to recipients shortly.