diff options
author | R. Tyler Ballance <tyler@monkeypox.org> | 2009-10-24 17:47:38 -0700 |
---|---|---|
committer | R. Tyler Ballance <tyler@monkeypox.org> | 2009-10-24 17:47:38 -0700 |
commit | 62481b7d1d7ad698a05ffc35488b29f6b32df8e4 (patch) | |
tree | d98757358e3b2c340b344bb6d58dd7deba19b325 /cheetah/Template.py | |
parent | 4c64fb2b00fb1121a42e48bcb53bac5f09841ee3 (diff) | |
parent | 7b1c2ad9f4e5830b5c88d95715014bb4044c090c (diff) | |
download | python-cheetah-maint.tar.gz |
Diffstat (limited to 'cheetah/Template.py')
-rw-r--r-- | cheetah/Template.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/cheetah/Template.py b/cheetah/Template.py index a8889d2..ec92208 100644 --- a/cheetah/Template.py +++ b/cheetah/Template.py @@ -994,22 +994,45 @@ class Template(Servlet): mainMethName = getattr(concreteTemplateClass,mainMethNameAttr, None) if mainMethName: def __str__(self): + rc = getattr(self, mainMethName)() + if isinstance(rc, unicode): + return rc.encode('utf-8') + return rc + def __unicode__(self): return getattr(self, mainMethName)() elif (hasattr(concreteTemplateClass, 'respond') and concreteTemplateClass.respond!=Servlet.respond): def __str__(self): + rc = self.respond() + if isinstance(rc, unicode): + return rc.encode('utf-8') + return rc + def __unicode__(self): return self.respond() else: def __str__(self): + rc = None + if hasattr(self, mainMethNameAttr): + rc = getattr(self,mainMethNameAttr)() + elif hasattr(self, 'respond'): + rc = self.respond() + else: + rc = super(self.__class__, self).__str__() + if isinstance(rc, unicode): + return rc.encode('utf-8') + return rc + def __unicode__(self): if hasattr(self, mainMethNameAttr): return getattr(self,mainMethNameAttr)() elif hasattr(self, 'respond'): return self.respond() else: - return super(self.__class__, self).__str__() + return super(self.__class__, self).__unicode__() __str__ = new.instancemethod(__str__, None, concreteTemplateClass) + __unicode__ = new.instancemethod(__unicode__, None, concreteTemplateClass) setattr(concreteTemplateClass, '__str__', __str__) + setattr(concreteTemplateClass, '__unicode__', __unicode__) _addCheetahPlumbingCodeToClass = classmethod(_addCheetahPlumbingCodeToClass) |