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

[Cheetahtemplate-discuss] Weird behavior on $items

Expand Messages
  • deelan
    hi all, yesterday i was using cheetah to generate a static HTML page from an RSS feed and i stumbled upon this weird bahavior of the template engine, i ve a
    Message 1 of 6 , Aug 28, 2003
      hi all,

      yesterday i was using cheetah to generate a static HTML page
      from an RSS feed and i stumbled upon this weird bahavior of the
      template engine, i've a reduced testcase to show the problem, please
      copy/paste:

      # begin ----------------------------------------

      from Cheetah.Template import Template

      tmpl = """
      #for $item in $items
      ($item.date), $item.link, $item.title
      #end for
      """

      items = [{'title':'abc', 'link':'http://someurl.com', 'date':'15jan2003'}]

      namespace = {'items': items}
      t = Template(tmpl, searchList=[namespace])

      print t # output is empty

      # end ------------------------------------------

      on my system the script prints nothing. i'm not
      sure what's the problem, maybe cheetah autocall
      does the wrong guess on that $items variable, maybe
      it calls dict's .items() method?

      to make the script working i need to change $items
      to $feed in the template string and the namespace
      accordingly:
      namespace = {'feed': items}

      can someone explain me what's wrong with my code?

      i'm using python2.3 on win2k SP4.

      TIA



      -------------------------------------------------------
      This sf.net email is sponsored by:ThinkGeek
      Welcome to geek heaven.
      http://thinkgeek.com/sf
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Tracy S. Ruggles
      ... [] I think it s printing the items from the empty dictionary in the search list since it shows up before the items in your own search ... [] -- [{},
      Message 2 of 6 , Aug 28, 2003
        Same result for me (0.9.15) -- and I get an empty list when I do this:

        >>> print Template('$items')
        []

        I think it's printing the 'items' from the empty dictionary in the
        search list since it shows up before the 'items' in your own search
        list:

        >>> print Template('$items --> $SL', searchList=[{'items':'huh?'}])
        [] --> [{}, {'items': 'huh?'}, <Cheetah.Template.Template instance at
        0x7c9890>]

        --T

        On Thursday, August 28, 2003, at 04:37 AM, deelan wrote:

        > hi all,
        >
        > yesterday i was using cheetah to generate a static HTML page
        > from an RSS feed and i stumbled upon this weird bahavior of the
        > template engine, i've a reduced testcase to show the problem, please
        > copy/paste:
        >
        > # begin ----------------------------------------
        >
        > from Cheetah.Template import Template
        >
        > tmpl = """
        > #for $item in $items
        > ($item.date), $item.link, $item.title
        > #end for
        > """
        >
        > items = [{'title':'abc', 'link':'http://someurl.com',
        > 'date':'15jan2003'}]
        >
        > namespace = {'items': items}
        > t = Template(tmpl, searchList=[namespace])
        >
        > print t # output is empty
        >
        > # end ------------------------------------------
        >
        > on my system the script prints nothing. i'm not
        > sure what's the problem, maybe cheetah autocall
        > does the wrong guess on that $items variable, maybe
        > it calls dict's .items() method?
        >
        > to make the script working i need to change $items
        > to $feed in the template string and the namespace
        > accordingly:
        > namespace = {'feed': items}
        >
        > can someone explain me what's wrong with my code?
        >
        > i'm using python2.3 on win2k SP4.
        >
        > TIA
        >
        >
        >
        > -------------------------------------------------------
        > This sf.net email is sponsored by:ThinkGeek
        > Welcome to geek heaven.
        > http://thinkgeek.com/sf
        > _______________________________________________
        > Cheetahtemplate-discuss mailing list
        > Cheetahtemplate-discuss@...
        > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        >



        -------------------------------------------------------
        This sf.net email is sponsored by:ThinkGeek
        Welcome to geek heaven.
        http://thinkgeek.com/sf
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Mike Orr
        ... Tada! The long-standing dict method bug, first discovered by Edmund, strikes again. Tavis and I separately rewrote NameMapper to overcome it, then he got
        Message 3 of 6 , Aug 28, 2003
          On Thu, Aug 28, 2003 at 07:57:17AM -0500, Tracy S. Ruggles wrote:
          > Same result for me (0.9.15) -- and I get an empty list when I do this:
          >
          > >>> print Template('$items')
          > []
          >
          > I think it's printing the 'items' from the empty dictionary in the
          > search list since it shows up before the 'items' in your own search
          > list:
          >
          > >>> print Template('$items --> $SL', searchList=[{'items':'huh?'}])
          > [] --> [{}, {'items': 'huh?'}, <Cheetah.Template.Template instance
          > at 0x7c9890>]

          Tada! The long-standing dict method bug, first discovered by Edmund,
          strikes again. Tavis and I separately rewrote NameMapper to overcome
          it, then he got busy with work and a final version never got finished.

          The workaround until then is to avoid names corresponding to dictionary
          methods.

          The empty dictionary is the '#set globals' dictionary.

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


          -------------------------------------------------------
          This sf.net email is sponsored by:ThinkGeek
          Welcome to geek heaven.
          http://thinkgeek.com/sf
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Edmund Lian
          ... Yup, sure is. I believe there was a fix to the Python version of the Namemapper, but this was removed when Tavis didn t have time to fix the C version. ...
          Message 4 of 6 , Aug 28, 2003
            Mike Orr wrote:

            > Tada! The long-standing dict method bug, first discovered by Edmund,
            > strikes again. Tavis and I separately rewrote NameMapper to overcome
            > it, then he got busy with work and a final version never got finished.
            >
            > The workaround until then is to avoid names corresponding to dictionary
            > methods.

            Yup, sure is. I believe there was a fix to the Python version of the
            Namemapper, but this was removed when Tavis didn't have time to fix the
            C version.

            ...Edmund.



            -------------------------------------------------------
            This sf.net email is sponsored by:ThinkGeek
            Welcome to geek heaven.
            http://thinkgeek.com/sf
            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • deelan
            Mike Orr wrote: (...) ... ahhh, ok, now i got it. thanks for the explanation. hope it will be fixed, sooner or later. :) later, deelan ... This sf.net email is
            Message 5 of 6 , Aug 28, 2003
              Mike Orr wrote:
              (...)
              > Tada! The long-standing dict method bug, first discovered by Edmund,
              > strikes again. Tavis and I separately rewrote NameMapper to overcome
              > it, then he got busy with work and a final version never got finished.

              > The workaround until then is to avoid names corresponding to dictionary
              > methods.
              > The empty dictionary is the '#set globals' dictionary.

              ahhh, ok, now i got it. thanks for
              the explanation. hope it will be fixed,
              sooner or later. :)

              later,
              deelan






              -------------------------------------------------------
              This sf.net email is sponsored by:ThinkGeek
              Welcome to geek heaven.
              http://thinkgeek.com/sf
              _______________________________________________
              Cheetahtemplate-discuss mailing list
              Cheetahtemplate-discuss@...
              https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
            • rtjohan@syspres.com
              Anyone using Cheetah with Spyce? Are there any good Cheetah examples? Even better if example shows how Cheetah is best used for large applications? Thanks,
              Message 6 of 6 , Aug 28, 2003
                Anyone using Cheetah with Spyce?

                Are there any good Cheetah examples?
                Even better if example shows how Cheetah is best used for large
                applications?

                Thanks,
                Richard




                -------------------------------------------------------
                This sf.net email is sponsored by:ThinkGeek
                Welcome to geek heaven.
                http://thinkgeek.com/sf
                _______________________________________________
                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.