Helpviewer/AdBlock/AdBlockBlockedNetworkReply.py

Wed, 02 Jan 2013 10:31:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 02 Jan 2013 10:31:48 +0100
changeset 2302
f29e9405c851
parent 1960
d8c45fe8a1b9
child 2525
8b507a9a2d40
child 3000
971d84f7a6d6
child 3163
9f50365a0870
permissions
-rw-r--r--

Updated copyright for 2013.

# -*- coding: utf-8 -*-

# Copyright (c) 2009 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a QNetworkReply subclass reporting a blocked request.
"""

from PyQt4.QtCore import QTimer
from PyQt4.QtNetwork import QNetworkReply, QNetworkAccessManager


class AdBlockBlockedNetworkReply(QNetworkReply):
    """
    Class implementing a QNetworkReply subclass reporting a blocked request.
    """
    def __init__(self, request, subscription, rule, parent=None):
        """
        Constructor
        
        @param request reference to the request object (QNetworkRequest)
        @param subscription subscription containing the matched rule (AdBlockSubscription)
        @param rule matching rule (AdBlockRule)
        @param parent reference to the parent object (QObject)
        """
        super().__init__(parent)
        self.setOperation(QNetworkAccessManager.GetOperation)
        self.setRequest(request)
        self.setUrl(request.url())
        self.setError(QNetworkReply.ContentAccessDenied,
                      "AdBlockRule:{0} ({1})".format(subscription.title(), rule.filter()))
        QTimer.singleShot(0, self.__fireSignals)
    
    def __fireSignals(self):
        """
        Private method to send some signals to end the connection.
        """
        self.error[QNetworkReply.NetworkError].emit(QNetworkReply.ContentAccessDenied)
        self.finished.emit()
    
    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 (string)
        """
        return None
    
    def abort(self):
        """
        Public slot to abort the operation.
        """
        # do nothing
        pass

eric ide

mercurial