From 65ae1882f0632051c5c8c1512a3257b201e327ff Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 20 Feb 2014 22:23:38 +0100 Subject: [PATCH] Move NetworkManager to own file --- qutebrowser/network/__init__.py | 1 + qutebrowser/network/networkmanager.py | 58 +++++++++++++++++++++++++++ qutebrowser/widgets/browser.py | 42 +------------------ 3 files changed, 61 insertions(+), 40 deletions(-) create mode 100644 qutebrowser/network/__init__.py create mode 100644 qutebrowser/network/networkmanager.py diff --git a/qutebrowser/network/__init__.py b/qutebrowser/network/__init__.py new file mode 100644 index 000000000..92c677c29 --- /dev/null +++ b/qutebrowser/network/__init__.py @@ -0,0 +1 @@ +"""Modules related to network operations.""" diff --git a/qutebrowser/network/networkmanager.py b/qutebrowser/network/networkmanager.py new file mode 100644 index 000000000..ec1009c09 --- /dev/null +++ b/qutebrowser/network/networkmanager.py @@ -0,0 +1,58 @@ +# Copyright 2014 Florian Bruhin (The Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""Our own QNetworkAccessManager.""" + +from PyQt5.QtNetwork import QNetworkAccessManager + +class NetworkManager(QNetworkAccessManager): + + """Our own QNetworkAccessManager. + + Attributes: + _requests: Pending requests. + + """ + + def __init__(self, parent=None): + self._requests = {} + super().__init__(parent) + + def abort_requests(self): + """Abort all running requests.""" + for request in self._requests.values(): + request.abort() + + def createRequest(self, op, req, outgoing_data): + """Return a new QNetworkReply object. + + Extend QNetworkAccessManager::createRequest to save requests in + self._requests. + + Args: + op: Operation op + req: const QNetworkRequest & req + outgoing_data: QIODevice * outgoingData + + Return: + A QNetworkReply. + + """ + reply = super().createRequest(op, req, outgoing_data) + self._requests[id(reply)] = reply + reply.destroyed.connect(lambda obj: self._requests.pop(id(obj))) + return reply diff --git a/qutebrowser/widgets/browser.py b/qutebrowser/widgets/browser.py index 53a6be3a0..567f257b2 100644 --- a/qutebrowser/widgets/browser.py +++ b/qutebrowser/widgets/browser.py @@ -30,7 +30,7 @@ from PyQt5.QtWidgets import QApplication, QShortcut, QSizePolicy from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QEvent from PyQt5.QtGui import QClipboard from PyQt5.QtPrintSupport import QPrintPreviewDialog -from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkReply +from PyQt5.QtNetwork import QNetworkReply from PyQt5.QtWebKit import QWebSettings from PyQt5.QtWebKitWidgets import QWebView, QWebPage @@ -38,6 +38,7 @@ import qutebrowser.utils.about as about import qutebrowser.utils.url as urlutils import qutebrowser.utils.config as config from qutebrowser.widgets.tabbar import TabWidget +from qutebrowser.network.networkmanager import NetworkManager from qutebrowser.utils.signals import SignalCache, dbg_signal from qutebrowser.utils.misc import read_file from qutebrowser.utils.types import NeighborList @@ -940,42 +941,3 @@ class BrowserPage(QWebPage): except KeyError: return super().extension(ext, opt, out) return handler(opt, out) - - -class NetworkManager(QNetworkAccessManager): - - """Our own QNetworkAccessManager. - - Attributes: - _requests: Pending requests. - - """ - - def __init__(self, parent=None): - self._requests = {} - super().__init__(parent) - - def abort_requests(self): - """Abort all running requests.""" - for request in self._requests.values(): - request.abort() - - def createRequest(self, op, req, outgoing_data): - """Return a new QNetworkReply object. - - Extend QNetworkAccessManager::createRequest to save requests in - self._requests. - - Args: - op: Operation op - req: const QNetworkRequest & req - outgoing_data: QIODevice * outgoingData - - Return: - A QNetworkReply. - - """ - reply = super().createRequest(op, req, outgoing_data) - self._requests[id(reply)] = reply - reply.destroyed.connect(lambda obj: self._requests.pop(id(obj))) - return reply