[Checkins] SVN: z3c.pt/trunk/ - Get rid of package-relative magic
in constructor of BaseTemplateFile
Chris McDonough
chrism at plope.com
Sat Aug 9 12:46:29 EDT 2008
Log message for revision 89580:
- Get rid of package-relative magic in constructor of BaseTemplateFile
in favor of just requiring an absolute path or a path relative
to getcwd(). Rationale: it didn't work when called from __main__
when the template was relative to getcwd(), which is the 99% case
for people first trying it out. [chrism]
Changed:
U z3c.pt/trunk/CHANGES.txt
U z3c.pt/trunk/src/z3c/pt/template.py
U z3c.pt/trunk/src/z3c/pt/template.txt
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2008-08-09 16:18:54 UTC (rev 89579)
+++ z3c.pt/trunk/CHANGES.txt 2008-08-09 16:46:29 UTC (rev 89580)
@@ -4,6 +4,12 @@
Version 1.0dev
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- Get rid of package-relative magic in constructor of BaseTemplateFile
+ in favor of just requiring an absolute path or a path relative
+ to getcwd(). Rationale: it didn't work when called from __main__
+ when the template was relative to getcwd(), which is the 99% case
+ for people first trying it out. [chrism]
+
- Added support for METAL.
[malthe]
Modified: z3c.pt/trunk/src/z3c/pt/template.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/template.py 2008-08-09 16:18:54 UTC (rev 89579)
+++ z3c.pt/trunk/src/z3c/pt/template.py 2008-08-09 16:46:29 UTC (rev 89580)
@@ -116,23 +116,9 @@
self.auto_reload = auto_reload
self.cachedir = cachedir
- if not os.path.isabs(filename):
- for depth in (1, 2):
- frame = sys._getframe(depth)
- package_name = frame.f_globals['__name__']
+ filename = os.path.abspath(
+ os.path.normpath(os.path.expanduser(filename)))
- if package_name != self.__module__:
- break
-
- module = sys.modules[package_name]
- try:
- path = module.__path__[0]
- except AttributeError:
- path = module.__file__
- path = path[:path.rfind(os.sep)]
-
- filename = path + os.sep + filename
-
# make sure file exists
os.lstat(filename)
self.filename = filename
Modified: z3c.pt/trunk/src/z3c/pt/template.txt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/template.txt 2008-08-09 16:18:54 UTC (rev 89579)
+++ z3c.pt/trunk/src/z3c/pt/template.txt 2008-08-09 16:46:29 UTC (rev 89580)
@@ -22,11 +22,16 @@
>>> from z3c.pt import PageTemplateFile
>>> from z3c.pt import tests
>>> path = tests.__path__[0]
- >>> print PageTemplateFile(path+'/helloworld.pt')()
+ >>> t = PageTemplateFile(path+'/helloworld.pt')
+ >>> print t()
<div>
Hello World!
</div>
+ >>> import os
+ >>> t.filename.startswith(os.sep)
+ True
+
z3c.pt.pagetemplate.ViewPageTemplate
------------------------------------
More information about the Checkins
mailing list