Sat, 21 Oct 2017 19:22:16 +0200
Some more fixes for the web browser NG.
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

1  # * coding: utf8 * 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

2  
5389
9b1c800daff3
Updated copyright for 2017.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5194
diff
changeset

3  # Copyright (c) 2009  2017 Detlev Offenbach <detlev@dieoffenbachs.de> 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

4  # 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

5  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

6  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

7  Module implementing the AdBlock rule class. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

8  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

9  
3145
a9de05d4a22f
# __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3060
diff
changeset

10  from __future__ import unicode_literals 
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2302
diff
changeset

11  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

12  import re 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

13  
5921
d4797da58218
Some more fixes for the web browser NG.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5736
diff
changeset

14  from PyQt5.QtCore import PYQT_VERSION, Qt, QRegExp 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

15  from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInfo 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

16  
5736
000ea446ff4b
Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5605
diff
changeset

17  from Globals import qVersionTuple 
000ea446ff4b
Prepared the code for Qt > 5.9.99.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5605
diff
changeset

18  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

19  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

20  def toSecondLevelDomain(url): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

21  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

22  Module function to get a second level domain from the given URL. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

23  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

24  @param url URL to extract domain from (QUrl) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

25  @return name of second level domain (string) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

26  """ 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

27  topLevelDomain = url.topLevelDomain() 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

28  urlHost = url.host() 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

29  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

30  if not topLevelDomain or not urlHost: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

31  return "" 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

32  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

33  domain = urlHost[:len(urlHost)  len(topLevelDomain)] 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

34  if domain.count(".") == 0: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

35  return urlHost 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

36  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

37  while domain.count(".") != 0: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

38  domain = domain[domain.find(".") + 1:] 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

39  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

40  return domain + topLevelDomain 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

41  
945
8cd4d08fa9f6
Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
791
diff
changeset

42  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

43  class AdBlockRule(object): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

44  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

45  Class implementing the AdBlock rule. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

46  """ 
5605
1950fe1a32c4
Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5389
diff
changeset

47  def __init__(self, filterRule="", subscription=None): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

48  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

49  Constructor 
2953
703452a2876f
Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2302
diff
changeset

50  
5605
1950fe1a32c4
Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5389
diff
changeset

51  @param filterRule filter string of the rule (string) 
2953
703452a2876f
Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2302
diff
changeset

52  @param subscription reference to the subscription object 
703452a2876f
Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2302
diff
changeset

53  (AdBlockSubscription) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

54  """ 
1963
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

55  self.__subscription = subscription 
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

56  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

57  self.__regExp = QRegExp() 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

58  self.__options = [] 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

59  self.__blockedDomains = [] 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

60  self.__allowedDomains = [] 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

61  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

62  self.__enabled = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

63  self.__cssRule = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

64  self.__exception = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

65  self.__internalDisabled = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

66  self.__domainRestricted = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

67  self.__useRegExp = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

68  self.__useDomainMatch = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

69  self.__useEndsMatch = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

70  self.__thirdParty = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

71  self.__thirdPartyException = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

72  self.__object = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

73  self.__objectException = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

74  self.__subdocument = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

75  self.__subdocumentException = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

76  self.__xmlhttprequest = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

77  self.__xmlhttprequestException = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

78  self.__document = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

79  self.__elemhide = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

80  self.__caseSensitivity = Qt.CaseInsensitive 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

81  self.__image = False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

82  self.__imageException = False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

83  self.__script = False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

84  self.__scriptException = False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

85  self.__stylesheet = False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

86  self.__stylesheetException = False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

87  self.__objectSubrequest = False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

88  self.__objectSubrequestException = False 
4881
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

89  self.__stringMatchRule = False 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

90  
5605
1950fe1a32c4
Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5389
diff
changeset

91  self.setFilter(filterRule) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

92  
1963
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

93  def subscription(self): 
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

94  """ 
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

95  Public method to get the subscription this rule belongs to. 
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

96  
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

97  @return subscription of the rule (AdBlockSubscription) 
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

98  """ 
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

99  return self.__subscription 
9c5b3235abf9
Added an icon to the status bar to give direct access to AdBlock.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1960
diff
changeset

100  
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

101  def filter(self): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

102  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

103  Public method to get the rule filter string. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

104  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

105  @return rule filter string (string) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

106  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

107  return self.__filter 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

108  
5605
1950fe1a32c4
Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5389
diff
changeset

109  def setFilter(self, filterRule): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

110  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

111  Public method to set the rule filter string. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

112  
5605
1950fe1a32c4
Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5389
diff
changeset

113  @param filterRule rule filter string (string) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

114  """ 
5605
1950fe1a32c4
Finished fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5389
diff
changeset

115  self.__filter = filterRule 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

116  self.__parseFilter() 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

117  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

118  def __parseFilter(self): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

119  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

120  Private method to parse the filter pattern. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

121  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

122  parsedLine = self.__filter 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

123  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

124  # empty rule or just a comment 
1994
84d55b34ba5a
Added support for AdBlock checksum checking when downloading a subscription to the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1963
diff
changeset

125  if not parsedLine.strip() or parsedLine.startswith(("!", "[Adblock")): 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

126  self.__enabled = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

127  return 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

128  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

129  # CSS element hiding rule 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

130  if "##" in parsedLine or "#@#" in parsedLine: 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

131  self.__cssRule = True 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

132  pos = parsedLine.find("#") 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

133  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

134  # domain restricted rule 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

135  if not parsedLine.startswith("##"): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

136  domains = parsedLine[:pos] 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

137  self.__parseDomains(domains, ",") 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

138  
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

139  self.__exception = parsedLine[pos + 1] == "@" 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

140  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

141  if self.__exception: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

142  self.__cssSelector = parsedLine[pos + 3:] 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

143  else: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

144  self.__cssSelector = parsedLine[pos + 2:] 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

145  # CSS rule cannot have more options > stop parsing 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

146  return 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

147  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

148  # Exception always starts with @@ 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

149  if parsedLine.startswith("@@"): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

150  self.__exception = True 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

151  parsedLine = parsedLine[2:] 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

152  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

153  # Parse all options following '$' character 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

154  optionsIndex = parsedLine.find("$") 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

155  if optionsIndex >= 0: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

156  options = parsedLine[optionsIndex + 1:].split(",") 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

157  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

158  handledOptions = 0 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

159  for option in options: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

160  if option.startswith("domain="): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

161  self.__parseDomains(option[7:], "") 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

162  handledOptions += 1 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

163  elif option == "matchcase": 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

164  self.__caseSensitivity = Qt.CaseSensitive 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

165  handledOptions += 1 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

166  elif option.endswith("thirdparty"): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

167  self.__thirdParty = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

168  self.__thirdPartyException = option.startswith("~") 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

169  handledOptions += 1 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

170  elif option.endswith("object"): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

171  self.__object = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

172  self.__objectException = option.startswith("~") 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

173  handledOptions += 1 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

174  elif option.endswith("subdocument"): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

175  self.__subdocument = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

176  self.__subdocumentException = option.startswith("~") 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

177  handledOptions += 1 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

178  elif option.endswith("xmlhttprequest"): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

179  self.__xmlhttprequest = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

180  self.__xmlhttprequestException = option.startswith("~") 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

181  handledOptions += 1 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

182  elif option.endswith("image"): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

183  self.__image = True 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

184  self.__imageException = option.startswith("~") 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

185  elif option.endswith("script"): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

186  self.__script = True 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

187  self.__scriptException = option.startswith("~") 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

188  elif option.endswith("stylesheet"): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

189  self.__stylesheet = True 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

190  self.__stylesheetException = option.startswith("~") 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

191  elif option.endswith("objectsubrequest"): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

192  self.__objectSubrequest = True 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

193  self.__objectSubrequestException = option.startswith("~") 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

194  elif option == "document" and self.__exception: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

195  self.__document = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

196  handledOptions += 1 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

197  elif option == "elemhide" and self.__exception: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

198  self.__elemhide = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

199  handledOptions += 1 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

200  elif option == "collapse": 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

201  # Hiding placeholders of blocked elements 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

202  handledOptions += 1 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

203  
3000
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

204  # If we don't handle all options, it's safer to just disable 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

205  # this rule 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

206  if handledOptions != len(options): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

207  self.__internalDisabled = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

208  return 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

209  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

210  parsedLine = parsedLine[:optionsIndex] 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

211  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

