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

[Cheetahtemplate-discuss] Bug? Was: Really basic searchList question

Expand Messages
  • Edmund Lian
    I m not sure yet, but I think there s an bug in the template instantiation process when Cheetah is used with Webware via containment... The following code
    Message 1 of 9 , Aug 30, 2002
    • 0 Attachment
      I'm not sure yet, but I think there's an bug in the template instantiation
      process when Cheetah is used with Webware via containment...

      The following code shows that objects that are supplied to the template at
      instantiation are being lost...

      When I insert a print statement after line 164 in Cheetah.Template to check
      that the searchList is being extended correctly, it is. It shows that
      {'test': 'hello'} and <default.elian.TestProperty.TestClass object at
      0x82adb64> are being added to the searchList. So it is sometime after the
      searchList is extended that it is incorrectly modified. I've yet to pin
      down why or where this is happening.


      ...Edmund.


      Code
      ----
      #!/usr/bin/env python

      from Cheetah.Template import Template
      from SiteLib.Page import Page

      class TestProperty(Page):

      def writeHTML(self):
      obj = TestClass()
      t = Template(file="/web/dev/webware/Contexts/elian/TByProperty.tmpl", \
      searchList= [{'test': 'hello'}, obj])
      print 'At instantiation', t._searchList
      t.addToSearchList({'test': 'hello'})
      print 'Added dict', t._searchList
      t.addToSearchList(obj)
      print 'Added object', t._searchList
      t.addToSearchList({'moon':'shot'})
      print 'Added another dict', t._searchList
      self.writeln(str(t))

      class TestClass(object):
      def __init__(self):
      self.test = 'apple'

      def test(self):
      return 'apple'

      Debugging Output
      ----------------
      At instantiation [{}, <Cheetah.Parser.GenTemplate instance at 0x836853c>]
      Added dict [{}, <Cheetah.Parser.GenTemplate instance at 0x836853c>,
      {'test': 'hello'}]
      Added object [{}, <Cheetah.Parser.GenTemplate instance at 0x836853c>,
      {'test': 'hello'}, <default.elian.TestProperty.TestClass object at
      0x831a2d4>]
      Added another dict [{}, <Cheetah.Parser.GenTemplate instance at 0x836853c>,
      {'test': 'hello'}, <default.elian.TestProperty.TestClass object at
      0x831a2d4>, {'moon': 'shot'}]



      -------------------------------------------------------
      This sf.net email is sponsored by: OSDN - Tired of that same old
      cell phone? Get a new here for FREE!
      https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Tavis Rudd
      Edmund, there s definitely something wrong with your installation, but I m not sure about there being a bug. I ran a simplified version of your test code on
      Message 2 of 9 , Aug 30, 2002
      • 0 Attachment
        Edmund,
        there's definitely something wrong with your installation, but I'm not sure
        about there being a bug. I ran a simplified version of your test code on
        Linux and FreeBSD from the command line and from expWebware and it worked
        perfectly.

        What sort of system are you running this on? os, python version, cheetah
        version, webware version, etc.

        What's in TByProperty.tmpl? What classes does it inherit from?

        Would you mind trying the following?

        ## test.py
        ###############################
        from WebKit.Servlet import Servlet
        from Cheetah.Template import Template

        class TestClass(object):
        def __init__(self):
        self.test = 'apple'

        def test(self):
        return 'apple'


        class test(Servlet):
        def respond(self, trans):
        obj = TestClass()
        t = Template(file=ABSOLUTE_PATH_TO_TMPL_FILE,
        searchList= [{'test': 'hello'}, obj])

        print 'At instantiation', t.searchList()
        t.addToSearchList({'test': 'hello'})
        print
        print 'Added dict', t.searchList()
        t.addToSearchList(obj)
        print
        print 'Added object', t.searchList()
        t.addToSearchList({'moon':'shot'})
        print
        print 'Added another dict', t.searchList()
        trans.response().writeln(str(t))
        import sys
        sys.stdout.flush()
        #######################

        ## test.tmpl
        #######################
        This is a test
        #######################




        -------------------------------------------------------
        This sf.net email is sponsored by: OSDN - Tired of that same old
        cell phone? Get a new here for FREE!
        https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Tavis Rudd
        ... Ahh, yes there is a bug. When you feed the Template() constructor a template file that subclasses another template, your manipulations of the searchList
        Message 3 of 9 , Aug 30, 2002
        • 0 Attachment
          On August 30, 2002 10:04 am, Tavis Rudd wrote:
          > Edmund,
          > there's definitely something wrong with your installation, but I'm not sure
          > about there being a bug. I ran a simplified version of your test code on
          > Linux and FreeBSD from the command line and from expWebware and it worked
          > perfectly.

          Ahh, yes there is a bug. When you feed the Template() constructor a template
          file that subclasses another template, your manipulations of the searchList
          get discarded when file is compiled. See line 1505 of Parser.py.
          ##############
          if self._templateObj:
          mod =
          self._templateObj._importAsDummyModule('\n'.join(self._importStatements))
          class newClass:
          pass
          newClass.__name__ = self._mainClassName
          __bases__ = (getattr(mod, self._baseClass), )
          newClass.__bases__ = __bases__
          self._templateObj.__class__ = newClass
          # must initialize it so instance attributes are accessible
          newClass.__init__(self._templateObj)

          This bit of code is dynamically reinitializing the live templateObj, which has
          the effect of discarding the original searchList, filters, and probably the
          settings dict. This is going to take some thought!

          Tavis


          -------------------------------------------------------
          This sf.net email is sponsored by: OSDN - Tired of that same old
          cell phone? Get a new here for FREE!
          https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Edmund Lian
          ... template ... searchList ... has ... the ... I was just writing a message to tell you that I just cut all my templates to barebones to eliminate all other
          Message 4 of 9 , Aug 30, 2002
          • 0 Attachment
            On 08/30/2002 01:45:04 PM Tavis Rudd wrote:

            >Ahh, yes there is a bug. When you feed the Template() constructor a
            template
            >file that subclasses another template, your manipulations of the
            searchList
            >get discarded when file is compiled. See line 1505 of Parser.py.
            >##############
            > if self._templateObj:
            > mod =
            >self._templateObj._importAsDummyModule('\n'.join(self._importStatements))
            > class newClass:
            > pass
            > newClass.__name__ = self._mainClassName
            > __bases__ = (getattr(mod, self._baseClass), )
            > newClass.__bases__ = __bases__
            > self._templateObj.__class__ = newClass
            > # must initialize it so instance attributes are accessible
            > newClass.__init__(self._templateObj)
            >
            >This bit of code is dynamically reinitializing the live templateObj, which
            has
            >the effect of discarding the original searchList, filters, and probably
            the
            >settings dict. This is going to take some thought!

            I was just writing a message to tell you that I just cut all my templates
            to barebones to eliminate all other sources of error, and have discovered
            that they templates were failing whenever they used #extends!!!

            And if you insert a print statement in Template.py to print out the
            searchList, you'll see that each template gets instantiated twice. The
            first time, searchList prints out as expected. The next time, it's just an
            empty list. This must be the dynamic reinitialization of the live template
            object, as you say.

            Good! I thought I was going crazy! How is it nobody else noticed this? I
            thought people quite a few people were using containment?

            ...Edmund.



            -------------------------------------------------------
            This sf.net email is sponsored by: OSDN - Tired of that same old
            cell phone? Get a new here for FREE!
            https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • Mike Orr
            ... So a workaround would be to use a precompiled template for the top level, no? ... Hmm, could it call a .warmInit method instead of .__init__ and do a
            Message 5 of 9 , Aug 30, 2002
            • 0 Attachment
              On Fri, Aug 30, 2002 at 10:45:04AM -0700, Tavis Rudd wrote:
              > Ahh, yes there is a bug. When you feed the Template() constructor a template
              > file that subclasses another template, your manipulations of the searchList
              > get discarded when file is compiled. See line 1505 of Parser.py.

              So a workaround would be to use a precompiled template for the top
              level, no?

              > ##############
              > if self._templateObj:
              > mod =
              > self._templateObj._importAsDummyModule('\n'.join(self._importStatements))
              > class newClass:
              > pass
              > newClass.__name__ = self._mainClassName
              > __bases__ = (getattr(mod, self._baseClass), )
              > newClass.__bases__ = __bases__
              > self._templateObj.__class__ = newClass
              > # must initialize it so instance attributes are accessible
              > newClass.__init__(self._templateObj)
              >
              > This bit of code is dynamically reinitializing the live templateObj, which has
              > the effect of discarding the original searchList, filters, and probably the
              > settings dict. This is going to take some thought!

              Hmm, could it call a .warmInit method instead of .__init__ and do a partial
              initialization?

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


              -------------------------------------------------------
              This sf.net email is sponsored by: OSDN - Tired of that same old
              cell phone? Get a new here for FREE!
              https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
              _______________________________________________
              Cheetahtemplate-discuss mailing list
              Cheetahtemplate-discuss@...
              https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
            • Tavis Rudd
              ... Yes, or just manipulate the searchList after the template has been compiled. ... This sf.net email is sponsored by: OSDN - Tired of that same old cell
              Message 6 of 9 , Aug 30, 2002
              • 0 Attachment
                On August 30, 2002 11:09 am, Mike Orr wrote:
                > On Fri, Aug 30, 2002 at 10:45:04AM -0700, Tavis Rudd wrote:
                > > Ahh, yes there is a bug. When you feed the Template() constructor a
                > > template file that subclasses another template, your manipulations of the
                > > searchList get discarded when file is compiled. See line 1505 of
                > > Parser.py.
                >
                > So a workaround would be to use a precompiled template for the top
                > level, no?

                Yes, or just manipulate the searchList after the template has been compiled.



                -------------------------------------------------------
                This sf.net email is sponsored by: OSDN - Tired of that same old
                cell phone? Get a new here for FREE!
                https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
                _______________________________________________
                Cheetahtemplate-discuss mailing list
                Cheetahtemplate-discuss@...
                https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
              • Stephan Diehl
                ... I m using the containment approach and have no problems whatsoever, but then I m not using #extends. stephan ... This sf.net email is sponsored by: OSDN -
                Message 7 of 9 , Aug 30, 2002
                • 0 Attachment
                  >...
                  > I was just writing a message to tell you that I just cut all my templates
                  > to barebones to eliminate all other sources of error, and have discovered
                  > that they templates were failing whenever they used #extends!!!
                  >
                  > ...
                  >
                  > Good! I thought I was going crazy! How is it nobody else noticed this? I
                  > thought people quite a few people were using containment?
                  >
                  > ...Edmund.
                  >

                  I'm using the containment approach and have no problems whatsoever, but then
                  I'm not using #extends.

                  stephan


                  -------------------------------------------------------
                  This sf.net email is sponsored by: OSDN - Tired of that same old
                  cell phone? Get a new here for FREE!
                  https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
                  _______________________________________________
                  Cheetahtemplate-discuss mailing list
                  Cheetahtemplate-discuss@...
                  https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                • Tavis Rudd
                  ... I m a little surprised that noone has, but I never use the containment approach. Your combination of the containment approach, #extends, and a modified
                  Message 8 of 9 , Aug 30, 2002
                  • 0 Attachment
                    On August 30, 2002 11:03 am, Edmund Lian wrote:
                    > Good! I thought I was going crazy! How is it nobody else noticed this? I
                    > thought people quite a few people were using containment?

                    I'm a little surprised that noone has, but I never use the containment
                    approach. Your combination of the containment approach, #extends, and a
                    modified searchList might be a first.


                    -------------------------------------------------------
                    This sf.net email is sponsored by: OSDN - Tired of that same old
                    cell phone? Get a new here for FREE!
                    https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
                    _______________________________________________
                    Cheetahtemplate-discuss mailing list
                    Cheetahtemplate-discuss@...
                    https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                  • Edmund Lian
                    ... Ah finally, a first for me in something! :-) ... This sf.net email is sponsored by: OSDN - Tired of that same old cell phone? Get a new here for FREE!
                    Message 9 of 9 , Aug 30, 2002
                    • 0 Attachment
                      On 08/30/2002 03:25:09 PM Tavis wrote:

                      >I'm a little surprised that noone has, but I never use the containment
                      >approach. Your combination of the containment approach, #extends, and a
                      >modified searchList might be a first.

                      Ah finally, a first for me in something! :-)

                      ...Edmund.



                      -------------------------------------------------------
                      This sf.net email is sponsored by: OSDN - Tired of that same old
                      cell phone? Get a new here for FREE!
                      https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
                      _______________________________________________
                      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.