def index_html(self, REQUEST, RESPONSE): """ The default view of the contents of a File or Image. Returns the contents of the file or image. Also, sets the Content-Type HTTP header to the objects content type. """ self._updateFromFS() view = _ViewEmulator().__of__(self) # If we have a conditional get, set status 304 and return # no content if _checkConditionalGET(view, extra_context={}): return '' RESPONSE.setHeader('Content-Type', self.content_type) # old-style If-Modified-Since header handling. if self._setOldCacheHeaders(): # Make sure the CachingPolicyManager gets a go as well _setCacheHeaders(view, extra_context={}) return '' data = self._readFile(0) data_len = len(data) RESPONSE.setHeader('Content-Length', data_len) #There are 2 Cache Managers which can be in play.... #need to decide which to use to determine where the cache headers #are decided on. if self.ZCacheable_getManager() is not None: self.ZCacheable_set(None) else: _setCacheHeaders(view, extra_context={}) return data
def pt_render(self, source=0, extra_context={}): self._updateFromFS() # Make sure the template has been loaded. result = FSPageTemplate.inheritedAttribute('pt_render')(self, source, extra_context) if not source: _setCacheHeaders(self, extra_context) return result
def pt_render(self, source=0, extra_context={}): self._updateFromFS() # Make sure the template has been loaded. result = FSPageTemplate.inheritedAttribute('pt_render')( self, source, extra_context ) if not source: _setCacheHeaders(self, extra_context) return result
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): """Render the document given a client object, REQUEST mapping, Response, and key word arguments.""" self._updateFromFS() kw["document_id"] = self.getId() kw["document_title"] = self.title if client is not None: if _checkConditionalGET(self, kw): return "" if not self._cache_namespace_keys: data = self.ZCacheable_get(default=_marker) if data is not _marker: # Return cached results. return data __traceback_info__ = self._filepath security = getSecurityManager() security.addContext(self) try: r = Globals.HTML.__call__(self, client, REQUEST, **kw) if client is None: # Called as subtemplate, so don't need error propagation! if RESPONSE is None: result = r else: result = decapitate(r, RESPONSE) if not self._cache_namespace_keys: self.ZCacheable_set(result) return result if not isinstance(r, basestring) or RESPONSE is None: if not self._cache_namespace_keys: self.ZCacheable_set(r) return r finally: security.removeContext(self) have_key = RESPONSE.headers.has_key if not (have_key("content-type") or have_key("Content-Type")): if self.__dict__.has_key("content_type"): c = self.content_type else: c, e = guess_content_type(self.getId(), r) RESPONSE.setHeader("Content-Type", c) if RESPONSE is not None: # caching policy manager hook _setCacheHeaders(self, {}) result = decapitate(r, RESPONSE) if not self._cache_namespace_keys: self.ZCacheable_set(result) return result
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): """Render the document given a client object, REQUEST mapping, Response, and key word arguments.""" self._updateFromFS() kw['document_id'] = self.getId() kw['document_title'] = self.title if client is not None: if _checkConditionalGET(self, kw): return '' if not self._cache_namespace_keys: data = self.ZCacheable_get(default=_marker) if data is not _marker: # Return cached results. return data __traceback_info__ = self._filepath security = getSecurityManager() security.addContext(self) try: r = Globals.HTML.__call__(self, client, REQUEST, **kw) if client is None: # Called as subtemplate, so don't need error propagation! if RESPONSE is None: result = r else: result = decapitate(r, RESPONSE) if not self._cache_namespace_keys: self.ZCacheable_set(result) return result if not isinstance(r, basestring) or RESPONSE is None: if not self._cache_namespace_keys: self.ZCacheable_set(r) return r finally: security.removeContext(self) have_key = RESPONSE.headers.has_key if not (have_key('content-type') or have_key('Content-Type')): if self.__dict__.has_key('content_type'): c = self.content_type else: c, e = guess_content_type(self.getId(), r) RESPONSE.setHeader('Content-Type', c) if RESPONSE is not None: # caching policy manager hook _setCacheHeaders(self, {}) result = decapitate(r, RESPONSE) if not self._cache_namespace_keys: self.ZCacheable_set(result) return result
def index_html(self, REQUEST, RESPONSE): """ The default view of the contents of a File or Image. Returns the contents of the file or image. Also, sets the Content-Type HTTP header to the objects content type. """ self._updateFromFS() data = self._readFile(0) data_len = len(data) last_mod = self._file_mod_time status = 200 # HTTP If-Modified-Since header handling. 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 # header. If the date string is not valid, we ignore it # rather than raise an error to be generally consistent # with common servers such as Apache (which can usually # understand the screwy date string as a lucky side effect # of the way they parse it). try: mod_since=long(DateTime(header).timeTime()) except: mod_since=None if mod_since is not None: if last_mod > 0 and last_mod <= mod_since: status = 304 data = '' #Last-Modified will get stomped on by a cache policy it there is #one set.... RESPONSE.setStatus(status) RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod)) RESPONSE.setHeader('Content-Type', self.content_type) if status != 304: # Avoid setting content-length for a 304. See RFC 2616. # Zope might still, for better or for worse, set a # content-length header with value "0". RESPONSE.setHeader('Content-Length', data_len) #There are 2 Cache Managers which can be in play.... #need to decide which to use to determine where the cache headers #are decided on. if self.ZCacheable_getManager() is not None: self.ZCacheable_set(None) else: _setCacheHeaders(_ViewEmulator().__of__(self), extra_context={}) return data
def pt_render(self, source=0, extra_context={}): self._updateFromFS() # Make sure the template has been loaded. if not source: # If we have a conditional get, set status 304 and return # no content if _checkConditionalGET(self, extra_context): return '' result = FSPageTemplate.inheritedAttribute('pt_render')(self, source, extra_context) if not source: _setCacheHeaders(self, extra_context) return result
def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw): """Render the document given a client object, REQUEST mapping, Response, and key word arguments.""" self._updateFromFS() if not self._cache_namespace_keys: data = self.ZCacheable_get(default=_marker) if data is not _marker: # Return cached results. return data kw['document_id'] =self.getId() kw['document_title']=self.title security=getSecurityManager() security.addContext(self) try: if client is None: # Called as subtemplate, so don't need error propagation! r=Globals.HTML.__call__(self, client, REQUEST, **kw) if RESPONSE is None: result = r else: result = decapitate(r, RESPONSE) if not self._cache_namespace_keys: self.ZCacheable_set(result) return result r=Globals.HTML.__call__(self, client, REQUEST, **kw) if type(r) is not type('') or RESPONSE is None: if not self._cache_namespace_keys: self.ZCacheable_set(r) return r finally: security.removeContext(self) have_key=RESPONSE.headers.has_key if not (have_key('content-type') or have_key('Content-Type')): if self.__dict__.has_key('content_type'): c=self.content_type else: c, e=guess_content_type(self.getId(), r) RESPONSE.setHeader('Content-Type', c) if RESPONSE is not None: # caching policy manager hook _setCacheHeaders(self, {}) result = decapitate(r, RESPONSE) if not self._cache_namespace_keys: self.ZCacheable_set(result) return result
def pt_render(self, source=0, extra_context={}): self._updateFromFS() # Make sure the template has been loaded. if not source: # If we have a conditional get, set status 304 and return # no content if _checkConditionalGET(self, extra_context): return '' result = FSPageTemplate.inheritedAttribute('pt_render')( self, source, extra_context ) if not source: _setCacheHeaders(self, extra_context) return result
def index_html(self, REQUEST, RESPONSE): """ The default view of the contents of a File or Image. Returns the contents of the file or image. Also, sets the Content-Type HTTP header to the objects content type. """ self._updateFromFS() data = self._data # HTTP If-Modified-Since header handling. 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 # header. If the date string is not valid, we ignore it # rather than raise an error to be generally consistent # with common servers such as Apache (which can usually # understand the screwy date string as a lucky side effect # of the way they parse it). try: mod_since = long(DateTime(header).timeTime()) except: mod_since = None if mod_since is not None: last_mod = self._file_mod_time if last_mod > 0 and last_mod <= mod_since: # Set header values since apache caching will return # Content-Length of 0 in response if size is not set here RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod)) RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Length', len(data)) RESPONSE.setStatus(304) return '' #Last-Modified will get stomped on by a cache policy it there is one set.... RESPONSE.setHeader('Last-Modified', rfc1123_date(self._file_mod_time)) RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Length', len(data)) #There are 2 Cache Managers which can be in play....need to decide which to use #to determine where the cache headers are decided on. if self.ZCacheable_getManager() is not None: self.ZCacheable_set(None) else: _setCacheHeaders(self, extra_context={}) return data
def index_html(self, REQUEST, RESPONSE): """ The default view of the contents of a File or Image. Returns the contents of the file or image. Also, sets the Content-Type HTTP header to the objects content type. """ self._updateFromFS() data = self._data # HTTP If-Modified-Since header handling. 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 # header. If the date string is not valid, we ignore it # rather than raise an error to be generally consistent # with common servers such as Apache (which can usually # understand the screwy date string as a lucky side effect # of the way they parse it). try: mod_since=long(DateTime(header).timeTime()) except: mod_since=None if mod_since is not None: last_mod = self._file_mod_time if last_mod > 0 and last_mod <= mod_since: # Set header values since apache caching will return # Content-Length of 0 in response if size is not set here RESPONSE.setHeader('Last-Modified', rfc1123_date(last_mod)) RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Length', len(data)) RESPONSE.setStatus(304) return '' #Last-Modified will get stomped on by a cache policy it there is one set.... RESPONSE.setHeader('Last-Modified', rfc1123_date(self._file_mod_time)) RESPONSE.setHeader('Content-Type', self.content_type) RESPONSE.setHeader('Content-Length', len(data)) #There are 2 Cache Managers which can be in play....need to decide which to use #to determine where the cache headers are decided on. if self.ZCacheable_getManager() is not None: self.ZCacheable_set(None) else: _setCacheHeaders(self, extra_context={}) return data
def ZCache_set(self, ob, data, view_name, keywords, mtime_func): """ An object is pushed into the cache Even though this cache implementation does not cache anything per se, this method is used as a suitable hook to activate the real heavy lifting done by the CachePolicyManager. """ if ob.meta_type not in VIEW_METATYPES: ob = _ViewEmulator().__of__(ob) return _setCacheHeaders(ob, extra_context={})
def pt_render(self, source=0, extra_context={}): self._updateFromFS() # Make sure the template has been loaded. try: result = FSPageTemplate.inheritedAttribute('pt_render')( self, source, extra_context) if not source: _setCacheHeaders(self, extra_context) return result except RuntimeError: if Globals.DevelopmentMode: err = FSPageTemplate.inheritedAttribute('pt_errors')(self) if not err: err = sys.exc_info() err_type = err[0] err_msg = '<pre>%s</pre>' % str(err[1]).replace("\'", "'") msg = 'FS Page Template %s has errors: %s.<br>%s' % ( self.id, err_type, html_quote(err_msg)) raise RuntimeError, msg else: raise
def pt_render(self, source=0, extra_context={}): self._updateFromFS() # Make sure the template has been loaded. try: result = FSPageTemplate.inheritedAttribute('pt_render')( self, source, extra_context ) if not source: _setCacheHeaders(self, extra_context) return result except RuntimeError: if Globals.DevelopmentMode: err = FSPageTemplate.inheritedAttribute( 'pt_errors' )( self ) if not err: err = sys.exc_info() err_type = err[0] err_msg = '<pre>%s</pre>' % replace( str(err[1]), "\'", "'" ) msg = 'FS Page Template %s has errors: %s.<br>%s' % ( self.id, err_type, html_quote(err_msg) ) raise RuntimeError, msg else: raise