212  # Rule is classic regexp 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

213  if parsedLine.startswith("/") and parsedLine.endswith("/"): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

214  parsedLine = parsedLine[1:1] 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

215  self.__useRegExp = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

216  self.__regExp = QRegExp(parsedLine, self.__caseSensitivity, 
3035
36e9f388958b
Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3022
diff
changeset

217  QRegExp.RegExp) 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

218  return 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

219  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

220  # Remove starting / ending wildcards 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

221  if parsedLine.startswith("*"): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

222  parsedLine = parsedLine[1:] 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

223  if parsedLine.endswith("*"): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

224  parsedLine = parsedLine[:1] 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

225  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

226  # Fast string matching for domain can be used 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

227  if parsedLine.startswith("") and \ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

228  parsedLine.endswith("^") and \ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

229  QRegExp("[/:?=&\\*]").indexIn(parsedLine) == 1: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

230  parsedLine = parsedLine[2:1] 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

231  self.__useDomainMatch = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

232  self.__matchString = parsedLine 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

233  return 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

234  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

235  # If rule contains '' only at the end, string matching can be used 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

236  if parsedLine.endswith("") and \ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

237  QRegExp("[\\^\\*]").indexIn(parsedLine) == 1 and \ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

238  parsedLine.count("") == 1: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

239  parsedLine = parsedLine[:1] 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

240  self.__useEndsMatch = True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

241  self.__matchString = parsedLine 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

242  return 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

243  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

244  # If there is still a wildcard (*) or separator (^) or (), 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

245  # the rule must be modified to comply with QRegExp. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

246  if "*" in parsedLine or "^" in parsedLine or "" in parsedLine: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

247  pattern = self.__convertPatternToRegExp(parsedLine) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

248  self.__useRegExp = True 
3000
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

249  self.__regExp = QRegExp(pattern, self.__caseSensitivity, 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

250  QRegExp.RegExp) 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

251  return 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

252  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

253  # no regexp required 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

254  self.__useRegExp = False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

255  self.__matchString = parsedLine 
4881
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

256  self.__stringMatchRule = True 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

257  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

258  def __parseDomains(self, domains, separator): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

259  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

260  Private method to parse a string with a domain list. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

261  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

262  @param domains list of domains (string) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

263  @param separator separator character used by the list (string) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

264  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

265  domainsList = domains.split(separator) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

266  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

267  for domain in domainsList: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

268  if not domain: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

269  continue 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

270  if domain.startswith("~"): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

271  self.__blockedDomains.append(domain[1:]) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

272  else: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

273  self.__allowedDomains.append(domain) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

274  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

275  self.__domainRestricted = \ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

276  bool(self.__blockedDomains) or bool(self.__allowedDomains) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

277  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

278  def networkMatch(self, request, domain, encodedUrl): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

279  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

280  Public method to check the rule for a match. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

281  
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

282  @param request reference to the network request 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

283  @type QWebEngineUrlRequestInfo 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

284  @param domain domain name 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

285  @type str 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

286  @param encodedUrl string encoded URL to be checked 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

287  @type str 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

288  @return flag indicating a match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

289  @rtype bool 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

290  """ 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

291  if self.__cssRule or not self.__enabled or self.__internalDisabled: 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

292  return False 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

293  
4881
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

294  matched = self.__stringMatch(domain, encodedUrl) 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

295  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

296  if matched: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

297  # check domain restrictions 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

298  if self.__domainRestricted and \ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

299  not self.matchDomain(request.firstPartyUrl().host()): 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

300  return False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

301  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

302  # check thirdparty restrictions 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

303  if self.__thirdParty and not self.matchThirdParty(request): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

304  return False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

305  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

306  # check object restrictions 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

307  if self.__object and not self.matchObject(request): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

308  return False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

309  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

310  # check subdocument restrictions 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

311  if self.__subdocument and not self.matchSubdocument(request): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

312  return False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

313  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

314  # check xmlhttprequest restriction 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

315  if self.__xmlhttprequest and not self.matchXmlHttpRequest(request): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

316  return False 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

317  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

318  # check image restriction 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

319  if self.__image and not self.matchImage(request): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

320  return False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

321  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

322  # check script restriction 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

323  if self.__script and not self.matchScript(request): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

324  return False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

325  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

326  # check stylesheet restriction 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

327  if self.__stylesheet and not self.matchStyleSheet(request): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

328  return False 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

329  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

330  # check objectsubrequest restriction 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

331  if self.__objectSubrequest and \ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

332  not self.matchObjectSubrequest(request): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

333  return False 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

334  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

335  return matched 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

336  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

337  def urlMatch(self, url): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

338  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

339  Public method to check an URL against the rule. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

340  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

341  @param url URL to check (QUrl) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

342  @return flag indicating a match (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

343  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

344  if not self.__document and not self.__elemhide: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

345  return False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

346  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

347  encodedUrl = bytes(url.toEncoded()).decode() 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

348  domain = url.host() 
4881
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

349  return self.__stringMatch(domain, encodedUrl) 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

350  
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

351  def __stringMatch(self, domain, encodedUrl): 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

352  """ 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

