[Zope3-checkins] CVS: Zope3/src/zope/pagetemplate - pagetemplate.py:1.3 pagetemplatefile.py:1.4

Godefroid Chapelle gotcha@swing.be
Tue, 25 Mar 2003 06:23:41 -0500


Update of /cvs-repository/Zope3/src/zope/pagetemplate
In directory cvs.zope.org:/tmp/cvs-serv20400/pagetemplate

Modified Files:
	pagetemplate.py pagetemplatefile.py 
Log Message:
merging template_usage branch

connection to menu usage still to be done



=== Zope3/src/zope/pagetemplate/pagetemplate.py 1.2 => 1.3 ===
--- Zope3/src/zope/pagetemplate/pagetemplate.py:1.2	Wed Dec 25 09:15:13 2002
+++ Zope3/src/zope/pagetemplate/pagetemplate.py	Tue Mar 25 06:23:10 2003
@@ -92,6 +92,7 @@
                 'options': options,
                 'args': args,
                 'nothing': None,
+                'usage': TemplateUsage(options.get("template_usage", u'')),
                 }
         rval.update(self.pt_getEngine().getBaseNames())
         return rval
@@ -199,6 +200,25 @@
             return self.content_type == 'text/html'
         return self.is_html
 
+
+class TemplateUsage:
+    def __init__(self, value):
+        if type(value) <> type(u''):
+            raise TypeError('TemplateUsage should be initialized with a Unicode string : %s' % repr(value))
+        self.stringValue = value
+
+    def __str__(self):
+        return self.stringValue
+
+    def __getitem__(self, key):
+        if key == self.stringValue:
+            return self.stringValue
+        else:
+            return None 
+
+    def __nonzero__(self):
+        return self.stringValue <> u''
+        
 
 
 class PTRuntimeError(RuntimeError):


=== Zope3/src/zope/pagetemplate/pagetemplatefile.py 1.3 => 1.4 ===
--- Zope3/src/zope/pagetemplate/pagetemplatefile.py:1.3	Fri Mar 21 13:02:21 2003
+++ Zope3/src/zope/pagetemplate/pagetemplatefile.py	Tue Mar 25 06:23:10 2003
@@ -16,9 +16,10 @@
 Zope object encapsulating a Page Template from the filesystem.
 """
 
+__version__ = '$Revision$'[11:-2]
+
 __metaclass__ = type
 
-__version__ = '$Revision$'[11:-2]
 
 import os, sys
 import logging
@@ -35,12 +36,17 @@
     _v_last_read = 0
 
     def __init__(self, filename, _prefix=None):
-        if not isinstance(_prefix, str):
-            if _prefix is None:
-                _prefix = sys._getframe(1).f_globals
-            _prefix = package_home(_prefix)
+        path = self.get_path_from_prefix(_prefix)
+        self.filename = os.path.join(path, filename)
 
-        self.filename = os.path.join(_prefix, filename)
+    def get_path_from_prefix(self, _prefix):
+        if isinstance(_prefix, str):
+            path = _prefix
+        else:
+            if _prefix is None:
+                _prefix = sys._getframe(2).f_globals
+            path = package_home(_prefix)
+        return path
 
     def _cook_check(self):
         if self._v_last_read and not __debug__: