Sat, 11 Mar 2017 19:17:59 +0100
Finished fixing code style issues detected by the extended style checker.
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  
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

14  from PyQt5.QtCore import qVersion, 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  
d8c45fe8a1b9
Reworked some of the AdBlock code to achieve some speed improvements.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
1950
diff
changeset

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

18  def toSecondLevelDomain(url): 
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  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

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

22  @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

23  @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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

49  @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

50  @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

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

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

53  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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

91  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

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

93  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

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  @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

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 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

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

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

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

101  Public method to get the rule filter string. 
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  @return rule filter string (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 self.__filter 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

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

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

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

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

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

111  @param filterRule rule filter string (string) 
0
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  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

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

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

116  def __parseFilter(self): 
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  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

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

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

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

122  # 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

123  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

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

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

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

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

128  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

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

130  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

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

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

133  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

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

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

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

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

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

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

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

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

142  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

143  # 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

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

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

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

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

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

149  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

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

151  # 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

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

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

154  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

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

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

157  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

158  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

159  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

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

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

162  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

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

164  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

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

166  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

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

168  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

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

170  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

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

172  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

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

174  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

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

176  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

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

178  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

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

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

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

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

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

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

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

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

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

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

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

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

191  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

192  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

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

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

195  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

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

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

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

199  # 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

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

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

202  # 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

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

204  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

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

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

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

208  parsedLine = parsedLine[:optionsIndex] 
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  # 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

211  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

212  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

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

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

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

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

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

218  # 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

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

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

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

224  # 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

225  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

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

227  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

228  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

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

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

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

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

233  # 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

234  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

235  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

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

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

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

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

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

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

242  # 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

243  # 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

244  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

245  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

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

247  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

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

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

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

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

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

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

254  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

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

256  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

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

258  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

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

260  @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

261  @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

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

263  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

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

265  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

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

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

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

269  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

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

271  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

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

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

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

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

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

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

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

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

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

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

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

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

284  @param encodedUrl string encoded URL to be checked 
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  @return flag indicating a match 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

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

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

289  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

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

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

292  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

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

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

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

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

297  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

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

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

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

301  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

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

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

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

305  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

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

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

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

309  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

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

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

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

313  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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

333  return matched 
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  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

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

337  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

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

339  @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

340  @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

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

342  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

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

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

345  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

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

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

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

349  def __stringMatch(self, 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  Private method to match a domain string. 
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  @param domain domain to match 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

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

355  @param encodedUrl URL in encoded form 
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  @return flag indicating a match 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

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

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

360  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

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

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

363  matched = 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  if self.__useRegExp: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

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

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

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

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

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

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

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

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

374  matched = encodedUrl.endswith(self.__matchString) 
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  if self.__caseSensitivity == Qt.CaseInsensitive: 
c269212cceac
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4860
diff
changeset

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

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

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

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

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

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

383  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

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

385  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

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

387  @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

388  @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

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

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

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

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

393  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

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

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

396  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

397  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

398  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

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

400  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

401  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

402  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

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

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

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

406  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

407  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

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

409  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

410  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

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

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

413  return False 
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  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

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

417  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

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

419  @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

420  @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

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

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

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

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

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

426  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

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

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

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

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

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

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

433  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

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

435  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

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

437  @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

438  @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

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

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

441  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

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

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

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

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

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

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

448  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

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

450  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

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

452  @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

453  @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

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

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

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

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

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

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

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

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

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

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

464  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

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

466  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

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

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

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

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

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

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

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

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

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

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

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

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

479  def matchImage(self, req): 
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  Public slot to match an Image rule. 
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  @param req request object to check (QWebEngineUrlRequestInfo) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

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

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

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

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

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

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

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

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

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

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

494  def matchScript(self, req): 
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  Public slot to match a Script rule. 
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  @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

499  @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

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

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

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

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

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

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

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

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

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

509  def matchStyleSheet(self, req): 
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  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

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

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

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

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

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

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

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

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

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

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

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

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

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

525  def matchObjectSubrequest(self, req): 
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  Public slot to match an Object Subrequest rule. 
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  @param req request object to check (QWebEngineUrlRequestInfo) 
19dff9c9cf26
Continued porting the web browser.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4631
diff
changeset

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

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

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

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

534  QWebEngineUrlRequestInfo.ResourceTypeSubResource) 
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

535  if qVersion() >= "5.7.0": 
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

536  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

537  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

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

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

540  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

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

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

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

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

545  def isException(self): 
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  Public method to check, if the rule defines an exception. 
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  @return flag indicating an exception (boolean) 
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 self.__exception 
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  def setException(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  Public method to set the rule's exception flag. 
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  @param exception flag indicating an exception rule (boolean) 
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  self.__exception = exception 
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  def isEnabled(self): 
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  Public method to check, if the rule is enabled. 
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  @return flag indicating enabled state (boolean) 
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 self.__enabled 
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  def setEnabled(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  Public method to set the rule's enabled state. 
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  @param enabled flag indicating the new enabled state (boolean) 
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  self.__enabled = enabled 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

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

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

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

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

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

581  def isCSSRule(self): 
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  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

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

585  @return flag indicating a CSS rule (boolean) 
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 self.__cssRule 
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

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

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

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

591  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

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

593  @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

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

595  return self.__cssSelector 
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  def isDocument(self): 
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  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

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

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

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

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

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

605  def isElementHiding(self): 
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  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

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

609  @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

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

611  return self.__elemhide 
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  def isDomainRestricted(self): 
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  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

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

617  @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

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

619  return self.__domainRestricted 
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  def isComment(self): 
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  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

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

625  @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

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

627  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

628  
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

629  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

630  """ 
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  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

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  @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

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 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

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

637  def isSlow(self): 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
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  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

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

641  @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

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

643  return self.__useRegExp 
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  def isInternalDisabled(self): 
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  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

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

649  @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

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

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

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

653  def __convertPatternToRegExp(self, wildcardPattern): 
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  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

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

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

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

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

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

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

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

663  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

664  # 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

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 leading wildcards 
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 trailing 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  # escape special symbols 
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"(\W)", r"\\\1", pattern) 
971d84f7a6d6
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
2953
diff
changeset

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

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

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

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

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

677  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

678  # 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

679  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

680  # 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

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  # replace wildcards by .* 
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) 
0
de9c2efb9d02
Started porting eric4 to Python3
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
diff
changeset

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

685  return pattern 