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

[Cheetahtemplate-discuss] mod_python.publisher and Cheetah

Expand Messages
  • Stephane Bortzmeyer
    I always used Cheetah on Apache with a custom mod_python handler (see http://wiki.cheetahtemplate.org/cheetahrecipes.html). I would like to use mod_python s
    Message 1 of 12 , Mar 14, 2005
      I always used Cheetah on Apache with a custom mod_python handler (see
      http://wiki.cheetahtemplate.org/cheetahrecipes.html). I would like to
      use mod_python's publisher
      http://www.modpython.org/live/current/doc-html/hand-pub.html, in order
      to limit my liability :-) specially for security reasons.

      It works fine but not if I use Cheetah's inheritance, as described in
      http://www.cheetahtemplate.org/docs/users_guide_html_multipage/inheritanceEtc.extends.html.
      My foobar.tmpl Cheetah file is compiled as foobar.py, which includes a
      foobar class. I added a index() routine but Cheetah puts in in the
      foobar class, not directly in the foobar module. When
      mod_python.publisher calls index(), it finds nothing and returns
      NOT_FOUND.



      My SiteLogic.py:


      from Cheetah.Template import Template

      class SiteLogic(Template):
      """ Pure Python class containing methods for the site """

      # Never found because Cheetah puts it in a class
      def index(req):
      return "Dummy"



      My Site.tmpl:



      #from SiteLogic import SiteLogic
      #extends SiteLogic
      #implements respond

      #def title
      No title #slurp
      #end def

      #def body
      <P>Default body.
      #end def

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <HTML>
      <HEAD>
      <TITLE>
      $title
      </TITLE>
      </HEAD>
      <BODY>
      <H1>$title</H1>
      $body
      <HR>



      A typical page:


      #from Site import Site
      #extends Site
      #implements body
      #def title
      Welcome
      #end def

      <P>Some content.


      -------------------------------------------------------
      SF email is sponsored by - The IT Product Guide
      Read honest & candid reviews on hundreds of IT Products from real users.
      Discover which products truly live up to the hype. Start reading now.
      http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Graham Dumpleton
      I somewhat suspect that you aren t going to get the code as by default generated by Cheetah to play well with publisher. As to your original custom handler,
      Message 2 of 12 , Mar 14, 2005
        I somewhat suspect that you aren't going to get the code as by
        default generated by Cheetah to play well with publisher. As to
        your original custom handler, you could clean it up somewhat
        by using something like:

        start = "/python/"

        from mod_python import apache
        import string

        def handler(req):

        req.content_type = "text/html"
        module_name = string.replace (req.uri, start, "")

        # try:
        # exec ("""import %s
        #tmpl = %s.%s()
        #tmpl.req = req""" % (module_name, module_name, module_name))
        # except ImportError:
        # return apache.HTTP_NOT_FOUND

        module = apache.import_module(module_name)
        if not hasattr(module,module_name):
        return apache.HTTP_NOT_FOUND

        tmpl = getattr(module,module_name)()
        tmpl.req = req

        req.send_http_header()
        req.write(tmpl.respond())

        return apache.OK

        I still see some issues with this code in as much as I think it
        requires everything to be in the one directory. Ie., can't have
        subdirectories. Using "start" as a fixed value is not good, but
        that can also be fixed. Also, you can't mix different file types
        in the same directory.

        When I get a chance, I'll write you a better version of this
        which would fix these problems and provide new abilities as well.
        I am surprised though that someone hasn't already written a
        better handler for integrating Cheetah with mod_python.

        BTW, I am not on the Cheetah mailing list, so ensure any responses
        also go back to the mod_python list as well.

        Graham

        On Tuesday, March 15, 2005, at 02:17 AM, Stephane Bortzmeyer wrote:

        > I always used Cheetah on Apache with a custom mod_python handler (see
        > http://wiki.cheetahtemplate.org/cheetahrecipes.html). I would like to
        > use mod_python's publisher
        > http://www.modpython.org/live/current/doc-html/hand-pub.html, in order
        > to limit my liability :-) specially for security reasons.
        >
        > It works fine but not if I use Cheetah's inheritance, as described in
        > http://www.cheetahtemplate.org/docs/users_guide_html_multipage/
        > inheritanceEtc.extends.html.
        > My foobar.tmpl Cheetah file is compiled as foobar.py, which includes a
        > foobar class. I added a index() routine but Cheetah puts in in the
        > foobar class, not directly in the foobar module. When
        > mod_python.publisher calls index(), it finds nothing and returns
        > NOT_FOUND.
        >
        >
        >
        > My SiteLogic.py:
        >
        >
        > from Cheetah.Template import Template
        >
        > class SiteLogic(Template):
        > """ Pure Python class containing methods for the site """
        >
        > # Never found because Cheetah puts it in a class
        > def index(req):
        > return "Dummy"
        >
        >
        >
        > My Site.tmpl:
        >
        >
        >
        > #from SiteLogic import SiteLogic
        > #extends SiteLogic
        > #implements respond
        >
        > #def title
        > No title #slurp
        > #end def
        >
        > #def body
        > <P>Default body.
        > #end def
        >
        > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
        > <HTML>
        > <HEAD>
        > <TITLE>
        > $title
        > </TITLE>
        > </HEAD>
        > <BODY>
        > <H1>$title</H1>
        > $body
        > <HR>
        >
        >
        >
        > A typical page:
        >
        >
        > #from Site import Site
        > #extends Site
        > #implements body
        > #def title
        > Welcome
        > #end def
        >
        > <P>Some content.
        > _______________________________________________
        > Mod_python mailing list
        > Mod_python@...
        > http://mailman.modpython.org/mailman/listinfo/mod_python



        -------------------------------------------------------
        SF email is sponsored by - The IT Product Guide
        Read honest & candid reviews on hundreds of IT Products from real users.
        Discover which products truly live up to the hype. Start reading now.
        http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Shannon -jj Behrens
        ... If you ll forgive the advertisement, Aquarium works with Cheetah and mod_python just fine. Best Regards, -jj -- I have decided to switch to Gmail, but
        Message 3 of 12 , Mar 14, 2005
          > I am surprised though that someone hasn't already written a
          > better handler for integrating Cheetah with mod_python.

          If you'll forgive the advertisement, Aquarium works with Cheetah and
          mod_python just fine.

          Best Regards,
          -jj

          --
          I have decided to switch to Gmail, but messages to my Yahoo account will
          still get through.


          -------------------------------------------------------
          SF email is sponsored by - The IT Product Guide
          Read honest & candid reviews on hundreds of IT Products from real users.
          Discover which products truly live up to the hype. Start reading now.
          http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Graham Dumpleton
          Here is a better version of a handler which allows use of Cheetah templates with mod_python. from mod_python import apache import os # It is assumed that
          Message 4 of 12 , Mar 14, 2005
            Here is a better version of a handler which allows use of Cheetah
            templates with mod_python.



            from mod_python import apache

            import os

            # It is assumed that Apache config or .htaccess file
            # blocks access to ".tmpl", ".py" and ".pyc" files.

            def handler(req):

            # Assume REST style URLs. Ie., no extension is used
            # for accessing Cheetah pages. On this basis, first
            # perform a check that there is a ".py" file in
            # existance. This is done because can't distinguish
            # between a non existant module and a module which has
            # a coding error in it when using the function
            # "apache.import_module()". By returning DECLINED,
            # Apache will then serve up any static files in the
            # directory which may otherwise be matched.

            target = req.filename + ".py"

            if not os.path.exists(target):
            return apache.DECLINED

            # Grab the module name to look for from the last part
            # of the path. This means that pages can be spread
            # across subdirectories as well.

            directory,module_name = os.path.split(req.filename)

            # Import the module. Any coding error in the module
            # being imported is thrown back to the user. Error
            # also results if by chance the target just vanished.

            module = apache.import_module(module_name,[directory])

            # Ensure that there is a class defined in the module
            # of the appropriate name.

            if not hasattr(module,module_name):
            return apache.DECLINED

            # Create instance of the class and setup request object.

            tmpl = getattr(module,module_name)()
            tmpl.req = req

            # Assume that HTML is being generated.

            req.content_type = "text/plain"
            req.send_http_header()

            # Now generate the actual content and return it.

            req.write(tmpl.respond())

            return apache.OK



            Graham Dumpleton wrote ..
            > I somewhat suspect that you aren't going to get the code as by
            > default generated by Cheetah to play well with publisher. As to
            > your original custom handler, you could clean it up somewhat
            > by using something like:
            >
            > start = "/python/"
            >
            > from mod_python import apache
            > import string
            >
            > def handler(req):
            >
            > req.content_type = "text/html"
            > module_name = string.replace (req.uri, start, "")
            >
            > # try:
            > # exec ("""import %s
            > #tmpl = %s.%s()
            > #tmpl.req = req""" % (module_name, module_name, module_name))
            > # except ImportError:
            > # return apache.HTTP_NOT_FOUND
            >
            > module = apache.import_module(module_name)
            > if not hasattr(module,module_name):
            > return apache.HTTP_NOT_FOUND
            >
            > tmpl = getattr(module,module_name)()
            > tmpl.req = req
            >
            > req.send_http_header()
            > req.write(tmpl.respond())
            >
            > return apache.OK
            >
            > I still see some issues with this code in as much as I think it
            > requires everything to be in the one directory. Ie., can't have
            > subdirectories. Using "start" as a fixed value is not good, but
            > that can also be fixed. Also, you can't mix different file types
            > in the same directory.
            >
            > When I get a chance, I'll write you a better version of this
            > which would fix these problems and provide new abilities as well.
            > I am surprised though that someone hasn't already written a
            > better handler for integrating Cheetah with mod_python.
            >
            > BTW, I am not on the Cheetah mailing list, so ensure any responses
            > also go back to the mod_python list as well.
            >
            > Graham
            >
            > On Tuesday, March 15, 2005, at 02:17 AM, Stephane Bortzmeyer wrote:
            >
            > > I always used Cheetah on Apache with a custom mod_python handler (see
            > > http://wiki.cheetahtemplate.org/cheetahrecipes.html). I would like to
            > > use mod_python's publisher
            > > http://www.modpython.org/live/current/doc-html/hand-pub.html, in order
            > > to limit my liability :-) specially for security reasons.
            > >
            > > It works fine but not if I use Cheetah's inheritance, as described in
            > > http://www.cheetahtemplate.org/docs/users_guide_html_multipage/
            > > inheritanceEtc.extends.html.
            > > My foobar.tmpl Cheetah file is compiled as foobar.py, which includes
            > a
            > > foobar class. I added a index() routine but Cheetah puts in in the
            > > foobar class, not directly in the foobar module. When
            > > mod_python.publisher calls index(), it finds nothing and returns
            > > NOT_FOUND.
            > >
            > >
            > >
            > > My SiteLogic.py:
            > >
            > >
            > > from Cheetah.Template import Template
            > >
            > > class SiteLogic(Template):
            > > """ Pure Python class containing methods for the site """
            > >
            > > # Never found because Cheetah puts it in a class
            > > def index(req):
            > > return "Dummy"
            > >
            > >
            > >
            > > My Site.tmpl:
            > >
            > >
            > >
            > > #from SiteLogic import SiteLogic
            > > #extends SiteLogic
            > > #implements respond
            > >
            > > #def title
            > > No title #slurp
            > > #end def
            > >
            > > #def body
            > > <P>Default body.
            > > #end def
            > >
            > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
            > > <HTML>
            > > <HEAD>
            > > <TITLE>
            > > $title
            > > </TITLE>
            > > </HEAD>
            > > <BODY>
            > > <H1>$title</H1>
            > > $body
            > > <HR>
            > >
            > >
            > >
            > > A typical page:
            > >
            > >
            > > #from Site import Site
            > > #extends Site
            > > #implements body
            > > #def title
            > > Welcome
            > > #end def
            > >
            > > <P>Some content.
            > > _______________________________________________
            > > Mod_python mailing list
            > > Mod_python@...
            > > http://mailman.modpython.org/mailman/listinfo/mod_python
            >
            > _______________________________________________
            > Mod_python mailing list
            > Mod_python@...
            > http://mailman.modpython.org/mailman/listinfo/mod_python


            -------------------------------------------------------
            SF email is sponsored by - The IT Product Guide
            Read honest & candid reviews on hundreds of IT Products from real users.
            Discover which products truly live up to the hype. Start reading now.
            http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
            _______________________________________________
            Cheetahtemplate-discuss mailing list
            Cheetahtemplate-discuss@...
            https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
          • Graham Dumpleton
            BTW, make sure that Apache MultiViews option is not enabled, else this will not always work. Thus: Options -MultiViews Graham Dumpleton wrote .. ... SF email
            Message 5 of 12 , Mar 14, 2005
              BTW, make sure that Apache MultiViews option is not enabled,
              else this will not always work. Thus:

              Options -MultiViews


              Graham Dumpleton wrote ..
              > Here is a better version of a handler which allows use of Cheetah
              > templates with mod_python.
              >
              >
              >
              > from mod_python import apache
              >
              > import os
              >
              > # It is assumed that Apache config or .htaccess file
              > # blocks access to ".tmpl", ".py" and ".pyc" files.
              >
              > def handler(req):
              >
              > # Assume REST style URLs. Ie., no extension is used
              > # for accessing Cheetah pages. On this basis, first
              > # perform a check that there is a ".py" file in
              > # existance. This is done because can't distinguish
              > # between a non existant module and a module which has
              > # a coding error in it when using the function
              > # "apache.import_module()". By returning DECLINED,
              > # Apache will then serve up any static files in the
              > # directory which may otherwise be matched.
              >
              > target = req.filename + ".py"
              >
              > if not os.path.exists(target):
              > return apache.DECLINED
              >
              > # Grab the module name to look for from the last part
              > # of the path. This means that pages can be spread
              > # across subdirectories as well.
              >
              > directory,module_name = os.path.split(req.filename)
              >
              > # Import the module. Any coding error in the module
              > # being imported is thrown back to the user. Error
              > # also results if by chance the target just vanished.
              >
              > module = apache.import_module(module_name,[directory])
              >
              > # Ensure that there is a class defined in the module
              > # of the appropriate name.
              >
              > if not hasattr(module,module_name):
              > return apache.DECLINED
              >
              > # Create instance of the class and setup request object.
              >
              > tmpl = getattr(module,module_name)()
              > tmpl.req = req
              >
              > # Assume that HTML is being generated.
              >
              > req.content_type = "text/plain"
              > req.send_http_header()
              >
              > # Now generate the actual content and return it.
              >
              > req.write(tmpl.respond())
              >
              > return apache.OK
              >
              >
              >
              > Graham Dumpleton wrote ..
              > > I somewhat suspect that you aren't going to get the code as by
              > > default generated by Cheetah to play well with publisher. As to
              > > your original custom handler, you could clean it up somewhat
              > > by using something like:
              > >
              > > start = "/python/"
              > >
              > > from mod_python import apache
              > > import string
              > >
              > > def handler(req):
              > >
              > > req.content_type = "text/html"
              > > module_name = string.replace (req.uri, start, "")
              > >
              > > # try:
              > > # exec ("""import %s
              > > #tmpl = %s.%s()
              > > #tmpl.req = req""" % (module_name, module_name, module_name))
              > > # except ImportError:
              > > # return apache.HTTP_NOT_FOUND
              > >
              > > module = apache.import_module(module_name)
              > > if not hasattr(module,module_name):
              > > return apache.HTTP_NOT_FOUND
              > >
              > > tmpl = getattr(module,module_name)()
              > > tmpl.req = req
              > >
              > > req.send_http_header()
              > > req.write(tmpl.respond())
              > >
              > > return apache.OK
              > >
              > > I still see some issues with this code in as much as I think it
              > > requires everything to be in the one directory. Ie., can't have
              > > subdirectories. Using "start" as a fixed value is not good, but
              > > that can also be fixed. Also, you can't mix different file types
              > > in the same directory.
              > >
              > > When I get a chance, I'll write you a better version of this
              > > which would fix these problems and provide new abilities as well.
              > > I am surprised though that someone hasn't already written a
              > > better handler for integrating Cheetah with mod_python.
              > >
              > > BTW, I am not on the Cheetah mailing list, so ensure any responses
              > > also go back to the mod_python list as well.
              > >
              > > Graham
              > >
              > > On Tuesday, March 15, 2005, at 02:17 AM, Stephane Bortzmeyer wrote:
              > >
              > > > I always used Cheetah on Apache with a custom mod_python handler (see
              > > > http://wiki.cheetahtemplate.org/cheetahrecipes.html). I would like
              > to
              > > > use mod_python's publisher
              > > > http://www.modpython.org/live/current/doc-html/hand-pub.html, in order
              > > > to limit my liability :-) specially for security reasons.
              > > >
              > > > It works fine but not if I use Cheetah's inheritance, as described
              > in
              > > > http://www.cheetahtemplate.org/docs/users_guide_html_multipage/
              > > > inheritanceEtc.extends.html.
              > > > My foobar.tmpl Cheetah file is compiled as foobar.py, which includes
              > > a
              > > > foobar class. I added a index() routine but Cheetah puts in in the
              > > > foobar class, not directly in the foobar module. When
              > > > mod_python.publisher calls index(), it finds nothing and returns
              > > > NOT_FOUND.
              > > >
              > > >
              > > >
              > > > My SiteLogic.py:
              > > >
              > > >
              > > > from Cheetah.Template import Template
              > > >
              > > > class SiteLogic(Template):
              > > > """ Pure Python class containing methods for the site """
              > > >
              > > > # Never found because Cheetah puts it in a class
              > > > def index(req):
              > > > return "Dummy"
              > > >
              > > >
              > > >
              > > > My Site.tmpl:
              > > >
              > > >
              > > >
              > > > #from SiteLogic import SiteLogic
              > > > #extends SiteLogic
              > > > #implements respond
              > > >
              > > > #def title
              > > > No title #slurp
              > > > #end def
              > > >
              > > > #def body
              > > > <P>Default body.
              > > > #end def
              > > >
              > > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
              > > > <HTML>
              > > > <HEAD>
              > > > <TITLE>
              > > > $title
              > > > </TITLE>
              > > > </HEAD>
              > > > <BODY>
              > > > <H1>$title</H1>
              > > > $body
              > > > <HR>
              > > >
              > > >
              > > >
              > > > A typical page:
              > > >
              > > >
              > > > #from Site import Site
              > > > #extends Site
              > > > #implements body
              > > > #def title
              > > > Welcome
              > > > #end def
              > > >
              > > > <P>Some content.
              > > > _______________________________________________
              > > > Mod_python mailing list
              > > > Mod_python@...
              > > > http://mailman.modpython.org/mailman/listinfo/mod_python
              > >
              > > _______________________________________________
              > > Mod_python mailing list
              > > Mod_python@...
              > > http://mailman.modpython.org/mailman/listinfo/mod_python
              > _______________________________________________
              > Mod_python mailing list
              > Mod_python@...
              > http://mailman.modpython.org/mailman/listinfo/mod_python


              -------------------------------------------------------
              SF email is sponsored by - The IT Product Guide
              Read honest & candid reviews on hundreds of IT Products from real users.
              Discover which products truly live up to the hype. Start reading now.
              http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
              _______________________________________________
              Cheetahtemplate-discuss mailing list
              Cheetahtemplate-discuss@...
              https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
            • Graham Dumpleton
              My obvious error should also be fixed. :-) # Assume that HTML is being generated. req.content_type = text/html req.send_http_header() Browser was smart
              Message 6 of 12 , Mar 14, 2005
                My obvious error should also be fixed. :-)

                # Assume that HTML is being generated.

                req.content_type = "text/html"
                req.send_http_header()

                Browser was smart enough to realise it was HTML anyway when
                I tested it.

                Graham

                Graham Dumpleton wrote ..
                > Here is a better version of a handler which allows use of Cheetah
                > templates with mod_python.
                >
                >
                >
                > from mod_python import apache
                >
                > import os
                >
                > # It is assumed that Apache config or .htaccess file
                > # blocks access to ".tmpl", ".py" and ".pyc" files.
                >
                > def handler(req):
                >
                > # Assume REST style URLs. Ie., no extension is used
                > # for accessing Cheetah pages. On this basis, first
                > # perform a check that there is a ".py" file in
                > # existance. This is done because can't distinguish
                > # between a non existant module and a module which has
                > # a coding error in it when using the function
                > # "apache.import_module()". By returning DECLINED,
                > # Apache will then serve up any static files in the
                > # directory which may otherwise be matched.
                >
                > target = req.filename + ".py"
                >
                > if not os.path.exists(target):
                > return apache.DECLINED
                >
                > # Grab the module name to look for from the last part
                > # of the path. This means that pages can be spread
                > # across subdirectories as well.
                >
                > directory,module_name = os.path.split(req.filename)
                >
                > # Import the module. Any coding error in the module
                > # being imported is thrown back to the user. Error
                > # also results if by chance the target just vanished.
                >
                > module = apache.import_module(module_name,[directory])
                >
                > # Ensure that there is a class defined in the module
                > # of the appropriate name.
                >
                > if not hasattr(module,module_name):
                > return apache.DECLINED
                >
                > # Create instance of the class and setup request object.
                >
                > tmpl = getattr(module,module_name)()
                > tmpl.req = req
                >
                > # Assume that HTML is being generated.
                >
                > req.content_type = "text/plain"
                > req.send_http_header()
                >
                > # Now generate the actual content and return it.
                >
                > req.write(tmpl.respond())
                >
                > return apache.OK
                >
                >
                >
                > Graham Dumpleton wrote ..
                > > I somewhat suspect that you aren't going to get the code as by
                > > default generated by Cheetah to play well with publisher. As to
                > > your original custom handler, you could clean it up somewhat
                > > by using something like:
                > >
                > > start = "/python/"
                > >
                > > from mod_python import apache
                > > import string
                > >
                > > def handler(req):
                > >
                > > req.content_type = "text/html"
                > > module_name = string.replace (req.uri, start, "")
                > >
                > > # try:
                > > # exec ("""import %s
                > > #tmpl = %s.%s()
                > > #tmpl.req = req""" % (module_name, module_name, module_name))
                > > # except ImportError:
                > > # return apache.HTTP_NOT_FOUND
                > >
                > > module = apache.import_module(module_name)
                > > if not hasattr(module,module_name):
                > > return apache.HTTP_NOT_FOUND
                > >
                > > tmpl = getattr(module,module_name)()
                > > tmpl.req = req
                > >
                > > req.send_http_header()
                > > req.write(tmpl.respond())
                > >
                > > return apache.OK
                > >
                > > I still see some issues with this code in as much as I think it
                > > requires everything to be in the one directory. Ie., can't have
                > > subdirectories. Using "start" as a fixed value is not good, but
                > > that can also be fixed. Also, you can't mix different file types
                > > in the same directory.
                > >
                > > When I get a chance, I'll write you a better version of this
                > > which would fix these problems and provide new abilities as well.
                > > I am surprised though that someone hasn't already written a
                > > better handler for integrating Cheetah with mod_python.
                > >
                > > BTW, I am not on the Cheetah mailing list, so ensure any responses
                > > also go back to the mod_python list as well.
                > >
                > > Graham
                > >
                > > On Tuesday, March 15, 2005, at 02:17 AM, Stephane Bortzmeyer wrote:
                > >
                > > > I always used Cheetah on Apache with a custom mod_python handler (see
                > > > http://wiki.cheetahtemplate.org/cheetahrecipes.html). I would like
                > to
                > > > use mod_python's publisher
                > > > http://www.modpython.org/live/current/doc-html/hand-pub.html, in order
                > > > to limit my liability :-) specially for security reasons.
                > > >
                > > > It works fine but not if I use Cheetah's inheritance, as described
                > in
                > > > http://www.cheetahtemplate.org/docs/users_guide_html_multipage/
                > > > inheritanceEtc.extends.html.
                > > > My foobar.tmpl Cheetah file is compiled as foobar.py, which includes
                > > a
                > > > foobar class. I added a index() routine but Cheetah puts in in the
                > > > foobar class, not directly in the foobar module. When
                > > > mod_python.publisher calls index(), it finds nothing and returns
                > > > NOT_FOUND.
                > > >
                > > >
                > > >
                > > > My SiteLogic.py:
                > > >
                > > >
                > > > from Cheetah.Template import Template
                > > >
                > > > class SiteLogic(Template):
                > > > """ Pure Python class containing methods for the site """
                > > >
                > > > # Never found because Cheetah puts it in a class
                > > > def index(req):
                > > > return "Dummy"
                > > >
                > > >
                > > >
                > > > My Site.tmpl:
                > > >
                > > >
                > > >
                > > > #from SiteLogic import SiteLogic
                > > > #extends SiteLogic
                > > > #implements respond
                > > >
                > > > #def title
                > > > No title #slurp
                > > > #end def
                > > >
                > > > #def body
                > > > <P>Default body.
                > > > #end def
                > > >
                > > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                > > > <HTML>
                > > > <HEAD>
                > > > <TITLE>
                > > > $title
                > > > </TITLE>
                > > > </HEAD>
                > > > <BODY>
                > > > <H1>$title</H1>
                > > > $body
                > > > <HR>
                > > >
                > > >
                > > >
                > > > A typical page:
                > > >
                > > >
                > > > #from Site import Site
                > > > #extends Site
                > > > #implements body
                > > > #def title
                > > > Welcome
                > > > #end def
                > > >
                > > > <P>Some content.
                > > > _______________________________________________
                > > > Mod_python mailing list
                > > > Mod_python@...
                > > > http://mailman.modpython.org/mailman/listinfo/mod_python
                > >
                > > _______________________________________________
                > > Mod_python mailing list
                > > Mod_python@...
                > > http://mailman.modpython.org/mailman/listinfo/mod_python
                > _______________________________________________
                > Mod_python mailing list
                > Mod_python@...
                > http://mailman.modpython.org/mailman/listinfo/mod_python


                -------------------------------------------------------
                SF email is sponsored by - The IT Product Guide
                Read honest & candid reviews on hundreds of IT Products from real users.
                Discover which products truly live up to the hype. Start reading now.
                http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
                _______________________________________________
                Cheetahtemplate-discuss mailing list
                Cheetahtemplate-discuss@...
                https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
              • Stephane Bortzmeyer
                On Mon, Mar 14, 2005 at 04:17:37PM +0100, Stephane Bortzmeyer wrote ... Well, it seems there is no other solution than to write your own
                Message 7 of 12 , Mar 15, 2005
                  On Mon, Mar 14, 2005 at 04:17:37PM +0100,
                  Stephane Bortzmeyer <bortzmeyer@...> wrote
                  a message of 75 lines which said:

                  > I always used Cheetah on Apache with a custom mod_python handler (see
                  > http://wiki.cheetahtemplate.org/cheetahrecipes.html). I would like to
                  > use mod_python's publisher
                  > http://www.modpython.org/live/current/doc-html/hand-pub.html, in order
                  > to limit my liability :-) specially for security reasons.

                  Well, it seems there is no other solution than to write your own
                  publisher. Graham sent one (which works fine), here is another
                  possible one, based on the mod_python.publisher.
                • Stephane Bortzmeyer
                  On Mon, Mar 14, 2005 at 06:25:50PM -0500, Graham Dumpleton wrote ... It seems to work fine. Many thanks. ... I changed it (personal
                  Message 8 of 12 , Mar 15, 2005
                    On Mon, Mar 14, 2005 at 06:25:50PM -0500,
                    Graham Dumpleton <grahamd@...> wrote
                    a message of 200 lines which said:

                    > Here is a better version of a handler which allows use of Cheetah
                    > templates with mod_python.

                    It seems to work fine. Many thanks.

                    > target = req.filename + ".py"
                    >
                    > if not os.path.exists(target):
                    > return apache.DECLINED

                    I changed it (personal preference and I have only Python content) to:

                    if req.filename[:-3] != ".py":
                    target = req.filename + ".py"
                    else:
                    target = req.filename

                    if not os.path.exists(target):
                    raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND



                    -------------------------------------------------------
                    SF email is sponsored by - The IT Product Guide
                    Read honest & candid reviews on hundreds of IT Products from real users.
                    Discover which products truly live up to the hype. Start reading now.
                    http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
                    _______________________________________________
                    Cheetahtemplate-discuss mailing list
                    Cheetahtemplate-discuss@...
                    https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                  • Stephane Bortzmeyer
                    On Mon, Mar 14, 2005 at 01:37:18PM -0800, Shannon -jj Behrens wrote ... You are forgiven and I ve added Test and evaluate Aquarium to my
                    Message 9 of 12 , Mar 15, 2005
                      On Mon, Mar 14, 2005 at 01:37:18PM -0800,
                      Shannon -jj Behrens <jjinux@...> wrote
                      a message of 12 lines which said:

                      > If you'll forgive the advertisement, Aquarium works with Cheetah and
                      > mod_python just fine.

                      You are forgiven and I've added "Test and evaluate Aquarium" to my
                      TODO list :-)


                      -------------------------------------------------------
                      SF email is sponsored by - The IT Product Guide
                      Read honest & candid reviews on hundreds of IT Products from real users.
                      Discover which products truly live up to the hype. Start reading now.
                      http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
                      _______________________________________________
                      Cheetahtemplate-discuss mailing list
                      Cheetahtemplate-discuss@...
                      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                    • Graham Dumpleton
                      ... I would strongly recommend against changing apache.DECLINED to apache.HTTP_NOT_FOUND, it is there for a very specific reason. By using apache.DECLINED, it
                      Message 10 of 12 , Mar 15, 2005
                        On 15/03/2005, at 10:28 PM, Stephane Bortzmeyer wrote:

                        > On Mon, Mar 14, 2005 at 06:25:50PM -0500,
                        > Graham Dumpleton <grahamd@...> wrote
                        >> target = req.filename + ".py"
                        >>
                        >> if not os.path.exists(target):
                        >> return apache.DECLINED
                        >
                        > I changed it (personal preference and I have only Python content) to:
                        >
                        > if req.filename[:-3] != ".py":
                        > target = req.filename + ".py"
                        > else:
                        > target = req.filename
                        >
                        > if not os.path.exists(target):
                        > raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND

                        I would strongly recommend against changing apache.DECLINED to
                        apache.HTTP_NOT_FOUND, it is there for a very specific reason.

                        By using apache.DECLINED, it is possible to put other types of
                        files such as images, plain text etc into the same directory
                        and Apache will serve them up without you having to go to
                        contortions in the Apache configuration to have it only use
                        mod_python for ".py" or some other extension. It is also not
                        really good practice to use ".py" extension in a URL anyway as
                        that is then exposing to a user of your web site what you are
                        using to implement the web site. This can open up security
                        issues in as much as they have a better idea of what potential
                        security holes to probe. Using ".py" extension also makes it
                        harder to change internally how pages are implemented to some
                        other Python based toolkit as you are more likely to have to
                        change the URL, thus invalidating bookmarks, search engine
                        databases etc. Thus, you are better off using REST style of no
                        extension, or use ".html" if it truly is HTML content.

                        For example, to use ".html" extension you might to the extent
                        of having:

                        # Only interpret ".html" requests.

                        target,extn = os.path.splitext(req.filename)

                        if extn != ".html":
                        return apache.DECLINED

                        # We only want to treat request as being a possible
                        # request for a Cheetah generated template file if
                        # there exists both a ".tmpl" and ".py" file.

                        target_tmpl = target + ".tmpl"
                        target_py = target + ".py"

                        if not os.path.exists(target_tmpl) and not os.path.exists(target_py):
                        return apache.DECLINED

                        This will allow ".html" requests for virtual pages generated from
                        Cheetah templates, presuming ".tmpl" is in same directory, or a
                        static ".html" constructed by hand residing in the same directory.
                        The latter will work because DECLINED is returned, which gives Apache
                        a second chance at it, instead of HTTP_NOT_FOUND, which gives it no
                        chance.

                        Graham



                        -------------------------------------------------------
                        SF email is sponsored by - The IT Product Guide
                        Read honest & candid reviews on hundreds of IT Products from real users.
                        Discover which products truly live up to the hype. Start reading now.
                        http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
                        _______________________________________________
                        Cheetahtemplate-discuss mailing list
                        Cheetahtemplate-discuss@...
                        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
                      • Stephane Bortzmeyer
                        On Wed, Mar 16, 2005 at 08:03:29AM +1100, Graham Dumpleton wrote ... OK, I went back to DECLINED. I modified the publisher again to have
                        Message 11 of 12 , Mar 25, 2005
                          On Wed, Mar 16, 2005 at 08:03:29AM +1100,
                          Graham Dumpleton <grahamd@...> wrote
                          a message of 67 lines which said:

                          > I would strongly recommend against changing apache.DECLINED to
                          > apache.HTTP_NOT_FOUND, it is there for a very specific reason.

                          OK, I went back to DECLINED.

                          I modified the publisher again to have both Cheetah-generated files
                          and "classic" mod_python scripts in the same directory.
                        • Graham Dumpleton
                          Sorry, not sure where to send this as can t work out email of person who updated: http://wiki.cheetahtemplate.org/cheetahrecipes.html To say: After a lot
                          Message 12 of 12 , Apr 4, 2005
                            Sorry, not sure where to send this as can't work out email of person
                            who updated:

                            http://wiki.cheetahtemplate.org/cheetahrecipes.html

                            To say:

                            After a lot research (I thought I'd screwed up my Apache .conf, or
                            something like that), I started debugging, and found two problems.

                            req.filename had the .py extension already appended, so the script
                            was trying import mptest.py.py

                            This may have been caused by my allowing .py, .tmpl, etc. file
                            extensions to not be blocked. But even when I left .py off the URL,
                            it was appended by the time req.filename was passed to the script.

                            With a code change of:

                            #target = req.filename + ".py"
                            target = req.filename

                            This was all in relation to mod_python handler code for Cheetah I
                            sent back in March.

                            Anyway, my guess as to why you had a problem here may well be because
                            you have MultiViews turned on. If you have MultiViews turned on, when a
                            URL has "mptest" but there is no file of that name, Apache will do some
                            matching to find a file with the same basename and internally add an
                            extension which makes it match a physical file. This would have result
                            in the code screwing up as you found.

                            When using mod_python it is highly recommended that you ensure that
                            MultiViews is turned for directories managed by mod_python, otherwise
                            Apache will screw with the URLs and things may not work reliably or
                            as expected.

                            In relation to the code change from:

                            module = apache.import_module(module_name,[directory]) #1

                            to:

                            module = apache.import_module(module_name, req, [directory]) #2

                            Strictly speaking, the original (#1) is actually wrong in that it should
                            have been:

                            module = apache.import_module(module_name,path=[directory]) #3

                            If this was done, then adding "req" as an argument in (#2) may not have
                            been required. All the "req" argument seems to do is possibly push the
                            positional parameter for the path to the correct place for mod_python
                            2.7.

                            The actual prototype for apache.import_module() in mod_python 3.1 is:

                            import_module(module_name[, autoreload=1, log=0, path=None])

                            Someone might like to try the code instead with (#3) and see if it works
                            for both mod_python 2.7 and 3.1.

                            If the suggestions work out, maybe someone can update the Wiki page
                            appropriately.

                            Graham


                            On Tuesday, March 15, 2005, at 10:28 PM, Stephane Bortzmeyer wrote:

                            > On Mon, Mar 14, 2005 at 06:25:50PM -0500,
                            > Graham Dumpleton <grahamd@...> wrote
                            > a message of 200 lines which said:
                            >
                            >> Here is a better version of a handler which allows use of Cheetah
                            >> templates with mod_python.
                            >
                            > It seems to work fine. Many thanks.
                            >
                            >> target = req.filename + ".py"
                            >>
                            >> if not os.path.exists(target):
                            >> return apache.DECLINED
                            >
                            > I changed it (personal preference and I have only Python content) to:
                            >
                            > if req.filename[:-3] != ".py":
                            > target = req.filename + ".py"
                            > else:
                            > target = req.filename
                            >
                            > if not os.path.exists(target):
                            > raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND



                            -------------------------------------------------------
                            SF email is sponsored by - The IT Product Guide
                            Read honest & candid reviews on hundreds of IT Products from real users.
                            Discover which products truly live up to the hype. Start reading now.
                            http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
                            _______________________________________________
                            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.