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

[Cheetahtemplate-discuss] RecursiveNull class is not comparable

Expand Messages
  • Peter Warasin
    Hi list I use the RecursiveNull class in order to fill variables with when they are not in the search list. An expression of the following form however
    Message 1 of 6 , Feb 16, 2009
      Hi list

      I use the RecursiveNull class in order to fill variables with '' when
      they are not in the search list.

      An expression of the following form however always will be False:

      #if $INEXISTENVAR != 'on'
      Not on
      #end if

      $INEXISTENTVAR in this expression is RecursiveNull, which should return
      '', but it does not compare to 'on', since RecursiveNull has no __eq__()
      method.

      A patch is attached to this mail, which solves the problem for me.
      I don't know if there is maybe a better solution for this problem,
      without patching the code.. (?)


      peter

      --
      :: e n d i a n
      :: open source - open minds

      :: peter warasin
      :: http://www.endian.com :: peter@...
    • R. Tyler Ballance
      ... This patch was brought to my attention, and I m a bit curious as to the usecase since RecursiveNull is not used anywhere in the Cheetah codebase, can you
      Message 2 of 6 , Mar 17, 2009
        On Mon, Feb 16, 2009 at 06:00:10PM +0100, Peter Warasin wrote:
        > Hi list
        >
        > I use the RecursiveNull class in order to fill variables with '' when
        > they are not in the search list.
        >
        > An expression of the following form however always will be False:
        >
        > #if $INEXISTENVAR != 'on'
        > Not on
        > #end if
        >
        > $INEXISTENTVAR in this expression is RecursiveNull, which should return
        > '', but it does not compare to 'on', since RecursiveNull has no __eq__()
        > method.
        >
        > A patch is attached to this mail, which solves the problem for me.
        > I don't know if there is maybe a better solution for this problem,
        > without patching the code.. (?)


        This patch was brought to my attention, and I'm a bit curious as to the
        usecase since RecursiveNull is not used anywhere in the Cheetah
        codebase, can you provide more context perhaps?

        Consider this patch instead however:

        diff --git a/src/Tools/RecursiveNull.py b/src/Tools/RecursiveNull.py
        index 4897d80..a1bae65 100644
        --- a/src/Tools/RecursiveNull.py
        +++ b/src/Tools/RecursiveNull.py
        @@ -20,4 +20,11 @@ class RecursiveNull:
        return ''
        def __nonzero__(self):
        return 0
        + def __eq__(self, x):
        + if x:
        + return False
        + return True
        + def __ne__(self, x):
        + return x and True or False


        This behavior is now exhibited by RecursiveNull in your case:

        >>> from src.Tools.RecursiveNull import RecursiveNull
        >>> rn = RecursiveNull()
        >>> rn == 'on'
        False
        >>> rn == False
        True
        >>> rn == None
        True
        >>> rn != 'on'
        True
        >>>


        At least from my read on the history of this module, this seems like the
        right thing to do with it.


        If this is the appropriate patch, I will go ahead and commit it to the
        GitHub repository (https://github.com/rtyler/cheetah/tree) and lump it
        in with the next Cheetah Community Edition release

        Thoughts?

        >
        > Index: Cheetah-2.0/src/Tools/RecursiveNull.py
        > ===================================================================
        > --- Cheetah-2.0.orig/src/Tools/RecursiveNull.py 2009-02-16 16:51:45.000000000 +0100
        > +++ Cheetah-2.0/src/Tools/RecursiveNull.py 2009-02-16 16:51:59.000000000 +0100
        > @@ -20,4 +20,6 @@
        > return ''
        > def __nonzero__(self):
        > return 0
        > + def __eq__(self, x):
        > + return x == ''
        >

        --
        -R. Tyler Ballance
        Slide, Inc.
      • R. Tyler Ballance
        ... For what it s worth, the modified patch that I suggested in my previous mail on this thread has been committed to the next branch of the Cheetah CE git
        Message 3 of 6 , Mar 19, 2009
          On Tue, Mar 17, 2009 at 02:50:07PM -0700, R. Tyler Ballance wrote:
          > On Mon, Feb 16, 2009 at 06:00:10PM +0100, Peter Warasin wrote:
          > > Hi list
          > >
          > > I use the RecursiveNull class in order to fill variables with '' when
          > > they are not in the search list.

          For what it's worth, the modified patch that I suggested in my previous
          mail on this thread has been committed to the 'next' branch of the
          Cheetah CE git repo (http://github.com/rtyler/cheetah/tree/next) and
          will go out with the Cheetah CE v2.1.1 release next month


          Thanks for the patch :)


          > >
          > > An expression of the following form however always will be False:
          > >
          > > #if $INEXISTENVAR != 'on'
          > > Not on
          > > #end if
          > >
          > > $INEXISTENTVAR in this expression is RecursiveNull, which should return
          > > '', but it does not compare to 'on', since RecursiveNull has no __eq__()
          > > method.
          > >
          > > A patch is attached to this mail, which solves the problem for me.
          > > I don't know if there is maybe a better solution for this problem,
          > > without patching the code.. (?)
          >
          >
          > This patch was brought to my attention, and I'm a bit curious as to the
          > usecase since RecursiveNull is not used anywhere in the Cheetah
          > codebase, can you provide more context perhaps?
          >
          > Consider this patch instead however:
          >
          > diff --git a/src/Tools/RecursiveNull.py b/src/Tools/RecursiveNull.py
          > index 4897d80..a1bae65 100644
          > --- a/src/Tools/RecursiveNull.py
          > +++ b/src/Tools/RecursiveNull.py
          > @@ -20,4 +20,11 @@ class RecursiveNull:
          > return ''
          > def __nonzero__(self):
          > return 0
          > + def __eq__(self, x):
          > + if x:
          > + return False
          > + return True
          > + def __ne__(self, x):
          > + return x and True or False
          >
          >
          > This behavior is now exhibited by RecursiveNull in your case:
          >
          > >>> from src.Tools.RecursiveNull import RecursiveNull
          > >>> rn = RecursiveNull()
          > >>> rn == 'on'
          > False
          > >>> rn == False
          > True
          > >>> rn == None
          > True
          > >>> rn != 'on'
          > True
          > >>>
          >
          >
          > At least from my read on the history of this module, this seems like the
          > right thing to do with it.
          >
          >
          > If this is the appropriate patch, I will go ahead and commit it to the
          > GitHub repository (https://github.com/rtyler/cheetah/tree) and lump it
          > in with the next Cheetah Community Edition release
          >
          > Thoughts?
          >
          > >
          > > Index: Cheetah-2.0/src/Tools/RecursiveNull.py
          > > ===================================================================
          > > --- Cheetah-2.0.orig/src/Tools/RecursiveNull.py 2009-02-16 16:51:45.000000000 +0100
          > > +++ Cheetah-2.0/src/Tools/RecursiveNull.py 2009-02-16 16:51:59.000000000 +0100
          > > @@ -20,4 +20,6 @@
          > > return ''
          > > def __nonzero__(self):
          > > return 0
          > > + def __eq__(self, x):
          > > + return x == ''
          > >
          >
          > --
          > -R. Tyler Ballance
          > Slide, Inc.



          > ------------------------------------------------------------------------------
          > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
          > powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
          > easily build your RIAs with Flex Builder, the Eclipse(TM)based development
          > software that enables intelligent coding and step-through debugging.
          > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
          > _______________________________________________
          > Cheetahtemplate-discuss mailing list
          > Cheetahtemplate-discuss@...
          > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss


          --
          -R. Tyler Ballance
          Slide, Inc.
        • Peter Warasin
          Hi ... It s a tool you can use or not in your implementations. If you like that template processing does not raise an error if you use variables within the
          Message 4 of 6 , Mar 23, 2009
            Hi

            R. Tyler Ballance wrote:
            > This patch was brought to my attention, and I'm a bit curious as to the
            > usecase since RecursiveNull is not used anywhere in the Cheetah
            > codebase, can you provide more context perhaps?

            It's a tool you can use or not in your implementations.

            If you like that template processing does not raise an error if you use
            variables within the template which are not in the searchlist, you can
            put an instance of this class to the end of the searchlist and it
            substitutes to '' without raising a namemapper.notfound exception.

            It's handy sometimes when you don't know which variables one may use in
            templates or if your default values should be '', but are not always set.


            > This behavior is now exhibited by RecursiveNull in your case:

            Great. That's fine!


            I found another issue using this class. I will send a new mail afterwards.

            peter

            --
            :: e n d i a n
            :: open source - open minds

            :: peter warasin
            :: http://www.endian.com :: peter@...

            ------------------------------------------------------------------------------
            Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
            powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
            easily build your RIAs with Flex Builder, the Eclipse(TM)based development
            software that enables intelligent coding and step-through debugging.
            Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • mobiledreamers@gmail.com
            If you like that template processing does not raise an error if you use variables within the template which are not in the searchlist, you can put an instance
            Message 5 of 6 , Mar 24, 2009
              If you like that template processing does not raise an error if you use
              variables within the template which are not in the searchlist, you can
              put an instance of this class to the end of the searchlist and it
              substitutes to '' without raising a namemapper.notfound exception.

              Peter can you show how to do this
              thanks


              On Mon, Mar 23, 2009 at 7:08 AM, Peter Warasin <peter@...> wrote:
              Hi

              R. Tyler Ballance wrote:
              > This patch was brought to my attention, and I'm a bit curious as to the
              > usecase since RecursiveNull is not used anywhere in the Cheetah
              > codebase, can you provide more context perhaps?

              It's a tool you can use or not in your implementations.

              If you like that template processing does not raise an error if you use
              variables within the template which are not in the searchlist, you can
              put an instance of this class to the end of the searchlist and it
              substitutes to '' without raising a namemapper.notfound exception.

              It's handy sometimes when you don't know which variables one may use in
              templates or if your default values should be '', but are not always set.


              > This behavior is now exhibited by RecursiveNull in your case:

              Great. That's fine!


              I found another issue using this class. I will send a new mail afterwards.

              peter

              --
              :: e n d i a n
              :: open source - open minds

              :: peter warasin
              :: http://www.endian.com   :: peter@...

              ------------------------------------------------------------------------------
              Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
              powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
              easily build your RIAs with Flex Builder, the Eclipse(TM)based development
              software that enables intelligent coding and step-through debugging.
              Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
              _______________________________________________
              Cheetahtemplate-discuss mailing list
              Cheetahtemplate-discuss@...
              https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss



              --
              Bidegg worlds best auction site
              http://bidegg.com
            • R. Tyler Ballance
              ... Peter demonstrated it s use in another thread see: RecursiveNull class in searchlist overrides template methods In the future, please include whitespace
              Message 6 of 6 , Mar 24, 2009
                On Tue, Mar 24, 2009 at 09:10:35AM -0700, mobiledreamers@... wrote:
                > If you like that template processing does not raise an error if you use
                > variables within the template which are not in the searchlist, you can
                > put an instance of this class to the end of the searchlist and it
                > substitutes to '' without raising a namemapper.notfound exception.

                > Peter can you show how to do this
                > thanks

                Peter demonstrated it's use in another thread see:
                "RecursiveNull class in searchlist overrides template methods"

                In the future, please include whitespace between your content in a reply
                and the previous author's content, it's far to difficult to read the
                replies you send to the list.

                >
                > On Mon, Mar 23, 2009 at 7:08 AM, Peter Warasin <peter@...> wrote:
                >
                > Hi
                > R. Tyler Ballance wrote:
                > > This patch was brought to my attention, and I'm a bit curious as to
                > the
                > > usecase since RecursiveNull is not used anywhere in the Cheetah
                > > codebase, can you provide more context perhaps?
                >
                > It's a tool you can use or not in your implementations.
                >
                > If you like that template processing does not raise an error if you use
                > variables within the template which are not in the searchlist, you can
                > put an instance of this class to the end of the searchlist and it
                > substitutes to '' without raising a namemapper.notfound exception.
                >
                > It's handy sometimes when you don't know which variables one may use in
                > templates or if your default values should be '', but are not always
                > set.
                >
                > > This behavior is now exhibited by RecursiveNull in your case:
                >
                > Great. That's fine!
                >
                > I found another issue using this class. I will send a new mail
                > afterwards.
                > peter
                >
                > --
                > :: e n d i a n
                > :: open source - open minds
                >
                > :: peter warasin
                > :: http://www.endian.com :: peter@...
                >
                > ------------------------------------------------------------------------------
                > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
                > powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
                > easily build your RIAs with Flex Builder, the Eclipse(TM)based
                > development
                > software that enables intelligent coding and step-through debugging.
                > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
                > _______________________________________________
                > Cheetahtemplate-discuss mailing list
                > Cheetahtemplate-discuss@...
                > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                >
                > --
                > Bidegg worlds best auction site
                > http://bidegg.com

                --
                -R. Tyler Ballance
                Slide, Inc.
              Your message has been successfully submitted and would be delivered to recipients shortly.