eric6/WebBrowser/AdBlock/AdBlockSearchTree.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8205
4a0f1f896341
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2017 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the AdBlock search tree.
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from .AdBlockRule import AdBlockRuleType
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 class AdBlockSearchTreeNode(object):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 Class implementing the AdBlock search tree node.
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 def __init__(self):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Constructor
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 self.char = ''
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 self.rule = None
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 self.children = {}
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 class AdBlockSearchTree(object):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Class implementing the AdBlock search tree.
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 def __init__(self):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Constructor
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.__root = AdBlockSearchTreeNode()
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 def clear(self):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 Public method to clear the search tree.
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.__deleteNode(self.__root)
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 self.__root = AdBlockSearchTreeNode()
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 def add(self, rule):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 Public method to add a rule to the search tree.
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @param rule rule to be added
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @type AdBlockRule
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @return flag indicating a successful addition
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @rtype bool
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 if rule.ruleType() != AdBlockRuleType.StringContainsMatchRule:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 return False
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 filterString = rule.matchString()
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 if len(filterString) <= 0:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 return False
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 node = self.__root
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 for filterChar in filterString:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 try:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 nextNode = node.children[filterChar]
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 except KeyError:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 nextNode = AdBlockSearchTreeNode()
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 nextNode.char = filterChar
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 node.children[filterChar] = nextNode
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 node = nextNode
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 node.rule = rule
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 return True
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 def find(self, request, domain, urlString):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 Public method to find a matching rule.
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 @param request URL request to be matched
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 @type QWebEngineUrlRequestInfo
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 @param domain domain of the URL
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 @type str
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 @param urlString requested URL as a lowercase string
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 @type str
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 @return reference to the matched rule
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 @rtype AdBlockRule
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 length = len(urlString)
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 if length <= 0:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 return None
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 for index in range(length):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 rule = self.__prefixSearch(request, domain, urlString,
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 urlString[index:], length - index)
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 if rule:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 return rule
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 return None
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 def __deleteNode(self, node):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 Private method to delete a search tree node.
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 @param node reference to the node to be deleted
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @type AdBlockSearchTreeNode
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if not node:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 return
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 for key in node.children.keys():
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 self.__deleteNode(node.children[key])
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 node.children = {}
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 node = None
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 def __prefixSearch(self, request, domain, urlString, string, length):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 Private method to perform a prefix search.
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 @param request URL request to be matched
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 @type QWebEngineUrlRequestInfo
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 @param domain domain of the URL
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 @type str
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 @param urlString requested URL as a lowercase string
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 @type str
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 @param string prefix string to search for
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @type str
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 @param length length to be considered
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 @type int
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 @return reference to the matched rule
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 @rtype AdBlockRule
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 """
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 if length <= 0:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 return None
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 char = string[0]
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 try:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 node = self.__root.children[char]
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 except KeyError:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 return None
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 for char in string[1:]:
7268
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
145 if (
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
146 node.rule and
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
147 node.rule.networkMatch(request, domain, urlString)
a28338eaf694 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
148 ):
6028
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 return node.rule
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 try:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 node = node.children[char]
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 except KeyError:
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 return None
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 if node.rule and node.rule.networkMatch(request, domain, urlString):
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 return node.rule
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
859f6894eed9 Reworked the AdBlock stuff of web browser NG.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 return None

eric ide

mercurial