Commit ceaa8f63 authored by Hanno Schlichting's avatar Hanno Schlichting

Changed PageTemplateFile not to load the file contents on Zope startup anymore...

Changed PageTemplateFile not to load the file contents on Zope startup anymore but on first access instead. This brings them inline with the zope.pagetemplate version and speeds up Zope startup.
parent cf2f9c02
...@@ -71,10 +71,6 @@ Zope Changes ...@@ -71,10 +71,6 @@ Zope Changes
Features added Features added
- Added LAZY_FILE_LOADING constant to PageTemplateFile. When set to True
Page Template files aren't lo aded and parsed on Zope startup anymore,
but on first access instead.
- Testing.ZopeTestCase: Introduced a "ZopeLite" test layer, making it - Testing.ZopeTestCase: Introduced a "ZopeLite" test layer, making it
possible to mix ZTC and non-ZTC tests much more freely. possible to mix ZTC and non-ZTC tests much more freely.
...@@ -179,6 +175,10 @@ Zope Changes ...@@ -179,6 +175,10 @@ Zope Changes
Bugs Fixed Bugs Fixed
- Changed PageTemplateFile not to load the file contents on Zope startup
anymore but on first access instead. This brings them inline with the
zope.pagetemplate version and speeds up Zope startup.
- Launchpad #147201: treat container-class in zope.conf as a string, - Launchpad #147201: treat container-class in zope.conf as a string,
making it possible to use types from extra products directories. making it possible to use types from extra products directories.
......
...@@ -31,8 +31,6 @@ from zope.pagetemplate.pagetemplatefile import sniff_type ...@@ -31,8 +31,6 @@ from zope.pagetemplate.pagetemplatefile import sniff_type
LOG = getLogger('PageTemplateFile') LOG = getLogger('PageTemplateFile')
LAZY_FILE_LOADING = False
def guess_type(filename, text): def guess_type(filename, text):
# check for XML ourself since guess_content_type can't # check for XML ourself since guess_content_type can't
...@@ -88,10 +86,6 @@ class PageTemplateFile(SimpleItem, Script, PageTemplate, Traversable): ...@@ -88,10 +86,6 @@ class PageTemplateFile(SimpleItem, Script, PageTemplate, Traversable):
self.filename = filename self.filename = filename
if not LAZY_FILE_LOADING:
content = open(filename).read()
self.pt_edit( content, guess_type(filename, content))
def pt_getContext(self): def pt_getContext(self):
root = self.getPhysicalRoot() root = self.getPhysicalRoot()
context = self._getContext() context = self._getContext()
......
...@@ -8,7 +8,6 @@ import transaction ...@@ -8,7 +8,6 @@ import transaction
from Testing.makerequest import makerequest from Testing.makerequest import makerequest
from Products.PageTemplates import PageTemplateFile as PTF
from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplateFile import PageTemplateFile
...@@ -197,29 +196,15 @@ class LineEndingsTestCase(unittest.TestCase): ...@@ -197,29 +196,15 @@ class LineEndingsTestCase(unittest.TestCase):
class LazyLoadingTestCase(unittest.TestCase): class LazyLoadingTestCase(unittest.TestCase):
TEMPFILENAME = tempfile.mktemp(".zpt") TEMPFILENAME = tempfile.mktemp(".zpt")
OLD_LAZY = None
def setUp(self):
self.OLD_LAZY = PTF.LAZY_FILE_LOADING
def tearDown(self): def tearDown(self):
if os.path.exists(self.TEMPFILENAME): if os.path.exists(self.TEMPFILENAME):
os.unlink(self.TEMPFILENAME) os.unlink(self.TEMPFILENAME)
PTF.LAZY_FILE_LOADING = self.OLD_LAZY
def test_not_lazy(self):
f = open(self.TEMPFILENAME, 'w')
print >> f, 'Lazyness'
f.close()
pt = PageTemplateFile(self.TEMPFILENAME)
self.failUnless(pt._text.startswith('Lazyness'))
self.failUnless(pt._v_program)
def test_lazy(self): def test_lazy(self):
f = open(self.TEMPFILENAME, 'w') f = open(self.TEMPFILENAME, 'w')
print >> f, 'Lazyness' print >> f, 'Lazyness'
f.close() f.close()
PTF.LAZY_FILE_LOADING = True
pt = PageTemplateFile(self.TEMPFILENAME) pt = PageTemplateFile(self.TEMPFILENAME)
self.failUnless(not pt._text and not pt._v_program) self.failUnless(not pt._text and not pt._v_program)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment