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

[Cheetahtemplate-discuss] [PATCH] Fix test, and correct the error cast in the compiler

Expand Messages
  • R. Tyler Ballance
    Cheetah markup like this: #try #import cjson #except ImportError #import simplejson #end try Will now appropriately generate this code: try: import cjson
    Message 1 of 2 , Jan 5, 2009
    • 0 Attachment
      Cheetah markup like this:
      #try
      #import cjson
      #except ImportError
      #import simplejson
      #end try

      Will now appropriately generate this code:
      try:
      import cjson
      except ImportError:
      import simplejson

      Instead of what it previously generated:
      import cjson
      import simplejson

      try:
      except ImportError

      Signed-off-by: R. Tyler Ballance <tyler@...>
      ---
      src/Compiler.py | 2 +-
      src/Tests/Template.py | 4 ++--
      2 files changed, 3 insertions(+), 3 deletions(-)

      diff --git a/src/Compiler.py b/src/Compiler.py
      index a2fc7e5..cc1c94e 100644
      --- a/src/Compiler.py
      +++ b/src/Compiler.py
      @@ -1712,7 +1712,7 @@ class ModuleCompiler(SettingsManager, GenUtils):
      return self._importedVarNames

      def addImportedVarNames(self, varNames):
      - self._importedVarNames.extend(varNames)
      + self.addChunk('import %s' % ', '.join(varNames))

      ## methods for adding stuff to the module and class definitions

      diff --git a/src/Tests/Template.py b/src/Tests/Template.py
      index d95b507..c8b6ee8 100644
      --- a/src/Tests/Template.py
      +++ b/src/Tests/Template.py
      @@ -307,8 +307,8 @@ class Preprocessors(TemplateTest):

      class TryExceptImportTest(TemplateTest):
      def test_FailCase(self):
      + ''' Test situation where an inline #import statement will get relocated '''
      source = '''
      -
      #def myFunction()
      Ahoy!
      #try
      @@ -318,8 +318,8 @@ class TryExceptImportTest(TemplateTest):
      #end try
      #end def
      '''
      + # This should raise an IndentationError (if the bug exists)
      klass = Template.compile(source=source)
      - print klass
      t = klass(namespaces={'foo' : 1234})


      --
      1.6.0.2


      ------------------------------------------------------------------------------
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • R. Tyler Ballance
      Looks like my cover letter got gobbled up in transit, here it is anyways ... From R. Tyler Ballance Subject: Patch to fix broken #import
      Message 2 of 2 , Jan 5, 2009
      • 0 Attachment
        Looks like my cover letter got gobbled up in transit, here it is anyways
        --------------------------------------------------------------------------


        From R. Tyler Ballance <tyler@...>
        Subject: Patch to fix broken #import behavior

        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 ;)


        --
        -R. Tyler Ballance
        Slide, Inc.
      Your message has been successfully submitted and would be delivered to recipients shortly.