WebBrowser/AdBlock/AdBlockSubscription.py

branch
QtWebEngine
changeset 4860
0a44aff88bfa
parent 4859
36c4b21c9f7b
child 4902
7a49807e493c
equal deleted inserted replaced
4859:36c4b21c9f7b 4860:0a44aff88bfa
14 import hashlib 14 import hashlib
15 import base64 15 import base64
16 16
17 from PyQt5.QtCore import pyqtSignal, Qt, QObject, QByteArray, QDateTime, \ 17 from PyQt5.QtCore import pyqtSignal, Qt, QObject, QByteArray, QDateTime, \
18 QUrl, QUrlQuery, QCryptographicHash, QFile, QIODevice, QTextStream, \ 18 QUrl, QUrlQuery, QCryptographicHash, QFile, QIODevice, QTextStream, \
19 QDate, QTime, qVersion 19 QDate, QTime
20 from PyQt5.QtNetwork import QNetworkReply 20 from PyQt5.QtNetwork import QNetworkReply
21 21
22 from E5Gui import E5MessageBox 22 from E5Gui import E5MessageBox
23 23
24 import Utilities 24 import Utilities
410 self.tr( 410 self.tr(
411 """Unable to open AdBlock file '{0}' for writing.""") 411 """Unable to open AdBlock file '{0}' for writing.""")
412 .file(fileName)) 412 .file(fileName))
413 return 413 return
414 414
415 # ToDo:AdBlock debug this
416 from WebBrowser.WebBrowserWindow import WebBrowserWindow 415 from WebBrowser.WebBrowserWindow import WebBrowserWindow
417 if WebBrowserWindow.adBlockManager().useLimitedEasyList() and \ 416 if WebBrowserWindow.adBlockManager().useLimitedEasyList() and \
418 self.url().toString().startswith( 417 self.url().toString().startswith(
419 WebBrowserWindow.adBlockManager().getDefaultSubscriptionUrl()): 418 WebBrowserWindow.adBlockManager().getDefaultSubscriptionUrl()):
419 limited = True
420 # ignore Third-party advertisers rules for performance 420 # ignore Third-party advertisers rules for performance
421 # whitelist rules at the end will be used 421 # whitelist rules at the end will be used
422 part1 = response.left(response.indexOf( 422 index = response.indexOf(
423 "!---------------------------" 423 "!---------------------------"
424 "Third-party advertisers" 424 "Third-party advertisers"
425 "---------------------------!")) 425 "---------------------------!")
426 part2 = response.mid(response.indexOf( 426 part1 = response.left(index)
427 index = response.indexOf(
427 "!-----------------------" 428 "!-----------------------"
428 "Whitelists to fix broken sites" 429 "Whitelists to fix broken sites"
429 "------------------------!")) 430 "------------------------!")
431 part2 = response.mid(index)
430 f.write(part1) 432 f.write(part1)
431 f.write(part2) 433 f.write(part2)
432 else: 434 else:
435 limited = False
433 f.write(response) 436 f.write(response)
434 f.close() 437 f.close()
435 self.__lastUpdate = QDateTime.currentDateTime() 438 self.__lastUpdate = QDateTime.currentDateTime()
436 if self.__validateCheckSum(fileName): 439 if limited or self.__validateCheckSum(fileName):
437 self.__loadRules() 440 self.__loadRules()
438 else: 441 else:
439 QFile.remove(fileName) 442 QFile.remove(fileName)
440 self.__downloading = None 443 self.__downloading = None
441 reply.deleteLater() 444 reply.deleteLater()
444 """ 447 """
445 Private method to check the subscription file's checksum. 448 Private method to check the subscription file's checksum.
446 449
447 @param fileName name of the file containing the subscription (string) 450 @param fileName name of the file containing the subscription (string)
448 @return flag indicating a valid file (boolean). A file is considered 451 @return flag indicating a valid file (boolean). A file is considered
449 valid, if the checksum is OK or the file does not contain a 452 valid, if the checksum is OK, the file does not contain a
450 checksum (i.e. cannot be checked). 453 checksum (i.e. cannot be checked) or we are using the limited
454 EasyList (because we fiddled with the original).
451 """ 455 """
452 try: 456 try:
453 f = open(fileName, "r", encoding="utf-8") 457 f = open(fileName, "r", encoding="utf-8")
454 data = f.read() 458 data = f.read()
455 f.close() 459 f.close()

eric ide

mercurial