[Zope-Checkins] SVN: Zope/trunk/ 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
Log message for revision 80940: 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. Changed: U Zope/trunk/doc/CHANGES.txt U Zope/trunk/lib/python/Products/PageTemplates/PageTemplateFile.py U Zope/trunk/lib/python/Products/PageTemplates/tests/test_ptfile.py -=- Modified: Zope/trunk/doc/CHANGES.txt === --- Zope/trunk/doc/CHANGES.txt 2007-10-19 16:05:16 UTC (rev 80939) +++ Zope/trunk/doc/CHANGES.txt 2007-10-20 09:57:58 UTC (rev 80940) @@ -71,10 +71,6 @@ 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 possible to mix ZTC and non-ZTC tests much more freely. @@ -179,6 +175,10 @@ 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, making it possible to use types from extra products directories. Modified: Zope/trunk/lib/python/Products/PageTemplates/PageTemplateFile.py === --- Zope/trunk/lib/python/Products/PageTemplates/PageTemplateFile.py 2007-10-19 16:05:16 UTC (rev 80939) +++ Zope/trunk/lib/python/Products/PageTemplates/PageTemplateFile.py 2007-10-20 09:57:58 UTC (rev 80940) @@ -31,8 +31,6 @@ LOG = getLogger('PageTemplateFile') -LAZY_FILE_LOADING = False - def guess_type(filename, text): # check for XML ourself since guess_content_type can't @@ -88,10 +86,6 @@ self.filename = filename -if not LAZY_FILE_LOADING: -content = open(filename).read() -self.pt_edit( content, guess_type(filename, content)) - def pt_getContext(self): root = self.getPhysicalRoot() context = self._getContext() Modified: Zope/trunk/lib/python/Products/PageTemplates/tests/test_ptfile.py === --- Zope/trunk/lib/python/Products/PageTemplates/tests/test_ptfile.py 2007-10-19 16:05:16 UTC (rev 80939) +++ Zope/trunk/lib/python/Products/PageTemplates/tests/test_ptfile.py 2007-10-20 09:57:58 UTC (rev 80940) @@ -8,7 +8,6 @@ from Testing.makerequest import makerequest -from Products.PageTemplates import PageTemplateFile as PTF from Products.PageTemplates.PageTemplateFile import PageTemplateFile @@ -197,29 +196,15 @@ class LazyLoadingTestCase(unittest.TestCase): TEMPFILENAME = tempfile.mktemp(.zpt) -OLD_LAZY = None -def setUp(self): -self.OLD_LAZY = PTF.LAZY_FILE_LOADING - def tearDown(self): if os.path.exists(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): f = open(self.TEMPFILENAME, 'w') print f, 'Lazyness' f.close() -PTF.LAZY_FILE_LOADING = True pt = PageTemplateFile(self.TEMPFILENAME) self.failUnless(not pt._text and not pt._v_program) ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/trunk/ Launchpad #143902: Fixed App.ImageFile to use a stream iterator to output the file. Avoid loading the file content when guessing the mimetype and only load the first 1
Log message for revision 80941: Launchpad #143902: Fixed App.ImageFile to use a stream iterator to output the file. Avoid loading the file content when guessing the mimetype and only load the first 1024 bytes of the file when it cannot be guessed from the filename. Changed: U Zope/trunk/doc/CHANGES.txt U Zope/trunk/lib/python/App/ImageFile.py -=- Modified: Zope/trunk/doc/CHANGES.txt === --- Zope/trunk/doc/CHANGES.txt 2007-10-20 09:57:58 UTC (rev 80940) +++ Zope/trunk/doc/CHANGES.txt 2007-10-20 10:31:27 UTC (rev 80941) @@ -175,6 +175,11 @@ Bugs Fixed + - Launchpad #143902: Fixed App.ImageFile to use a stream iterator to +output the file. Avoid loading the file content when guessing the +mimetype and only load the first 1024 bytes of the file when it cannot +be guessed from the filename. + - 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. Modified: Zope/trunk/lib/python/App/ImageFile.py === --- Zope/trunk/lib/python/App/ImageFile.py 2007-10-20 09:57:58 UTC (rev 80940) +++ Zope/trunk/lib/python/App/ImageFile.py 2007-10-20 10:31:27 UTC (rev 80941) @@ -15,6 +15,7 @@ __version__='$Revision: 1.20 $'[11:-2] import os +import stat import time import Acquisition @@ -28,6 +29,8 @@ from zope.contenttype import guess_content_type +from ZPublisher.Iterators import filestream_iterator + class ImageFile(Acquisition.Explicit): Image objects stored in external files. @@ -48,16 +51,28 @@ max_age = 3600 # One hour self.cch = 'public,max-age=%d' % max_age -data = open(path, 'rb').read() -content_type, enc=guess_content_type(path, data) +# First try to get the content_type by name +content_type, enc=guess_content_type(path, default='failed') + +if content_type == 'failed': +# This failed, lets look into the file content +img = open(path, 'rb') +data = img.read(1024) # 1k should be enough +img.close() + +content_type, enc=guess_content_type(path, data) + if content_type: self.content_type=content_type else: -self.content_type='image/%s' % path[path.rfind('.')+1:] -self.__name__=path[path.rfind('/')+1:] -self.lmt=float(os.stat(path)[8]) or time.time() -self.lmh=rfc1123_date(self.lmt) +ext = os.path.splitext(path)[-1].replace('.', '') +self.content_type='image/%s' % ext +self.__name__ = os.path.split(path)[-1] +stat_info = os.stat(path) +self.size = stat_info[stat.ST_SIZE] +self.lmt = float(stat_info[stat.ST_MTIME]) or time.time() +self.lmh = rfc1123_date(self.lmt) def index_html(self, REQUEST, RESPONSE): Default document @@ -67,7 +82,8 @@ RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Last-Modified', self.lmh) RESPONSE.setHeader('Cache-Control', self.cch) -header=REQUEST.get_header('If-Modified-Since', None) +RESPONSE.setHeader('Content-Length', str(self.size).replace('L', '')) +header = REQUEST.get_header('If-Modified-Since', None) if header is not None: header=header.split(';')[0] # Some proxies seem to send invalid date strings for this @@ -87,7 +103,7 @@ RESPONSE.setStatus(304) return '' -return open(self.path,'rb').read() +return filestream_iterator(self.path, mode='rb') security.declarePublic('HEAD') def HEAD(self, REQUEST, RESPONSE): ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins
[Zope-Checkins] SVN: Zope/trunk/ Moved two implements declarations from Five into the proper classes.
Log message for revision 80945: Moved two implements declarations from Five into the proper classes. Changed: U Zope/trunk/doc/CHANGES.txt U Zope/trunk/lib/python/OFS/ObjectManager.py U Zope/trunk/lib/python/Products/Five/configure.zcml U Zope/trunk/lib/python/ZPublisher/HTTPRequest.py -=- Modified: Zope/trunk/doc/CHANGES.txt === --- Zope/trunk/doc/CHANGES.txt 2007-10-20 11:37:27 UTC (rev 80944) +++ Zope/trunk/doc/CHANGES.txt 2007-10-20 13:43:09 UTC (rev 80945) @@ -9,6 +9,8 @@ Restructuring + - Moved two implements declarations from Five into the proper classes. + - Document.sequence: replaced by zope.sequencesort - All Products folders as well as the zope and zope.app folders are Modified: Zope/trunk/lib/python/OFS/ObjectManager.py === --- Zope/trunk/lib/python/OFS/ObjectManager.py 2007-10-20 11:37:27 UTC (rev 80944) +++ Zope/trunk/lib/python/OFS/ObjectManager.py 2007-10-20 13:43:09 UTC (rev 80945) @@ -55,6 +55,8 @@ from zope.app.container.contained import ObjectAddedEvent from zope.app.container.contained import ObjectRemovedEvent from zope.app.container.contained import notifyContainerModified +from zope.app.container.interfaces import IContainer +from zope.interface import implements from OFS.event import ObjectWillBeAddedEvent from OFS.event import ObjectWillBeRemovedEvent import OFS.subscribers @@ -140,7 +142,7 @@ This class provides core behavior for collections of heterogeneous objects. -implements(IObjectManager) +implements(IObjectManager, IContainer) security = ClassSecurityInfo() security.declareObjectProtected(access_contents_information) Modified: Zope/trunk/lib/python/Products/Five/configure.zcml === --- Zope/trunk/lib/python/Products/Five/configure.zcml 2007-10-20 11:37:27 UTC (rev 80944) +++ Zope/trunk/lib/python/Products/Five/configure.zcml 2007-10-20 13:43:09 UTC (rev 80945) @@ -16,13 +16,4 @@ include package=.utilities / include package=.viewlet / - !-- this is really lying, but it's to please checkContainer -- - five:implements class=OFS.ObjectManager.ObjectManager - interface=zope.app.container.interfaces.IContainer / - - !-- make Zope 2's REQUEST implement the right thing -- - five:implements class=ZPublisher.HTTPRequest.HTTPRequest - interface=zope.publisher.interfaces.browser.IBrowserRequest - / - /configure Modified: Zope/trunk/lib/python/ZPublisher/HTTPRequest.py === --- Zope/trunk/lib/python/ZPublisher/HTTPRequest.py 2007-10-20 11:37:27 UTC (rev 80944) +++ Zope/trunk/lib/python/ZPublisher/HTTPRequest.py 2007-10-20 13:43:09 UTC (rev 80945) @@ -27,7 +27,9 @@ from zope.i18n.interfaces import IUserPreferredLanguages from zope.i18n.locales import locales, LoadLocaleError +from zope.interface import implements from zope.publisher.base import DebugFlags +from zope.publisher.interfaces.browser import IBrowserRequest # This may get overwritten during configuration default_encoding = 'iso-8859-15' @@ -119,12 +121,15 @@ values will be looked up in the order: environment variables, other variables, form data, and then cookies. +implements(IBrowserRequest) + _hacked_path=None args=() _file=None _urls = () retry_max_count=3 + def supports_retry(self): if self.retry_count self.retry_max_count: time.sleep(random.uniform(0, 2**(self.retry_count))) ___ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins