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

[Cheetahtemplate-discuss] can't fill templates from strings

Expand Messages
  • Doug Wyatt
    Hi, I m using Cheetah 0.9.15 on Mac OS X 10.3. I can compile and fill templates from files just fine. I changed my code so that I was creating a template from
    Message 1 of 4 , Jul 3, 2004
    • 0 Attachment
      Hi,

      I'm using Cheetah 0.9.15 on Mac OS X 10.3.

      I can compile and fill templates from files just fine. I changed my
      code so that I was creating a template from a string, however, and this
      fails:

      Traceback (most recent call last):
      ...
      File
      "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
      python2.3/site-packages/Cheetah/Template.py", line 156, in __init__
      self.compile(source, file)
      File
      "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
      python2.3/site-packages/Cheetah/Template.py", line 245, in compile
      compiler.compile()
      File
      "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
      python2.3/site-packages/Cheetah/Compiler.py", line 1086, in compile
      self.parse()
      File
      "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
      python2.3/site-packages/Cheetah/Parser.py", line 1036, in parse
      self.eatDirective()
      File
      "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
      python2.3/site-packages/Cheetah/Parser.py", line 1150, in eatDirective
      self.directiveEaters[directiveKey]()
      File
      "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
      python2.3/site-packages/Cheetah/Parser.py", line 1470, in eatExtends
      mod =
      self._templateObj._importAsDummyModule('\n'.join(self._importStatements)
      )
      File
      "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
      python2.3/site-packages/Cheetah/Template.py", line 453, in
      _importAsDummyModule
      packageName = self._makeDummyPackageForDir(moduleDir)
      File
      "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
      python2.3/site-packages/Cheetah/Template.py", line 477, in
      _makeDummyPackageForDir
      isPackageDir=1,forceReload=1)
      File
      "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
      python2.3/site-packages/Cheetah/Template.py", line 529, in
      _importModuleFromDirectory
      fp, pathname, stuff = imp.find_module(moduleName, [directory])
      ImportError: No module named tmp

      In _importModuleFromDirectory:
      fullModuleName= Cheetah.Temp._tmp
      moduleName= tmp
      directory= /

      So I guess Python is not finding the "__init__.py" written into /tmp.

      I wonder if it's because on Mac OS X, /tmp is a symlink to /private/tmp
      ?

      Would appreciate any help.

      Thanks
      Doug



      -------------------------------------------------------
      This SF.Net email sponsored by Black Hat Briefings & Training.
      Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
      digital self defense, top technical experts, no vendor pitches,
      unmatched networking opportunities. Visit www.blackhat.com
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    • Doug Wyatt
      I did some more poking ... I tried writing the template to a file in /tmp and passing this file to the Template constructor and got the same error. I then
      Message 2 of 4 , Jul 3, 2004
      • 0 Attachment
        I did some more poking ... I tried writing the template to a file in
        /tmp and passing this file to the Template constructor and got the same
        error. I then changed the file's path to /private/tmp and no longer got
        an error.

        So apparently the Python import mechanism doesn't like being pointed at
        a symlink? This is Python 2.3.3.

        Doug

        On Jul 3, 2004, at 17:05, Doug Wyatt wrote:

        > Hi,
        >
        > I'm using Cheetah 0.9.15 on Mac OS X 10.3.
        >
        > I can compile and fill templates from files just fine. I changed my
        > code so that I was creating a template from a string, however, and
        > this fails:
        >
        > Traceback (most recent call last):
        > ...
        > File
        > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
        > python2.3/site-packages/Cheetah/Template.py", line 156, in __init__
        > self.compile(source, file)
        > File
        > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
        > python2.3/site-packages/Cheetah/Template.py", line 245, in compile
        > compiler.compile()
        > File
        > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
        > python2.3/site-packages/Cheetah/Compiler.py", line 1086, in compile
        > self.parse()
        > File
        > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
        > python2.3/site-packages/Cheetah/Parser.py", line 1036, in parse
        > self.eatDirective()
        > File
        > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
        > python2.3/site-packages/Cheetah/Parser.py", line 1150, in eatDirective
        > self.directiveEaters[directiveKey]()
        > File
        > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
        > python2.3/site-packages/Cheetah/Parser.py", line 1470, in eatExtends
        > mod =
        > self._templateObj._importAsDummyModule('\n'.join(self._importStatements
        > ))
        > File
        > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
        > python2.3/site-packages/Cheetah/Template.py", line 453, in
        > _importAsDummyModule
        > packageName = self._makeDummyPackageForDir(moduleDir)
        > File
        > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
        > python2.3/site-packages/Cheetah/Template.py", line 477, in
        > _makeDummyPackageForDir
        > isPackageDir=1,forceReload=1)
        > File
        > "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
        > python2.3/site-packages/Cheetah/Template.py", line 529, in
        > _importModuleFromDirectory
        > fp, pathname, stuff = imp.find_module(moduleName, [directory])
        > ImportError: No module named tmp
        >
        > In _importModuleFromDirectory:
        > fullModuleName= Cheetah.Temp._tmp
        > moduleName= tmp
        > directory= /
        >
        > So I guess Python is not finding the "__init__.py" written into /tmp.
        >
        > I wonder if it's because on Mac OS X, /tmp is a symlink to
        > /private/tmp ?
        >
        > Would appreciate any help.
        >
        > Thanks
        > Doug
        >
        >
        >
        > -------------------------------------------------------
        > This SF.Net email sponsored by Black Hat Briefings & Training.
        > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -digital
        > self defense, top technical experts, no vendor pitches,unmatched
        > networking opportunities. Visit www.blackhat.com
        > _______________________________________________
        > Cheetahtemplate-discuss mailing list
        > Cheetahtemplate-discuss@...
        > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        >
        >



        -------------------------------------------------------
        This SF.Net email sponsored by Black Hat Briefings & Training.
        Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
        digital self defense, top technical experts, no vendor pitches,
        unmatched networking opportunities. Visit www.blackhat.com
        _______________________________________________
        Cheetahtemplate-discuss mailing list
        Cheetahtemplate-discuss@...
        https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
      • Aaron Held
        Can you post the code? I do this all the time: templateDef= Hello $rf rf = Aaron t = Template(templateDef,[{ rf :rf}]) ... This SF.Net email sponsored
        Message 3 of 4 , Jul 6, 2004
        • 0 Attachment
          Can you post the code?

          I do this all the time:

          templateDef='''\
          Hello $rf'''
          rf = 'Aaron'
          t = Template(templateDef,[{'rf':rf}])

          Doug Wyatt wrote:

          > Hi,
          >
          > I'm using Cheetah 0.9.15 on Mac OS X 10.3.
          >
          > I can compile and fill templates from files just fine. I changed my
          > code so that I was creating a template from a string, however, and
          > this fails:
          >
          > Traceback (most recent call last):
          > ...
          > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
          > python2.3/site-packages/Cheetah/Template.py", line 156, in __init__
          > self.compile(source, file)
          > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
          > python2.3/site-packages/Cheetah/Template.py", line 245, in compile
          > compiler.compile()
          > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
          > python2.3/site-packages/Cheetah/Compiler.py", line 1086, in compile
          > self.parse()
          > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
          > python2.3/site-packages/Cheetah/Parser.py", line 1036, in parse
          > self.eatDirective()
          > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
          > python2.3/site-packages/Cheetah/Parser.py", line 1150, in eatDirective
          > self.directiveEaters[directiveKey]()
          > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
          > python2.3/site-packages/Cheetah/Parser.py", line 1470, in eatExtends
          > mod =
          > self._templateObj._importAsDummyModule('\n'.join(self._importStatements)
          > )
          > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
          > python2.3/site-packages/Cheetah/Template.py", line 453, in
          > _importAsDummyModule
          > packageName = self._makeDummyPackageForDir(moduleDir)
          > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
          > python2.3/site-packages/Cheetah/Template.py", line 477, in
          > _makeDummyPackageForDir
          > isPackageDir=1,forceReload=1)
          > File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
          > python2.3/site-packages/Cheetah/Template.py", line 529, in
          > _importModuleFromDirectory
          > fp, pathname, stuff = imp.find_module(moduleName, [directory])
          > ImportError: No module named tmp
          >
          > In _importModuleFromDirectory:
          > fullModuleName= Cheetah.Temp._tmp
          > moduleName= tmp
          > directory= /
          >
          > So I guess Python is not finding the "__init__.py" written into /tmp.
          >
          > I wonder if it's because on Mac OS X, /tmp is a symlink to
          > /private/tmp ?
          >
          > Would appreciate any help.
          >
          > Thanks
          > Doug
          >
          >
          >
          > -------------------------------------------------------
          > This SF.Net email sponsored by Black Hat Briefings & Training.
          > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital
          > self defense, top technical experts, no vendor pitches, unmatched
          > networking opportunities. Visit www.blackhat.com
          > _______________________________________________
          > Cheetahtemplate-discuss mailing list
          > Cheetahtemplate-discuss@...
          > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss




          -------------------------------------------------------
          This SF.Net email sponsored by Black Hat Briefings & Training.
          Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
          digital self defense, top technical experts, no vendor pitches,
          unmatched networking opportunities. Visit www.blackhat.com
          _______________________________________________
          Cheetahtemplate-discuss mailing list
          Cheetahtemplate-discuss@...
          https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
        • Doug Wyatt
          Hi Aaron, Thanks for the reply. Your example works fine. I must be misunderstanding something about using inheritence in my templates because the problem only
          Message 4 of 4 , Jul 6, 2004
          • 0 Attachment
            Hi Aaron,

            Thanks for the reply.

            Your example works fine. I must be misunderstanding something about
            using inheritence in my templates because the problem only manifests
            with them. I'll try to boil this down to a small test case if
            necessary, but before I do that, here are what seem like the relevant
            bits:

            source text:
            #extends sonosphere
            sonosphere.tmpl:
            #extends basepage
            basepage.tmpl:
            #extends rootpage
            #implements respond
            rootpage.py:
            class rootpage(Template):

            These are all in the same directory.

            Is the "#implements respond" necessary in templates which inherit from
            basepage?

            Also, I have no idea why, but this fixes the problem if I invoke it
            before my templates:
            import tempfile
            if tempfile.tempdir == None and tempfile.gettempdir() == '/tmp' and
            sys.platform == 'darwin':
            tempfile.tempdir = '/private/tmp'

            I'm running in a CGI context if that matters, but my web server is on
            localhost and runs as me, not "nobody" or "www".

            Also, I'm inserting my template directory at the front of sys.path.

            Thanks
            Doug


            On Jul 6, 2004, at 12:20, Aaron Held wrote:

            > Can you post the code?
            >
            > I do this all the time:
            >
            > templateDef='''\
            > Hello $rf'''
            > rf = 'Aaron'
            > t = Template(templateDef,[{'rf':rf}])
            >
            > Doug Wyatt wrote:
            >
            >> Hi,
            >>
            >> I'm using Cheetah 0.9.15 on Mac OS X 10.3.
            >>
            >> I can compile and fill templates from files just fine. I changed my
            >> code so that I was creating a template from a string, however, and
            >> this fails:
            >>
            >> Traceback (most recent call last):
            >> ...
            >> File
            >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
            >> python2.3/site-packages/Cheetah/Template.py", line 156, in __init__
            >> self.compile(source, file)
            >> File
            >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
            >> python2.3/site-packages/Cheetah/Template.py", line 245, in compile
            >> compiler.compile()
            >> File
            >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
            >> python2.3/site-packages/Cheetah/Compiler.py", line 1086, in compile
            >> self.parse()
            >> File
            >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
            >> python2.3/site-packages/Cheetah/Parser.py", line 1036, in parse
            >> self.eatDirective()
            >> File
            >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
            >> python2.3/site-packages/Cheetah/Parser.py", line 1150, in
            >> eatDirective
            >> self.directiveEaters[directiveKey]()
            >> File
            >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
            >> python2.3/site-packages/Cheetah/Parser.py", line 1470, in eatExtends
            >> mod =
            >> self._templateObj._importAsDummyModule('\n'.join(self._importStatement
            >> s) )
            >> File
            >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
            >> python2.3/site-packages/Cheetah/Template.py", line 453, in
            >> _importAsDummyModule
            >> packageName = self._makeDummyPackageForDir(moduleDir)
            >> File
            >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
            >> python2.3/site-packages/Cheetah/Template.py", line 477, in
            >> _makeDummyPackageForDir
            >> isPackageDir=1,forceReload=1)
            >> File
            >> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
            >> python2.3/site-packages/Cheetah/Template.py", line 529, in
            >> _importModuleFromDirectory
            >> fp, pathname, stuff = imp.find_module(moduleName, [directory])
            >> ImportError: No module named tmp
            >>
            >> In _importModuleFromDirectory:
            >> fullModuleName= Cheetah.Temp._tmp
            >> moduleName= tmp
            >> directory= /
            >>
            >> So I guess Python is not finding the "__init__.py" written into /tmp.
            >>
            >> I wonder if it's because on Mac OS X, /tmp is a symlink to
            >> /private/tmp ?
            >>
            >> Would appreciate any help.
            >>
            >> Thanks
            >> Doug
            >>
            >>
            >>
            >> -------------------------------------------------------
            >> This SF.Net email sponsored by Black Hat Briefings & Training.
            >> Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital
            >> self defense, top technical experts, no vendor pitches, unmatched
            >> networking opportunities. Visit www.blackhat.com
            >> _______________________________________________
            >> Cheetahtemplate-discuss mailing list
            >> Cheetahtemplate-discuss@...
            >> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
            >
            >
            >
            >
            > -------------------------------------------------------
            > This SF.Net email sponsored by Black Hat Briefings & Training.
            > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital
            > self defense, top technical experts, no vendor pitches, unmatched
            > networking opportunities. Visit www.blackhat.com
            > _______________________________________________
            > Cheetahtemplate-discuss mailing list
            > Cheetahtemplate-discuss@...
            > https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
            >
            >



            -------------------------------------------------------
            This SF.Net email sponsored by Black Hat Briefings & Training.
            Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
            digital self defense, top technical experts, no vendor pitches,
            unmatched networking opportunities. Visit www.blackhat.com
            _______________________________________________
            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.