Fixed issues in the AdBlock code.

Sun, 15 Jul 2012 17:53:39 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 15 Jul 2012 17:53:39 +0200
changeset 1950
4f004ec74b48
parent 1947
84626f18f2c3
child 1951
ac142b52e7dc

Fixed issues in the AdBlock code.

Helpviewer/AdBlock/AdBlockAccessHandler.py file | annotate | diff | comparison | revisions
Helpviewer/AdBlock/AdBlockRule.py file | annotate | diff | comparison | revisions
Helpviewer/HelpBrowserWV.py file | annotate | diff | comparison | revisions
Helpviewer/Network/EmptyNetworkReply.py file | annotate | diff | comparison | revisions
--- a/Helpviewer/AdBlock/AdBlockAccessHandler.py	Sat Jul 14 17:56:26 2012 +0200
+++ b/Helpviewer/AdBlock/AdBlockAccessHandler.py	Sun Jul 15 17:53:39 2012 +0200
@@ -15,6 +15,7 @@
 
 import Helpviewer.HelpWindow
 from Helpviewer.Network.SchemeAccessHandler import SchemeAccessHandler
+from Helpviewer.Network.EmptyNetworkReply import EmptyNetworkReply
 
 
 class AdBlockAccessHandler(SchemeAccessHandler):
@@ -52,4 +53,4 @@
             dlg.setCurrentIndex(model.index(model.rowCount() - 1, 0))
             dlg.setFocus()
         
-        return None
+        return EmptyNetworkReply(self.parent())
--- a/Helpviewer/AdBlock/AdBlockRule.py	Sat Jul 14 17:56:26 2012 +0200
+++ b/Helpviewer/AdBlock/AdBlockRule.py	Sun Jul 15 17:53:39 2012 +0200
@@ -177,7 +177,7 @@
         pattern = re.sub(r"\^\|$", "^", pattern)    # remove anchors following separator placeholder
         pattern = re.sub(r"^(\*)", "", pattern)     # remove leading wildcards
         pattern = re.sub(r"(\*)$", "", pattern)     # remove trailing wildcards
-        pattern = re.sub(r"(\W)", "", pattern)      # escape special symbols
+        pattern = re.sub(r"(\W)", r"\\\1", pattern)      # escape special symbols
         pattern = re.sub(r"^\\\|\\\|",
             r"^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?", pattern)  # process extended anchor at expression start
         pattern = re.sub(r"\\\^",
--- a/Helpviewer/HelpBrowserWV.py	Sat Jul 14 17:56:26 2012 +0200
+++ b/Helpviewer/HelpBrowserWV.py	Sun Jul 15 17:53:39 2012 +0200
@@ -308,6 +308,11 @@
                     errorPage.content = html
                     return True
             
+            if info.domain == QWebPage.QtNetwork and \
+               info.error == QNetworkReply.OperationCanceledError and \
+               info.errorString == "eric5:No Error":
+                return False
+            
             title = self.trUtf8("Error loading page: {0}").format(urlString)
             htmlFile = QFile(":/html/notFoundPage.html")
             htmlFile.open(QFile.ReadOnly)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Helpviewer/Network/EmptyNetworkReply.py	Sun Jul 15 17:53:39 2012 +0200
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a network reply class for an empty reply
+(i.e. request was handle other way).
+"""
+
+from PyQt4.QtCore import QTimer
+from PyQt4.QtNetwork import QNetworkReply, QNetworkAccessManager
+
+
+class EmptyNetworkReply(QNetworkReply):
+    """
+    Class implementing an empty network reply.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent object (QObject)
+        """
+        super().__init__(parent)
+        
+        self.setOperation(QNetworkAccessManager.GetOperation)
+        self.setError(QNetworkReply.OperationCanceledError, "eric5:No Error")
+        
+        QTimer.singleShot(0, lambda: self.finished.emit())
+    
+    def abort(self):
+        """
+        Public slot to abort the operation.
+        """
+        # do nothing
+        pass
+    
+    def readData(self, maxlen):
+        """
+        Protected method to retrieve data from the reply object.
+        
+        @param maxlen maximum number of bytes to read (integer)
+        @return string containing the data (bytes)
+        """
+        return bytes()

eric ide

mercurial