HI !
For what it's worth, Specto actually already uses this, I *think*. In the 0.2.2 series, if you look at the code in watch_web_static.py, you can see in lines 109-121:
if (self.cached == 1) or (os.path.exists(self.cacheFullPath_)): self.cached = 1
f = file(self.cacheFullPath_, "r")# Load up the cached version self.infoB_ = HTTPMessage(f)
if self.infoB_.has_key('last-modified'): request.add_header("If-Modified-Since", self.infoB_['last-modified'])
if self.infoB_.has_key('ETag'): request.add_header("If-None-Match", self.infoB_['ETag'])
try: response = urllib2.urlopen(request)
except (urllib2.URLError, BadStatusLine), e: self.error = True self.specto.logger.log(_("Watch: \"%s\" has error: ") % self.name + str(e), "error", self.__class__)
However,
- the code might not be elegant
- the code/logic might be wrong (after all, I took a long time doing it and I'm not sure I did it properly)
I don't know if that is conforming to your suggestions, or if you meant that
- some piece is missing?
- something is not working properly?
Also, I think the etag headers may not work properly with websites that use advertising/dynamic content, so, if I remember correctly my own code, the "error margin" (difference percentage based on file sizes) would override it.
HI ! static. py, you can see in lines 109-121:
For what it's worth, Specto actually already uses this, I *think*. In the 0.2.2 series, if you look at the code in watch_web_
if (self.cached == 1) or (os.path. exists( self.cacheFullP ath_)):
self. cached = 1 cacheFullPath_ , "r")# Load up the cached version
self. infoB_ = HTTPMessage(f) .has_key( 'last-modified' ):
request. add_header( "If-Modified- Since", self.infoB_ ['last- modified' ]) .has_key( 'ETag') :
request. add_header( "If-None- Match", self.infoB_ ['ETag' ])
response = urllib2. urlopen( request)
self. error = True
self. specto. logger. log(_(" Watch: \"%s\" has error: ") % self.name + str(e), "error", self.__class__)
f = file(self.
if self.infoB_
if self.infoB_
try:
except (urllib2.URLError, BadStatusLine), e:
However,
- the code might not be elegant
- the code/logic might be wrong (after all, I took a long time doing it and I'm not sure I did it properly)
I don't know if that is conforming to your suggestions, or if you meant that
- some piece is missing?
- something is not working properly?
Also, I think the etag headers may not work properly with websites that use advertising/dynamic content, so, if I remember correctly my own code, the "error margin" (difference percentage based on file sizes) would override it.