Exemplo n.º 1
0
 def test_data_chunked(self, chunk_size, req):
     data = b'123'
     reply = networkreply.FixedDataNetworkReply(req, data, 'test/foo')
     while data:
         assert reply.bytesAvailable() == len(data)
         assert reply.readData(chunk_size) == data[:chunk_size]
         data = data[chunk_size:]
Exemplo n.º 2
0
    def createRequest(self, _op, request, _outgoing_data):
        """Create a new request.

        Args:
             request: const QNetworkRequest & req
             _op: Operation op
             _outgoing_data: QIODevice * outgoingData

        Return:
            A QNetworkReply.
        """
        path = request.url().path()
        host = request.url().host()
        # An url like "qute:foo" is split as "scheme:path", not "scheme:host".
        log.misc.debug("url: {}, path: {}, host {}".format(
            request.url().toDisplayString(), path, host))
        try:
            handler = HANDLERS[path]
        except KeyError:
            try:
                handler = HANDLERS[host]
            except KeyError:
                errorstr = "No handler found for {}!".format(
                    request.url().toDisplayString())
                return networkreply.ErrorNetworkReply(
                    request, errorstr, QNetworkReply.ContentNotFoundError,
                    self.parent())
        try:
            data = handler(self._win_id, request)
        except OSError as e:
            return networkreply.ErrorNetworkReply(
                request, str(e), QNetworkReply.ContentNotFoundError,
                self.parent())
        return networkreply.FixedDataNetworkReply(request, data, 'text/html',
                                                  self.parent())
Exemplo n.º 3
0
    def test_data(self, qtbot, req, data):
        reply = networkreply.FixedDataNetworkReply(req, data, 'test/foo')
        with qtbot.waitSignals([reply.metaDataChanged, reply.readyRead,
                                reply.finished]):
            pass

        assert reply.bytesAvailable() == len(data)
        assert reply.readAll() == data
Exemplo n.º 4
0
 def test_attributes(self, req):
     reply = networkreply.FixedDataNetworkReply(req, b'', 'test/foo')
     assert reply.request() == req
     assert reply.url() == req.url()
     assert reply.openMode() == QIODevice.ReadOnly
     assert reply.header(QNetworkRequest.ContentTypeHeader) == 'test/foo'
     http_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute)
     http_reason = reply.attribute(
         QNetworkRequest.HttpReasonPhraseAttribute)
     assert http_code == 200
     assert http_reason == 'OK'
     assert reply.isFinished()
     assert not reply.isRunning()
Exemplo n.º 5
0
    def createRequest(self, _op, request, _outgoing_data):
        """Create a new request.

        Args:
             request: const QNetworkRequest & req
             _op: Operation op
             _outgoing_data: QIODevice * outgoingData

        Return:
            A QNetworkReply for directories, None for files.
        """
        path = request.url().toLocalFile()
        if os.path.isdir(path):
            data = dirbrowser_html(path)
            return networkreply.FixedDataNetworkReply(
                request, data, 'text/html', self.parent())
Exemplo n.º 6
0
 def test_abort(self, req):
     reply = networkreply.FixedDataNetworkReply(req, b'foo', 'test/foo')
     reply.abort()
     assert reply.readAll() == b'foo'