WebBrowser/SafeBrowsing/SafeBrowsingCache.py

branch
safe_browsing
changeset 5829
d3448873ced3
parent 5820
b610cb5b501a
child 5847
fd1262c3fa79
--- a/WebBrowser/SafeBrowsing/SafeBrowsingCache.py	Sun Jul 30 19:56:04 2017 +0200
+++ b/WebBrowser/SafeBrowsing/SafeBrowsingCache.py	Fri Aug 04 18:38:45 2017 +0200
@@ -18,7 +18,8 @@
 
 import os
 
-from PyQt5.QtCore import QObject, QByteArray, QCryptographicHash
+from PyQt5.QtCore import QObject, QByteArray, QCryptographicHash, \
+    QCoreApplication, QEventLoop
 from PyQt5.QtSql import QSql, QSqlDatabase, QSqlQuery
 
 from .SafeBrowsingUtilities import toHex
@@ -283,7 +284,7 @@
             try:
                 query = QSqlQuery(db)
                 query.prepare(
-                    queryStr.format(",".join(["?" * len(hashValues)])))
+                    queryStr.format(",".join(["?"] * len(hashValues))))
                 for hashValue in hashValues:
                     query.addBindValue(QByteArray(hashValue),
                                        QSql.In | QSql.Binary)
@@ -294,7 +295,7 @@
                     threatType = query.value(0)
                     platformType = query.value(1)
                     threatEntryType = query.value(2)
-                    hasExpired = query.value(3)     # TODO: check if bool
+                    hasExpired = bool(query.value(3))
                     threatList = ThreatList(threatType, platformType,
                                             threatEntryType)
                     output.append((threatList, hasExpired))
@@ -327,7 +328,7 @@
             try:
                 query = QSqlQuery(db)
                 query.prepare(
-                    queryStr.format(",".join(["?" * len(prefixes)])))
+                    queryStr.format(",".join(["?"] * len(prefixes))))
                 for prefix in prefixes:
                     query.addBindValue(prefix)
                 
@@ -338,7 +339,7 @@
                     threatType = query.value(1)
                     platformType = query.value(2)
                     threatEntryType = query.value(3)
-                    negativeCacheExpired = query.value(4)  # TODO: check if bool
+                    negativeCacheExpired = bool(query.value(4))
                     threatList = ThreatList(threatType, platformType,
                                             threatEntryType)
                     output.append((threatList, fullHash, negativeCacheExpired))
@@ -627,7 +628,7 @@
         db = QSqlDatabase.database(self.__connectionName)
         if db.isOpen():
             db.transaction()
-            hash = QCryptographicHash(QCryptographicHash.Sha256)
+            sha256Hash = QCryptographicHash(QCryptographicHash.Sha256)
             try:
                 query = QSqlQuery(db)
                 query.prepare(queryStr)
@@ -638,12 +639,13 @@
                 query.exec_()
                 
                 while query.next():
-                    hash.addData(query.value(0))
+                    sha256Hash.addData(query.value(0))
+                    QCoreApplication.processEvents(QEventLoop.AllEvents, 200)
                 del query
             finally:
                 db.commit()
             
-            checksum = bytes(hash.result())
+            checksum = bytes(sha256Hash.result())
         
         return checksum
     

eric ide

mercurial