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

[Cheetahtemplate-discuss] Single triple quotes disappear?

Expand Messages
  • Tim Lesher
    [Python 2.4.2, Cheetah 2.0rc7, WinXP] I m running Cheetah to generate Python code. I m running into an issue with a template that looks like this: def a(arg):
    Message 1 of 5 , Aug 31, 2006
    • 0 Attachment
      [Python 2.4.2, Cheetah 2.0rc7, WinXP]

      I'm running Cheetah to generate Python code. I'm running into an
      issue with a template that looks like this:


      def a(arg):
      """Docstring for a."""
      return arg

      def b(arg):
      "Docstring for b."
      return arg

      def c(arg):
      '''Docstring for c.'''
      return arg

      def d(arg):
      'Docstring for d.'
      return arg

      After compiling and running the template, each docstring comes through
      fine except for function c's. Cheetah strips the quotes altogether,
      turning it into this:

      def c(arg):
      Docstring for c.
      return arg

      I searched the docs and mailing list, but I haven't found any
      reference to this phenomenon. I've tested it with both Cheetah 1.0
      and Cheetah 2.0rc7. Is this a bug?

      --
      Tim Lesher <tlesher@...>

      -------------------------------------------------------------------------
      Using Tomcat but need to do more? Need to support web services, security?
      Get stuff done quickly with pre-integrated technology to make your job easier
      Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
      http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Tavis Rudd
      Hi Tom, it sounds like a bug. How are you compiling the template? Tavis ... Using Tomcat but need to do more? Need to support web services, security? Get
      Message 2 of 5 , Aug 31, 2006
      • 0 Attachment
        Hi Tom,
        it sounds like a bug. How are you compiling the template?
        Tavis

        On Thursday 31 August 2006 11:28 am, Tim Lesher wrote:
        > [Python 2.4.2, Cheetah 2.0rc7, WinXP]
        >
        > I'm running Cheetah to generate Python code. I'm running into an
        > issue with a template that looks like this:
        >
        >
        > def a(arg):
        > """Docstring for a."""
        > return arg
        >
        > def b(arg):
        > "Docstring for b."
        > return arg
        >
        > def c(arg):
        > '''Docstring for c.'''
        > return arg
        >
        > def d(arg):
        > 'Docstring for d.'
        > return arg
        >
        > After compiling and running the template, each docstring comes through
        > fine except for function c's. Cheetah strips the quotes altogether,
        > turning it into this:
        >
        > def c(arg):
        > Docstring for c.
        > return arg
        >
        > I searched the docs and mailing list, but I haven't found any
        > reference to this phenomenon. I've tested it with both Cheetah 1.0
        > and Cheetah 2.0rc7. Is this a bug?

        -------------------------------------------------------------------------
        Using Tomcat but need to do more? Need to support web services, security?
        Get stuff done quickly with pre-integrated technology to make your job easier
        Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
        http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Mike Orr
        ... Cheetah is indeed miscompiling it. This is probably an oversight, thinking nobody would use all four of Python s quoting styles in the same template.
        Message 3 of 5 , Aug 31, 2006
        • 0 Attachment
          On 8/31/06, Tim Lesher <tlesher@...> wrote:
          > [Python 2.4.2, Cheetah 2.0rc7, WinXP]
          >
          > I'm running Cheetah to generate Python code. I'm running into an
          > issue with a template that looks like this:
          >
          >
          > def a(arg):
          > """Docstring for a."""
          > return arg
          >
          > def b(arg):
          > "Docstring for b."
          > return arg
          >
          > def c(arg):
          > '''Docstring for c.'''
          > return arg
          >
          > def d(arg):
          > 'Docstring for d.'
          > return arg
          >
          > After compiling and running the template, each docstring comes through
          > fine except for function c's. Cheetah strips the quotes altogether,
          > turning it into this:
          >
          > def c(arg):
          > Docstring for c.
          > return arg
          >
          > I searched the docs and mailing list, but I haven't found any
          > reference to this phenomenon. I've tested it with both Cheetah 1.0
          > and Cheetah 2.0rc7. Is this a bug?


          Cheetah is indeed miscompiling it. This is probably an oversight,
          thinking nobody would use all four of Python's quoting styles in the
          same template. Cheetah is putting the text in a ''' string literal in
          the compiled template. It's converting the ''' docstring to ''''.
          What it should do, I'm not sure. Add backslashes?

          I tried changing the ''' to \'\'\', but that put that literally in the
          output. Using \''' resulted in \ in the output.

          The easiest workaround is to just use """, as 99.9% of Python
          docstrings do. I only use ''' to block out large sections of code I
          don't want to execute. Second easiest is to use """# to open and """
          to close, then run the output through a regex substitution thus:

          rx = re.compile( R'"""#(.*?)""" )
          output = template.respond()
          output = rx.sub( R"'''\1'''" , output)

          --
          Mike Orr <sluggoster@...>

          -------------------------------------------------------------------------
          Using Tomcat but need to do more? Need to support web services, security?
          Get stuff done quickly with pre-integrated technology to make your job easier
          Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
          http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Tim Lesher
          ... Heh. It s not really a question of using all four in one template. It happened on code that used only single triple quotes; I added the other three cases
          Message 4 of 5 , Aug 31, 2006
          • 0 Attachment
            On 8/31/06, Mike Orr <sluggoster@...> wrote:
            > Cheetah is indeed miscompiling it. This is probably an oversight,
            > thinking nobody would use all four of Python's quoting styles in the
            > same template.

            Heh. It's not really a question of using all four in one template.
            It happened on code that used only single triple quotes; I added the
            other three cases to see if any other docstring formats would have
            similar problems. Still, it sounds like a reasonable unit test.

            > Cheetah is putting the text in a ''' string literal in
            > the compiled template. It's converting the ''' docstring to ''''.
            > What it should do, I'm not sure. Add backslashes?

            That would be my suggestion. PyDoc has this bug, too:

            http://sourceforge.net/tracker/index.php?func=detail&aid=1185124&group_id=5470&atid=105470

            > The easiest workaround is to just use """, as 99.9% of Python
            > docstrings do.

            Yes, as PEP-257 suggests (and all of the standard Python libraries do).

            Somehow along the way I adopted single-triple-quotes as my own style,
            and only recently found out that '257 suggests otherwise. But that's
            my own problem. :-)

            --
            Tim Lesher <tlesher@...>

            -------------------------------------------------------------------------
            Using Tomcat but need to do more? Need to support web services, security?
            Get stuff done quickly with pre-integrated technology to make your job easier
            Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
            http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • Raphael MARVIE
            Hi, I have the same problem on code such as: data_template = # -*- coding: utf-8 -*- # # data # Specify and document your data object definitions #
            Message 5 of 5 , Aug 31, 2006
            • 0 Attachment
              Hi,

              I have the same problem on code such as:

              data_template = """# -*- coding: utf-8 -*-
              #
              # data
              #

              '''
              Specify and document your data object definitions
              ''''

              # eof
              """

              that fails while reversing """ and ''' works.

              And I have the same approach and conclusion as Tim... Good to see I was
              not alone :-)

              r.

              Tim Lesher wrote:
              [snip]

              >> The easiest workaround is to just use """, as 99.9% of Python
              >> docstrings do.
              >
              > Yes, as PEP-257 suggests (and all of the standard Python libraries do).
              >
              > Somehow along the way I adopted single-triple-quotes as my own style,
              > and only recently found out that '257 suggests otherwise. But that's
              > my own problem. :-)


              --
              Raphael Marvie, PhD http://www.lifl.fr/~marvie/
              Maître de Conférences / Associate Professor @ LIFL -- IRCICA
              Directeur du Master Informatique Professionnel spécialité IAGL
              Head of Master's in Software Engineering +33 3 28 77 85 83

              -------------------------------------------------------------------------
              Using Tomcat but need to do more? Need to support web services, security?
              Get stuff done quickly with pre-integrated technology to make your job easier
              Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
              http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
              _______________________________________________
              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.