WebBrowser/AdBlock/AdBlockRule.py

branch
QtWebEngine
changeset 4881
c269212cceac
parent 4860
0a44aff88bfa
child 5194
4750c83cc718
--- a/WebBrowser/AdBlock/AdBlockRule.py	Sat Mar 19 18:18:09 2016 +0100
+++ b/WebBrowser/AdBlock/AdBlockRule.py	Sat Mar 19 20:07:34 2016 +0100
@@ -12,7 +12,6 @@
 import re
 
 from PyQt5.QtCore import Qt, QRegExp
-from PyQt5.QtNetwork import QNetworkRequest
 from PyQt5.QtWebEngineCore import QWebEngineUrlRequestInfo
 
 
@@ -85,6 +84,7 @@
         self.__stylesheetException = False
         self.__objectSubrequest = False
         self.__objectSubrequestException = False
+        self.__stringMatchRule = False
         
         self.setFilter(filter)
     
@@ -251,6 +251,7 @@
         # no regexp required
         self.__useRegExp = False
         self.__matchString = parsedLine
+        self.__stringMatchRule = True
     
     def __parseDomains(self, domains, separator):
         """
@@ -288,23 +289,7 @@
         if self.__cssRule or not self.__enabled or self.__internalDisabled:
             return False
         
-        matched = False
-        
-        if self.__useRegExp:
-            matched = self.__regExp.indexIn(encodedUrl) != -1
-        elif self.__useDomainMatch:
-            matched = domain.endswith(self.__matchString)
-        elif self.__useEndsMatch:
-            if self.__caseSensitivity == Qt.CaseInsensitive:
-                matched = encodedUrl.lower().endswith(
-                    self.__matchString.lower())
-            else:
-                matched = encodedUrl.endswith(self.__matchString)
-        else:
-            if self.__caseSensitivity == Qt.CaseInsensitive:
-                matched = self.__matchString.lower() in encodedUrl.lower()
-            else:
-                matched = self.__matchString in encodedUrl
+        matched = self.__stringMatch(domain, encodedUrl)
         
         if matched:
             # check domain restrictions
@@ -359,7 +344,41 @@
         
         encodedUrl = bytes(url.toEncoded()).decode()
         domain = url.host()
-        return self.networkMatch(QNetworkRequest(url), domain, encodedUrl)
+        return self.__stringMatch(domain, encodedUrl)
+    
+    def __stringMatch(self, domain, encodedUrl):
+        """
+        Private method to match a domain string.
+        
+        @param domain domain to match
+        @type str
+        @param encodedUrl URL in encoded form
+        @type str
+        @return flag indicating a match
+        @rtype bool
+        """
+        if self.__cssRule or not self.__enabled or self.__internalDisabled:
+            return False
+        
+        matched = False
+        
+        if self.__useRegExp:
+            matched = self.__regExp.indexIn(encodedUrl) != -1
+        elif self.__useDomainMatch:
+            matched = domain.endswith(self.__matchString)
+        elif self.__useEndsMatch:
+            if self.__caseSensitivity == Qt.CaseInsensitive:
+                matched = encodedUrl.lower().endswith(
+                    self.__matchString.lower())
+            else:
+                matched = encodedUrl.endswith(self.__matchString)
+        else:
+            if self.__caseSensitivity == Qt.CaseInsensitive:
+                matched = self.__matchString.lower() in encodedUrl.lower()
+            else:
+                matched = self.__matchString in encodedUrl
+        
+        return matched
     
     def matchDomain(self, domain):
         """

eric ide

mercurial