353  Private method to match a domain string. 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

354  
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

355  @param domain domain to match 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

356  @type str 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

357  @param encodedUrl URL in encoded form 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

358  @type str 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

359  @return flag indicating a match 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

360  @rtype bool 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

361  """ 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

362  if self.__cssRule or not self.__enabled or self.__internalDisabled: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

363  return False 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

364  
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

365  matched = False 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

366  
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

367  if self.__useRegExp: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

368  matched = self.__regExp.indexIn(encodedUrl) != 1 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

369  elif self.__useDomainMatch: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

370  matched = domain.endswith(self.__matchString) 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

371  elif self.__useEndsMatch: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

372  if self.__caseSensitivity == Qt.CaseInsensitive: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

373  matched = encodedUrl.lower().endswith( 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

374  self.__matchString.lower()) 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

375  else: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

376  matched = encodedUrl.endswith(self.__matchString) 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

377  else: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

378  if self.__caseSensitivity == Qt.CaseInsensitive: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

379  matched = self.__matchString.lower() in encodedUrl.lower() 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

380  else: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

381  matched = self.__matchString in encodedUrl 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

382  
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

383  return matched 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

384  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

385  def matchDomain(self, domain): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

386  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

387  Public method to match a domain. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

388  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

389  @param domain domain name to check (string) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

390  @return flag indicating a match (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

391  """ 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

392  if not self.__enabled: 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

393  return False 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

394  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

395  if not self.__domainRestricted: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

396  return True 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

397  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

398  if len(self.__blockedDomains) == 0: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

399  for dom in self.__allowedDomains: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

400  if domain.endswith(dom): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

401  return True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

402  elif len(self.__allowedDomains) == 0: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

403  for dom in self.__blockedDomains: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

404  if domain.endswith(dom): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

405  return False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

406  return True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

407  else: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

408  for dom in self.__blockedDomains: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

409  if domain.endswith(dom): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

410  return False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

411  for dom in self.__allowedDomains: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

412  if domain.endswith(dom): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

413  return True 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

414  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

415  return False 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

416  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

417  def matchThirdParty(self, req): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

418  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

419  Public slot to match a thirdparty rule. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

420  
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

421  @param req request object to check (QWebEngineUrlRequestInfo) 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

