Example #1
0
 def metaData(self, url):
     k = url.toEncoded()
     if k in self.cache:
         metaData, buf, mtime = self.cache[k]
         if buf:
             return metaData
     # return non-valid
     metaData = QtNetwork.QNetworkCacheMetaData()
     return metaData
Example #2
0
 def metaData(self, url):
     k = url.toString(QUrl.FullyEncoded)
     if k in self.cache:
         metaData, buf, mtime = self.cache.pop(k)
         if buf:
             return metaData
     # return non-valid
     metaData = QtNetwork.QNetworkCacheMetaData()
     return metaData
Example #3
0
    def metaData(self, url):
        print((list(self.cache.keys())))
        k = url.toEncoded()
        if k in self.cache:
            metaData, buf, mtime = self.cache[k]
            if buf:
                return metaData
        responses = []
        for row in self.Data.read_responses_by_url(self.cursor, k):
            response = [m or '' for m in row]
            if int(response[ResponsesTable.RES_LENGTH]) > 0 and str(
                    response[ResponsesTable.STATUS]).startswith('2'):
                responses.append(response)
        if len(responses) > 0:
            metaData = QtNetwork.QNetworkCacheMetaData()
            metaData.setUrl(url)
            headers = bytes(responses[-1][ResponsesTable.RES_HEADERS])
            rawHeaders = []
            for line in headers.splitlines():
                if b':' in line:
                    name, value = [m.strip() for m in line.split(b':', 1)]
                    rawHeaders.append((QByteArray(name), QByteArray(value)))
                    try:
                        if b'last-modified' == name.lower():
                            metaData.setLastModified(
                                QDateTime.fromString(value.decode('utf-8')))
                        elif b'expires' == name.lower():
                            metaData.setExpirationDate(
                                QDateTime.fromString(value.decode('utf-8')))
                    except Exception as e:
                        print(('ignoring error: %s' % e))

            metaData.setRawHeaders(rawHeaders)
            buf = QByteArray(bytes(responses[-1][ResponsesTable.RES_DATA]))
            self.cache[k] = [metaData, buf, time.time()]
        else:
            # return non-valid
            metaData = QtNetwork.QNetworkCacheMetaData()
        return metaData