def send_head(self): """Only GET implemented for this. This sends the response code and MIME headers. Return value is a file object, or None. """ print 'Request :', self.path # traceback to sys.stdout url_tuple = urlparse.urlparse(self.path) url = url_tuple[2] domain = url_tuple[1] if domain.find('.google.') != -1: # bypass the cache for google domains req = urllib2.Request(self.path, None, self.txheaders) self.send_response(200) self.send_header("Content-type", 'text/html') self.end_headers() return urllib2.urlopen(req) dotloc = url.rfind('.') + 1 if dotloc and url[dotloc:] not in self.cached_types: return None # not a cached type - don't even try print 'Fetching :', self.path # traceback to sys.stdout thepage = google.doGetCachedPage(self.path) # XXXX should we check for errors here ? headerpos = thepage.find(self.googlemarker) if headerpos != -1: pos = self.markerlen + headerpos thepage = thepage[pos:] f = StringIO(thepage) # turn the page into a file like object self.send_response(200) self.send_header("Content-type", 'text/html') self.send_header("Content-Length", str(len(thepage))) self.end_headers() return f
def testCacheLong(self): """--cache should retrieve cache""" google.main(["--cache", self.url]) commandLineAnswer = self.lastOutput() google._output(google.doGetCachedPage(self.url), self.cacheparams) self.assertEqual(commandLineAnswer, self.lastOutput())
def doGetCachedPage(self, url, http_proxy = None): google.setLicense( self.license ) return google.doGetCachedPage(url, http_proxy)
def doGetCachedPage(self, url, http_proxy=None): #doGetCachedPage google.setLicense(self.license_key) return google.doGetCachedPage(url, http_proxy)