422  @return flag indicating a match (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

423  """ 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

424  # Thirdparty matching should be performed on secondlevel domains 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

425  firstPartyHost = toSecondLevelDomain(req.firstPartyUrl()) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

426  host = toSecondLevelDomain(req.requestUrl()) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

427  
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

428  match = firstPartyHost != host 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

429  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

430  if self.__thirdPartyException: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

431  return not match 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

432  else: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

433  return match 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

434  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

435  def matchObject(self, req): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

436  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

437  Public slot to match an object rule. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

438  
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

439  @param req request object to check (QWebEngineUrlRequestInfo) 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

440  @return flag indicating a match (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

441  """ 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

442  match = ( 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

443  req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeObject) 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

444  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

445  if self.__objectException: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

446  return not match 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

447  else: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

448  return match 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

449  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

450  def matchSubdocument(self, req): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

451  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

452  Public slot to match a subdocument rule. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

453  
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

454  @param req request object to check (QWebEngineUrlRequestInfo) 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

455  @return flag indicating a match (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

456  """ 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

457  match = ( 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

458  req.resourceType() == 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

459  QWebEngineUrlRequestInfo.ResourceTypeSubFrame) 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

460  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

461  if self.__subdocumentException: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

462  return not match 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

463  else: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

464  return match 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

465  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

466  def matchXmlHttpRequest(self, req): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

467  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

468  Public slot to match a XmlHttpRequest rule. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

469  
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

470  @param req request object to check (QWebEngineUrlRequestInfo) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

471  @return flag indicating a match (boolean) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

472  """ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

473  match = ( 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

474  req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeXhr) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

475  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

476  if self.__xmlhttprequestException: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

477  return not match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

478  else: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

479  return match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

480  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

481  def matchImage(self, req): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

482  """ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

483  Public slot to match an Image rule. 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

484  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

485  @param req request object to check (QWebEngineUrlRequestInfo) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

486  @return flag indicating a match (boolean) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

487  """ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

488  match = ( 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

489  req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeImage) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

490  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

491  if self.__imageException: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

492  return not match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

493  else: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

494  return match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

495  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

496  def matchScript(self, req): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

497  """ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

498  Public slot to match a Script rule. 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

499  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

500  @param req request object to check (QWebEngineUrlRequestInfo) 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

501  @return flag indicating a match (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

502  """ 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

503  match = ( 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

504  req.resourceType() == QWebEngineUrlRequestInfo.ResourceTypeScript) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

505  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

506  if self.__scriptException: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

507  return not match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

508  else: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

509  return match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

510  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

511  def matchStyleSheet(self, req): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

512  """ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

513  Public slot to match a StyleSheet rule. 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

514  
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

515  @param req request object to check (QWebEngineUrlRequestInfo) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

516  @return flag indicating a match (boolean) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

517  """ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

518  match = ( 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

519  req.resourceType() == 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

520  QWebEngineUrlRequestInfo.ResourceTypeStylesheet) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

521  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

522  if self.__stylesheetException: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

523  return not match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

524  else: 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

525  return match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

526  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

527  def matchObjectSubrequest(self, req): 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

528  """ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

529  Public slot to match an Object Subrequest rule. 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

530  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

531  @param req request object to check (QWebEngineUrlRequestInfo) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

532  @return flag indicating a match (boolean) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

533  """ 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

534  match = ( 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

535  req.resourceType() == 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

536  QWebEngineUrlRequestInfo.ResourceTypeSubResource) 
5921
d4797da58218
Some more fixes for the web browser NG.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
5736
diff
changeset

537  if qVersionTuple() >= (5, 7, 0) and PYQT_VERSION >= 0x50700: 
5194
4750c83cc718
Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4881
diff
changeset

538  match = match or ( 
4750c83cc718
Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4881
diff
changeset

539  req.resourceType() == 
4750c83cc718
Added an 'unselect' alternative for Qt < 5.7.0 to the new web browser and added possibility to save the current page in various formats.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4881
diff
changeset

540  QWebEngineUrlRequestInfo.ResourceTypePluginResource) 
4858
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

541  
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

542  if self.__objectSubrequestException: 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

543  return not match 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

544  else: 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

545  return match 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

546  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

547  def isException(self): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

548  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

549  Public method to check, if the rule defines an exception. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

550  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

551  @return flag indicating an exception (boolean) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

552  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

553  return self.__exception 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

554  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

555  def setException(self, exception): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

556  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

557  Public method to set the rule's exception flag. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

558  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

559  @param exception flag indicating an exception rule (boolean) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

560  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

561  self.__exception = exception 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

562  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

563  def isEnabled(self): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

564  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

565  Public method to check, if the rule is enabled. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

566  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

567  @return flag indicating enabled state (boolean) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

568  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

569  return self.__enabled 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

570  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

571  def setEnabled(self, enabled): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

572  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

573  Public method to set the rule's enabled state. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

574  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

575  @param enabled flag indicating the new enabled state (boolean) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

576  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

577  self.__enabled = enabled 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

578  if not enabled: 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

579  self.__filter = "!" + self.__filter 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

580  else: 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

581  self.__filter = self.__filter[1:] 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

582  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

583  def isCSSRule(self): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

584  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

585  Public method to check, if the rule is a CSS rule. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

586  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

587  @return flag indicating a CSS rule (boolean) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

588  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

589  return self.__cssRule 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

590  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

591  def cssSelector(self): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

592  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

593  Public method to get the CSS selector of the rule. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

594  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

595  @return CSS selector (string) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

596  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

597  return self.__cssSelector 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

598  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

599  def isDocument(self): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

600  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

601  Public method to check, if this is a document rule. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

602  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

603  @return flag indicating a document rule (boolean) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

604  """ 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

605  return self.__document 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

606  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

607  def isElementHiding(self): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

608  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

609  Public method to check, if this is an element hiding rule. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

610  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

611  @return flag indicating an element hiding rule (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

612  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

613  return self.__elemhide 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

614  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

615  def isDomainRestricted(self): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

616  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

617  Public method to check, if this rule is restricted by domain. 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

618  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

619  @return flag indicating a domain restriction (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

620  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

621  return self.__domainRestricted 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

622  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

623  def isComment(self): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

624  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

625  Public method to check, if this is a comment. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

626  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

627  @return flag indicating a comment (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

628  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

629  return self.__filter.startswith("!") 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

630  
1994
84d55b34ba5a
Added support for AdBlock checksum checking when downloading a subscription to the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1963
diff
changeset

631  def isHeader(self): 
84d55b34ba5a
Added support for AdBlock checksum checking when downloading a subscription to the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1963
diff
changeset

632  """ 
84d55b34ba5a
Added support for AdBlock checksum checking when downloading a subscription to the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1963
diff
changeset

633  Public method to check, if this is a header. 
84d55b34ba5a
Added support for AdBlock checksum checking when downloading a subscription to the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1963
diff
changeset

634  
84d55b34ba5a
Added support for AdBlock checksum checking when downloading a subscription to the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1963
diff
changeset

635  @return flag indicating a header (boolean) 
84d55b34ba5a
Added support for AdBlock checksum checking when downloading a subscription to the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1963
diff
changeset

636  """ 
84d55b34ba5a
Added support for AdBlock checksum checking when downloading a subscription to the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1963
diff
changeset

637  return self.__filter.startswith("[Adblock") 
84d55b34ba5a
Added support for AdBlock checksum checking when downloading a subscription to the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1963
diff
changeset

638  
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

639  def isSlow(self): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

640  """ 
1960
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

641  Public method to check, if this is a slow rule. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

642  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

643  @return flag indicating a slow rule (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

644  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

645  return self.__useRegExp 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

646  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

647  def isInternalDisabled(self): 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

648  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

649  Public method to check, if this rule was disabled internally. 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

650  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

651  @return flag indicating an internally disabled rule (boolean) 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

652  """ 
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

653  return self.__internalDisabled 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

654  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

655  def __convertPatternToRegExp(self, wildcardPattern): 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

656  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

657  Private method to convert a wildcard pattern to a regular expression. 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

658  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

659  @param wildcardPattern string containing the wildcard pattern (string) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

660  @return string containing a regular expression (string) 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

661  """ 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

662  pattern = wildcardPattern 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

663  
3000
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

664  # remove multiple wildcards 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

665  pattern = re.sub(r"\*+", "*", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

666  # remove anchors following separator placeholder 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

667  pattern = re.sub(r"\^\$", "^", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

668  # remove leading wildcards 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

669  pattern = re.sub(r"^(\*)", "", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

670  # remove trailing wildcards 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

671  pattern = re.sub(r"(\*)$", "", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

672  # escape special symbols 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

673  pattern = re.sub(r"(\W)", r"\\\1", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

674  # process extended anchor at expression start 
3022
57179e4cdadd
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3000
diff
changeset

675  pattern = re.sub( 
57179e4cdadd
Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3000
diff
changeset

676  r"^\\\\\\", 
3000
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

677  r"^[\w\]+:\/+(?!\/)(?:[^\/]+\.)?", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

678  # process separator placeholders 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

679  pattern = re.sub(r"\\\^", r"(?:[^\w\d\.%]$)", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

680  # process anchor at expression start 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

681  pattern = re.sub(r"^\\\", "^", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

682  # process anchor at expression end 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

683  pattern = re.sub(r"\\\$", "$", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

684  # replace wildcards by .* 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

685  pattern = re.sub(r"\\\*", ".*", pattern) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

686  
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

687  return pattern 