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

Re: [Cheetahtemplate-discuss] #errorCatcher

Expand Messages
  • Mike Orr
    ... It s a bug. I ll give you a quick fix for now, and let Tavis decide how to deal with it in the source. Edit Cheetah/Compiler.py in your installed Cheetah
    Message 1 of 6 , Jan 20, 2002
    • 0 Attachment
      On Mon, Jan 21, 2002 at 01:16:44PM +1100, Huy Do wrote:
      > I have been trying to set the #errorCatcher directive in my template with no
      > success.
      >
      > I have tried the following
      > #from Cheetah.ErrorCatchers import ErrorCatcher
      > #errorCatcher ErrorCatcher
      >
      > which gives me this error when i run cheetah-compile -R -v
      >
      > catcherMeth.addMethDocString('Generated from ' + rawCode +
      > TypeError: cannot concatenate 'str' and 'tuple' objects
      >
      > I only want to use the Cheetah.ErrorCatchers.Echo functionality

      It's a bug. I'll give you a quick fix for now, and let Tavis decide
      how to deal with it in the source.

      Edit Cheetah/Compiler.py in your installed Cheetah package.
      Lines 833-834 look like this:

      catcherMeth.addMethDocString('Generated from ' + rawCode +
      ' at line, col ' + lineCol + '.')

      Put backticks around lineCol so it looks like this:

      catcherMeth.addMethDocString('Generated from ' + rawCode +
      ' at line, col ' + `lineCol` + '.')

      That converts the tuple to a string so it can be concatenated.

      To troubleshoot this, I first went to Cheetah/Test/SyntaxAndOutput.py
      to see if there was a test case showing the correct #errorCatcher usage.
      There wasn't. By memory from my past usage, it seemed like you were
      right. So I went to my temp directory and created x.tmpl:

      =====================
      #from Cheetah.ErrorCatchers import ErrorCatcher
      #errorCatcher ErrorCatcher
      $nonexistentVariable
      ======================

      and then ran "cheetah-compile -R -v". The first time I did it was
      with just the first two lines, not the placeholder line. That compiled
      fine. Then I added the placeholder line and got the same exception you
      did. I ran it again, forcing Python into interactive mode after the
      error:

      $ python -i PYTHON_BIN_DIR/cheetah-compile -R -v

      After it threw the exception and the the Python prompt came back, I
      invoked the debugger:

      import pdb
      pdb.pm()

      'list', 'where' and 'dir()' in pdb isolated the problem to that line.
      I remembered (line, col) looks like a 2-tuple in the generated *.py
      file, so I assumed it was. So it was clear that a tuple was being
      concatenated into a string, a no-no unless you use the % operator
      with the "%s" format.

      --
      -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
      http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Huy Do
      Hi, Can someone tell me how to turn the Echo errorCatcher on by Default. It works (thanks to Mike) when I use the #errorCatcher directive in one tmpl file, but
      Message 2 of 6 , Jan 21, 2002
      • 0 Attachment
        Hi,

        Can someone tell me how to turn the Echo errorCatcher on by Default.

        It works (thanks to Mike) when I use the #errorCatcher directive in one tmpl
        file, but the errorCatcher doesn't seem to be inherited if i then inherit
        this tmpl file.

        I have also tried editing the Template.py file by setting the Default
        errorCatcher parameter to 'Echo' (in __init__), but that still doesn't have
        the desired effect.

        Thanks

        Huy



        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Huy Do
        Hi, Is there a way to set a default errorCatcher (eg. Echo) for all my templates instead of putting the #errorCatcher tag in all my templates. Thanks Huy ...
        Message 3 of 6 , Feb 13, 2002
        • 0 Attachment
          Hi,

          Is there a way to set a default errorCatcher (eg. Echo) for all my templates
          instead of putting the #errorCatcher tag in all my templates.

          Thanks

          Huy

          > -----Original Message-----
          > From: cheetahtemplate-discuss-admin@...
          > [mailto:cheetahtemplate-discuss-admin@...]On Behalf Of
          > Mike Orr
          > Sent: Monday, 21 January 2002 4:00 PM
          > To: Cheetah Template List
          > Subject: Re: [Cheetahtemplate-discuss] #errorCatcher
          >
          >
          > On Mon, Jan 21, 2002 at 01:16:44PM +1100, Huy Do wrote:
          > > I have been trying to set the #errorCatcher directive in my
          > template with no
          > > success.
          > >
          > > I have tried the following
          > > #from Cheetah.ErrorCatchers import ErrorCatcher
          > > #errorCatcher ErrorCatcher
          > >
          > > which gives me this error when i run cheetah-compile -R -v
          > >
          > > catcherMeth.addMethDocString('Generated from ' + rawCode +
          > > TypeError: cannot concatenate 'str' and 'tuple' objects
          > >
          > > I only want to use the Cheetah.ErrorCatchers.Echo functionality
          >
          > It's a bug. I'll give you a quick fix for now, and let Tavis decide
          > how to deal with it in the source.
          >
          > Edit Cheetah/Compiler.py in your installed Cheetah package.
          > Lines 833-834 look like this:
          >
          > catcherMeth.addMethDocString('Generated from ' + rawCode +
          > ' at line, col ' + lineCol + '.')
          >
          > Put backticks around lineCol so it looks like this:
          >
          > catcherMeth.addMethDocString('Generated from ' + rawCode +
          > ' at line, col ' + `lineCol` + '.')
          >
          > That converts the tuple to a string so it can be concatenated.
          >
          > To troubleshoot this, I first went to Cheetah/Test/SyntaxAndOutput.py
          > to see if there was a test case showing the correct #errorCatcher usage.
          > There wasn't. By memory from my past usage, it seemed like you were
          > right. So I went to my temp directory and created x.tmpl:
          >
          > =====================
          > #from Cheetah.ErrorCatchers import ErrorCatcher
          > #errorCatcher ErrorCatcher
          > $nonexistentVariable
          > ======================
          >
          > and then ran "cheetah-compile -R -v". The first time I did it was
          > with just the first two lines, not the placeholder line. That compiled
          > fine. Then I added the placeholder line and got the same exception you
          > did. I ran it again, forcing Python into interactive mode after the
          > error:
          >
          > $ python -i PYTHON_BIN_DIR/cheetah-compile -R -v
          >
          > After it threw the exception and the the Python prompt came back, I
          > invoked the debugger:
          >
          > import pdb
          > pdb.pm()
          >
          > 'list', 'where' and 'dir()' in pdb isolated the problem to that line.
          > I remembered (line, col) looks like a 2-tuple in the generated *.py
          > file, so I assumed it was. So it was clear that a tuple was being
          > concatenated into a string, a no-no unless you use the % operator
          > with the "%s" format.
          >
          > --
          > -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
          > http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol
          >
          > _______________________________________________
          > Cheetahtemplate-discuss mailing list
          > Cheetahtemplate-discuss@...
          > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          >


          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Mike Orr
          ... from Cheetah.Template import Template class MyTemplate(Template): def __init__(self, *args, **kw): kw[ errorCatcher ] = myErrorCatcher()
          Message 4 of 6 , Feb 16, 2002
          • 0 Attachment
            On Thu, Feb 14, 2002 at 02:54:47PM +1100, Huy Do wrote:
            > Is there a way to set a default errorCatcher (eg. Echo) for all my templates
            > instead of putting the #errorCatcher tag in all my templates.

            from Cheetah.Template import Template
            class MyTemplate(Template):
            def __init__(self, *args, **kw):
            kw['errorCatcher'] = myErrorCatcher()
            Template.__init__(self, *args, **kw)

            You would then have to arrange to instantiate your template
            class rather than Template. Easy if you're calling it from
            Python; harder if you're using cheetah-compile. Maybe
            you can use '#extends MyTemplate', although #extends wasn't
            intended for overriding the Template constructor, so there
            may be some gotchas.

            --
            -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
            http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • Mike Orr
            ... That should be myErrorCatcher, not myErrorCatcher(). -- -Mike (Iron) Orr, iron@mso.oz.net (if mail problems: mso@oz.net) http://iron.cx/ English *
            Message 5 of 6 , Feb 16, 2002
            • 0 Attachment
              On Sat, Feb 16, 2002 at 01:42:34AM -0800, wrote:
              > kw['errorCatcher'] = myErrorCatcher()

              That should be myErrorCatcher, not myErrorCatcher().

              --
              -Mike (Iron) Orr, iron@... (if mail problems: mso@...)
              http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol

              _______________________________________________
              Cheetahtemplate-discuss mailing list
              Cheetahtemplate-discuss@...
              https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
            Your message has been successfully submitted and would be delivered to recipients shortly.