[Checkins] SVN: grok/trunk/src/grok/ forbid unrecognized files in
template directories
Wolfgang Schnerring
wosc at wosc.de
Tue Oct 17 10:19:32 EDT 2006
Log message for revision 70748:
forbid unrecognized files in template directories
Changed:
U grok/trunk/src/grok/_grok.py
A grok/trunk/src/grok/tests/view/dirtemplatesonly/
A grok/trunk/src/grok/tests/view/dirtemplatesonly/index.pt
A grok/trunk/src/grok/tests/view/dirtemplatesonly/invalid.txt
A grok/trunk/src/grok/tests/view/dirtemplatesonly.py
-=-
Modified: grok/trunk/src/grok/_grok.py
===================================================================
--- grok/trunk/src/grok/_grok.py 2006-10-17 13:59:47 UTC (rev 70747)
+++ grok/trunk/src/grok/_grok.py 2006-10-17 14:19:31 UTC (rev 70748)
@@ -144,11 +144,16 @@
if resource_exists(dotted_name, directory_name):
template_files = resource_listdir(dotted_name, directory_name)
for template_file in template_files:
- if not template_file.endswith(".pt"):
+ if template_file.startswith('.') or template_file.endswith('~'):
continue
+
template_name = template_file[:-3]
template_path = os.path.join(directory_name, template_file)
+ if not template_file.endswith('.pt'):
+ raise GrokError("Unrecognized file '%s' in template directory '%s'."
+ % (template_file, directory_name), module)
+
contents = resource_string(dotted_name, template_path)
template = PageTemplate(contents)
template.__grok_name__ = template_name
Added: grok/trunk/src/grok/tests/view/dirtemplatesonly/index.pt
===================================================================
--- grok/trunk/src/grok/tests/view/dirtemplatesonly/index.pt 2006-10-17 13:59:47 UTC (rev 70747)
+++ grok/trunk/src/grok/tests/view/dirtemplatesonly/index.pt 2006-10-17 14:19:31 UTC (rev 70748)
@@ -0,0 +1 @@
+nothing to see here
Added: grok/trunk/src/grok/tests/view/dirtemplatesonly/invalid.txt
===================================================================
--- grok/trunk/src/grok/tests/view/dirtemplatesonly/invalid.txt 2006-10-17 13:59:47 UTC (rev 70747)
+++ grok/trunk/src/grok/tests/view/dirtemplatesonly/invalid.txt 2006-10-17 14:19:31 UTC (rev 70748)
@@ -0,0 +1 @@
+nothing to see here
Added: grok/trunk/src/grok/tests/view/dirtemplatesonly.py
===================================================================
--- grok/trunk/src/grok/tests/view/dirtemplatesonly.py 2006-10-17 13:59:47 UTC (rev 70747)
+++ grok/trunk/src/grok/tests/view/dirtemplatesonly.py 2006-10-17 14:19:31 UTC (rev 70748)
@@ -0,0 +1,12 @@
+"""
+A template directory may only contain recognized template files:
+
+ >>> grok.grok(__name__)
+ Traceback (most recent call last):
+ ...
+ GrokError: Unrecognized file 'invalid.txt' in template directory 'dirtemplatesonly'.
+"""
+import grok
+
+class Mammoth(grok.Model):
+ pass
More information about the Checkins
mailing list