eric6/WebBrowser/SafeBrowsing/SafeBrowsingCache.py

changeset 7759
51aa6c6b66f7
parent 7628
f904d0eef264
child 7923
91e843545d9a
equal deleted inserted replaced
7758:dd54d33d21d2 7759:51aa6c6b66f7
149 db = QSqlDatabase.database(self.__connectionName) 149 db = QSqlDatabase.database(self.__connectionName)
150 db.transaction() 150 db.transaction()
151 try: 151 try:
152 query = QSqlQuery(db) 152 query = QSqlQuery(db)
153 # step 1: drop old tables 153 # step 1: drop old tables
154 query.exec_(self.drop_threat_list_stmt) 154 query.exec(self.drop_threat_list_stmt)
155 query.exec_(self.drop_full_hashes_stmt) 155 query.exec(self.drop_full_hashes_stmt)
156 query.exec_(self.drop_hash_prefix_stmt) 156 query.exec(self.drop_hash_prefix_stmt)
157 # step 2: drop old indices 157 # step 2: drop old indices
158 query.exec_(self.drop_full_hash_cue_idx) 158 query.exec(self.drop_full_hash_cue_idx)
159 query.exec_(self.drop_full_hash_expires_idx) 159 query.exec(self.drop_full_hash_expires_idx)
160 query.exec_(self.drop_full_hash_value_idx) 160 query.exec(self.drop_full_hash_value_idx)
161 # step 3: create tables 161 # step 3: create tables
162 query.exec_(self.create_threat_list_stmt) 162 query.exec(self.create_threat_list_stmt)
163 query.exec_(self.create_full_hashes_stmt) 163 query.exec(self.create_full_hashes_stmt)
164 query.exec_(self.create_hash_prefix_stmt) 164 query.exec(self.create_hash_prefix_stmt)
165 # step 4: create indices 165 # step 4: create indices
166 query.exec_(self.create_full_hash_cue_idx) 166 query.exec(self.create_full_hash_cue_idx)
167 query.exec_(self.create_full_hash_expires_idx) 167 query.exec(self.create_full_hash_expires_idx)
168 query.exec_(self.create_full_hash_value_idx) 168 query.exec(self.create_full_hash_value_idx)
169 finally: 169 finally:
170 del query 170 del query
171 db.commit() 171 db.commit()
172 172
173 def lookupFullHashes(self, hashValues): 173 def lookupFullHashes(self, hashValues):
197 queryStr.format(",".join(["?"] * len(hashValues)))) 197 queryStr.format(",".join(["?"] * len(hashValues))))
198 for hashValue in hashValues: 198 for hashValue in hashValues:
199 query.addBindValue(QByteArray(hashValue), 199 query.addBindValue(QByteArray(hashValue),
200 QSql.In | QSql.Binary) 200 QSql.In | QSql.Binary)
201 201
202 query.exec_() 202 query.exec()
203 203
204 while query.next(): # __IGNORE_WARNING_M523__ 204 while query.next(): # __IGNORE_WARNING_M523__
205 threatType = query.value(0) 205 threatType = query.value(0)
206 platformType = query.value(1) 206 platformType = query.value(1)
207 threatEntryType = query.value(2) 207 threatEntryType = query.value(2)
242 query.prepare( 242 query.prepare(
243 queryStr.format(",".join(["?"] * len(prefixes)))) 243 queryStr.format(",".join(["?"] * len(prefixes))))
244 for prefix in prefixes: 244 for prefix in prefixes:
245 query.addBindValue(prefix) 245 query.addBindValue(prefix)
246 246
247 query.exec_() 247 query.exec()
248 248
249 while query.next(): # __IGNORE_WARNING_M523__ 249 while query.next(): # __IGNORE_WARNING_M523__
250 fullHash = bytes(query.value(0)) 250 fullHash = bytes(query.value(0))
251 threatType = query.value(1) 251 threatType = query.value(1)
252 platformType = query.value(2) 252 platformType = query.value(2)
303 QSql.In | QSql.Binary) 303 QSql.In | QSql.Binary)
304 query.addBindValue(threatList.threatType) 304 query.addBindValue(threatList.threatType)
305 query.addBindValue(threatList.platformType) 305 query.addBindValue(threatList.platformType)
306 query.addBindValue(threatList.threatEntryType) 306 query.addBindValue(threatList.threatEntryType)
307 query.addBindValue(malwareThreatType) 307 query.addBindValue(malwareThreatType)
308 query.exec_() 308 query.exec()
309 del query 309 del query
310 310
311 query = QSqlQuery(db) 311 query = QSqlQuery(db)
312 query.prepare(updateQueryStr) 312 query.prepare(updateQueryStr)
313 query.addBindValue(QByteArray(hashValue), 313 query.addBindValue(QByteArray(hashValue),
314 QSql.In | QSql.Binary) 314 QSql.In | QSql.Binary)
315 query.addBindValue(threatList.threatType) 315 query.addBindValue(threatList.threatType)
316 query.addBindValue(threatList.platformType) 316 query.addBindValue(threatList.platformType)
317 query.addBindValue(threatList.threatEntryType) 317 query.addBindValue(threatList.threatEntryType)
318 query.exec_() 318 query.exec()
319 del query 319 del query
320 finally: 320 finally:
321 db.commit() 321 db.commit()
322 322
323 def deleteHashPrefixList(self, threatList): 323 def deleteHashPrefixList(self, threatList):
339 query = QSqlQuery(db) 339 query = QSqlQuery(db)
340 query.prepare(queryStr) 340 query.prepare(queryStr)
341 query.addBindValue(threatList.threatType) 341 query.addBindValue(threatList.threatType)
342 query.addBindValue(threatList.platformType) 342 query.addBindValue(threatList.platformType)
343 query.addBindValue(threatList.threatEntryType) 343 query.addBindValue(threatList.threatEntryType)
344 query.exec_() 344 query.exec()
345 del query 345 del query
346 finally: 346 finally:
347 db.commit() 347 db.commit()
348 348
349 def cleanupFullHashes(self, keepExpiredFor=43200): 349 def cleanupFullHashes(self, keepExpiredFor=43200):
365 if db.isOpen(): 365 if db.isOpen():
366 db.transaction() 366 db.transaction()
367 try: 367 try:
368 query = QSqlQuery(db) 368 query = QSqlQuery(db)
369 query.prepare(queryStr) 369 query.prepare(queryStr)
370 query.exec_() 370 query.exec()
371 del query 371 del query
372 finally: 372 finally:
373 db.commit() 373 db.commit()
374 374
375 def updateHashPrefixExpiration(self, threatList, hashPrefix, 375 def updateHashPrefixExpiration(self, threatList, hashPrefix,
403 query.addBindValue(QByteArray(hashPrefix), 403 query.addBindValue(QByteArray(hashPrefix),
404 QSql.In | QSql.Binary) 404 QSql.In | QSql.Binary)
405 query.addBindValue(threatList.threatType) 405 query.addBindValue(threatList.threatType)
406 query.addBindValue(threatList.platformType) 406 query.addBindValue(threatList.platformType)
407 query.addBindValue(threatList.threatEntryType) 407 query.addBindValue(threatList.threatEntryType)
408 query.exec_() 408 query.exec()
409 del query 409 del query
410 finally: 410 finally:
411 db.commit() 411 db.commit()
412 412
413 def getThreatLists(self): 413 def getThreatLists(self):
428 db.transaction() 428 db.transaction()
429 try: 429 try:
430 query = QSqlQuery(db) 430 query = QSqlQuery(db)
431 query.prepare(queryStr) 431 query.prepare(queryStr)
432 432
433 query.exec_() 433 query.exec()
434 434
435 while query.next(): # __IGNORE_WARNING_M523__ 435 while query.next(): # __IGNORE_WARNING_M523__
436 threatType = query.value(0) 436 threatType = query.value(0)
437 platformType = query.value(1) 437 platformType = query.value(1)
438 threatEntryType = query.value(2) 438 threatEntryType = query.value(2)
468 query = QSqlQuery(db) 468 query = QSqlQuery(db)
469 query.prepare(queryStr) 469 query.prepare(queryStr)
470 query.addBindValue(threatList.threatType) 470 query.addBindValue(threatList.threatType)
471 query.addBindValue(threatList.platformType) 471 query.addBindValue(threatList.platformType)
472 query.addBindValue(threatList.threatEntryType) 472 query.addBindValue(threatList.threatEntryType)
473 query.exec_() 473 query.exec()
474 del query 474 del query
475 finally: 475 finally:
476 db.commit() 476 db.commit()
477 477
478 def deleteThreatList(self, threatList): 478 def deleteThreatList(self, threatList):
494 query = QSqlQuery(db) 494 query = QSqlQuery(db)
495 query.prepare(queryStr) 495 query.prepare(queryStr)
496 query.addBindValue(threatList.threatType) 496 query.addBindValue(threatList.threatType)
497 query.addBindValue(threatList.platformType) 497 query.addBindValue(threatList.platformType)
498 query.addBindValue(threatList.threatEntryType) 498 query.addBindValue(threatList.threatEntryType)
499 query.exec_() 499 query.exec()
500 del query 500 del query
501 finally: 501 finally:
502 db.commit() 502 db.commit()
503 503
504 def updateThreatListClientState(self, threatList, clientState): 504 def updateThreatListClientState(self, threatList, clientState):
523 query.prepare(queryStr) 523 query.prepare(queryStr)
524 query.addBindValue(clientState) 524 query.addBindValue(clientState)
525 query.addBindValue(threatList.threatType) 525 query.addBindValue(threatList.threatType)
526 query.addBindValue(threatList.platformType) 526 query.addBindValue(threatList.platformType)
527 query.addBindValue(threatList.threatEntryType) 527 query.addBindValue(threatList.threatEntryType)
528 query.exec_() 528 query.exec()
529 del query 529 del query
530 finally: 530 finally:
531 db.commit() 531 db.commit()
532 532
533 def hashPrefixListChecksum(self, threatList): 533 def hashPrefixListChecksum(self, threatList):
556 query.prepare(queryStr) 556 query.prepare(queryStr)
557 query.addBindValue(threatList.threatType) 557 query.addBindValue(threatList.threatType)
558 query.addBindValue(threatList.platformType) 558 query.addBindValue(threatList.platformType)
559 query.addBindValue(threatList.threatEntryType) 559 query.addBindValue(threatList.threatEntryType)
560 560
561 query.exec_() 561 query.exec()
562 562
563 while query.next(): # __IGNORE_WARNING_M523__ 563 while query.next(): # __IGNORE_WARNING_M523__
564 sha256Hash.addData(query.value(0)) 564 sha256Hash.addData(query.value(0))
565 QCoreApplication.processEvents(QEventLoop.AllEvents, 565 QCoreApplication.processEvents(QEventLoop.AllEvents,
566 self.maxProcessEventsTime) 566 self.maxProcessEventsTime)
599 QSql.In | QSql.Binary) 599 QSql.In | QSql.Binary)
600 query.addBindValue(prefix[:4].hex()) 600 query.addBindValue(prefix[:4].hex())
601 query.addBindValue(threatList.threatType) 601 query.addBindValue(threatList.threatType)
602 query.addBindValue(threatList.platformType) 602 query.addBindValue(threatList.platformType)
603 query.addBindValue(threatList.threatEntryType) 603 query.addBindValue(threatList.threatEntryType)
604 query.exec_() 604 query.exec()
605 del query 605 del query
606 QCoreApplication.processEvents(QEventLoop.AllEvents, 606 QCoreApplication.processEvents(QEventLoop.AllEvents,
607 self.maxProcessEventsTime) 607 self.maxProcessEventsTime)
608 finally: 608 finally:
609 db.commit() 609 db.commit()
636 query.prepare(queryStr) 636 query.prepare(queryStr)
637 query.addBindValue(threatList.threatType) 637 query.addBindValue(threatList.threatType)
638 query.addBindValue(threatList.platformType) 638 query.addBindValue(threatList.platformType)
639 query.addBindValue(threatList.threatEntryType) 639 query.addBindValue(threatList.threatEntryType)
640 640
641 query.exec_() 641 query.exec()
642 642
643 index = 0 643 index = 0
644 while query.next(): # __IGNORE_WARNING_M523__ 644 while query.next(): # __IGNORE_WARNING_M523__
645 if index in indexes: 645 if index in indexes:
646 prefix = bytes(query.value(0)) 646 prefix = bytes(query.value(0))
692 query.addBindValue(threatList.platformType) 692 query.addBindValue(threatList.platformType)
693 query.addBindValue(threatList.threatEntryType) 693 query.addBindValue(threatList.threatEntryType)
694 for prefix in removeBatch: 694 for prefix in removeBatch:
695 query.addBindValue(QByteArray(prefix), 695 query.addBindValue(QByteArray(prefix),
696 QSql.In | QSql.Binary) 696 QSql.In | QSql.Binary)
697 query.exec_() 697 query.exec()
698 del query 698 del query
699 QCoreApplication.processEvents( 699 QCoreApplication.processEvents(
700 QEventLoop.AllEvents, self.maxProcessEventsTime) 700 QEventLoop.AllEvents, self.maxProcessEventsTime)
701 finally: 701 finally:
702 db.commit() 702 db.commit()

eric ide

mercurial