in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

Not Necessarily Dot Net

cheetah templates on Google App Engine

I've run across a few blog entries that indicate other people have managed to get this working, but I don't see any hints around (or even about) this particular problem. Maybe it's something that is just really well known for Genshi and Mako, and I just didn't make the connection.

Anyway, setup.py installs fine, with the pure python name mapper.

When I try to actually start using variables in my template, I get this exception:

'module' object has no attribute 'get_suffixes'

Traceback (most recent call last): File "blah/main.py", line 132, in Twiddle result = self.fill_view(variables)
File "blah/main.py", line 109, in fill_view return str(t)
File "blah/Cheetah/Template.py", line 982, in __str__ def __str__(self): return getattr(self, mainMethName)()
File "blah/applications/init/views/whatever/default.py", line 96, in respond _v = VFFSL(SL,"name",True) # '$name' on line 10, col 11
^^^
(That's my compiled template)

File "blah/Cheetah/NameMapper.py", line 255, in valueFromFrameOrSearchList frame = inspect.stack()[1][0]
File "/tmp/python.6884/usr/lib/python2.5/inspect.py", line 885, in stack return getouterframes(sys._getframe(1), context)
File "/tmp/python.6884/usr/lib/python2.5/inspect.py", line 866, in getouterframes framelist.append((frame,) + getframeinfo(frame, context))
File "/tmp/python.6884/usr/lib/python2.5/inspect.py", line 837, in getframeinfo filename = getsourcefile(frame) or getfile(frame)
File "/tmp/python.6884/usr/lib/python2.5/inspect.py", line 386, in getsourcefile for suffix, mode, kind in imp.get_suffixes(): AttributeError: 'module' object has no attribute 'get_suffixes'

get_suffixes is a method that Google doesn't allow into their sandbox.  The solution is to add a monkey patch in NameMapper.py.

Underneath the opening document comments, there's a credits section, followed by some imports:

import types
from types import StringType, InstanceType, ClassType, TypeType
from pprint import pformat
import inspect

You need to update the inspect module's reference to the imp module (do this just below the import):

def get_suffixes():
    return [('.py', 'U', 1)]
inspect.imp.get_suffixes = get_suffixes

Actually, that's probably simple enough that it's worth putting into a lambda:

inspect.imp.get_suffixes = lambda : [('.py', 'U', 1)]


Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
2015 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems