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

[Cheetahtemplate-discuss] Weird Searchlist bug?

Expand Messages
  • Peter Mott
    The program below hangs: from Cheetah.Template import Template SL = [{ items :[1,2,3]}] tmpl = #for $i in $items $i #end for t = Template(source=tmpl,
    Message 1 of 3 , Sep 6, 2005

      The program below hangs:

       

      from Cheetah.Template import Template

       

      SL = [{"items":[1,2,3]}]

       

      tmpl = """

       #for $i in $items

       $i

       #end for """

       

      t = Template(source=tmpl, searchList=SL)

      print t 

       

      However if the identifier ‘items’ is replaced by the identifier ‘things’ the program behaves as expected.

       

      Peter

    • mso@oz.net
      ... There s a bug in Cheetah regarding placeholders with the same name as dictionary methods. The wrong value is found, from a hidden dictionary used to
      Message 2 of 3 , Sep 6, 2005
        Peter Mott wrote:
        > The program below hangs:
        >
        >
        >
        > from Cheetah.Template import Template
        >
        >
        >
        > SL = [{"items":[1,2,3]}]
        >
        >
        >
        > tmpl = """
        >
        > #for $i in $items
        >
        > $i
        >
        > #end for """
        >
        >
        >
        > t = Template(source=tmpl, searchList=SL)
        >
        > print t
        >
        >
        >
        > However if the identifier 'items' is replaced by the identifier 'things'
        > the
        > program behaves as expected.

        There's a bug in Cheetah regarding placeholders with the same name as
        dictionary methods. The wrong value is found, from a hidden dictionary
        used to implement '#set global'. See Mapping Types in the Python Library
        Reference for a list of dict methods. 'update' is the one people most
        commonly use.

        Curiously, I get different behavior depending how the template is
        instantiated.

        - Using source= as Peter did, I get an infinite recursion.
        - Using file=, the output is the path of the template file.
        - Using a precompiled template, the output is locals().items() of the
        template's main method.

        These are probably just q

        --
        -- Mike Orr <mso@...>



        -------------------------------------------------------
        SF.Net email is Sponsored by the Better Software Conference & EXPO
        September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
        Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
        Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • mso@oz.net
        ... There s a bug in Cheetah with placeholders named the same as a dictionary method. Cheetah sees the hidden dict used to implement #set global and thinks
        Message 3 of 3 , Sep 6, 2005
          Peter Mott wrote:
          > The program below hangs:
          >
          >
          >
          > from Cheetah.Template import Template
          >
          >
          >
          > SL = [{"items":[1,2,3]}]
          >
          >
          >
          > tmpl = """
          >
          > #for $i in $items
          >
          > $i
          >
          > #end for """
          >
          >
          >
          > t = Template(source=tmpl, searchList=SL)
          >
          > print t
          >
          >
          >
          > However if the identifier 'items' is replaced by the identifier 'things'
          > the
          > program behaves as expected.

          There's a bug in Cheetah with placeholders named the same as a dictionary
          method. Cheetah sees the hidden dict used to implement '#set global' and
          thinks it has found the value. There's a list of dict methods in the
          "Mapping Types" section of the Python Library Reference. Avoid those.
          $update is the most common one.

          Curiously, I get different output depending on how the template was
          instantiated.

          - With source= as Peter did, I get an infinite recursion error.
          - With file=, the output is the path of the template file.
          - With a precompiled template, the output is locals().items() of the
          template's main method.

          These are presumably due to quirks in how the three modes are implemented.

          --
          -- Mike Orr <mso@...>



          -------------------------------------------------------
          SF.Net email is Sponsored by the Better Software Conference & EXPO
          September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
          Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
          Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
          _______________________________________________
          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.