Cleanup
This commit is contained in:
parent
d975ec080d
commit
a96261e7b8
@ -63,8 +63,8 @@ class NetworkManager(QNetworkAccessManager):
|
||||
|
||||
"""
|
||||
scheme = req.url().scheme()
|
||||
logging.debug("new req, scheme {}, handlers {}".format(scheme,
|
||||
self._scheme_handlers))
|
||||
logging.debug("new req, scheme {}, handlers {}".format(
|
||||
scheme, self._scheme_handlers))
|
||||
if scheme in self._scheme_handlers:
|
||||
reply = self._scheme_handlers[scheme].createRequest(
|
||||
op, req, outgoing_data)
|
||||
|
@ -102,10 +102,8 @@ class QuteSchemeHandler(SchemeHandler):
|
||||
A QNetworkReply.
|
||||
|
||||
"""
|
||||
|
||||
# FIXME handle unknown pages
|
||||
# FIXME adjust URLutils based on handlers
|
||||
|
||||
logging.debug('request: {}'.format(request))
|
||||
data = handle(urlstring(request.url()))
|
||||
return SpecialNetworkReply(request, data, "text/html", self.parent())
|
||||
|
@ -20,16 +20,15 @@
|
||||
|
||||
"""Base class for custom scheme handlers."""
|
||||
|
||||
import logging
|
||||
|
||||
from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest
|
||||
from PyQt5.QtCore import pyqtSlot, QObject, QIODevice, QByteArray, QTimer
|
||||
|
||||
|
||||
class SchemeHandler(QObject):
|
||||
|
||||
"""Abstract base class for custom scheme handlers."""
|
||||
|
||||
def createRequest(self, op, request, outgoingData=None):
|
||||
def createRequest(self, op, request, outgoingData):
|
||||
"""Create a new request.
|
||||
|
||||
Args:
|
||||
@ -43,11 +42,11 @@ class SchemeHandler(QObject):
|
||||
Raise:
|
||||
NotImplementedError because this needs to be overwritten by
|
||||
subclasses.
|
||||
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
|
||||
class SpecialNetworkReply(QNetworkReply):
|
||||
|
||||
"""QNetworkReply subclass for special data."""
|
||||
@ -77,6 +76,8 @@ class SpecialNetworkReply(QNetworkReply):
|
||||
QByteArray.number(len(fileData)))
|
||||
self.setAttribute(QNetworkRequest.HttpStatusCodeAttribute, 200)
|
||||
self.setAttribute(QNetworkRequest.HttpReasonPhraseAttribute, "OK")
|
||||
# For some reason, a segfault will be triggered if these lambdas aren't
|
||||
# there. pylint: disable=unnecessary-lambda
|
||||
QTimer.singleShot(0, lambda: self.metaDataChanged.emit())
|
||||
QTimer.singleShot(0, lambda: self.readyRead.emit())
|
||||
QTimer.singleShot(0, lambda: self.finished.emit())
|
||||
@ -93,7 +94,6 @@ class SpecialNetworkReply(QNetworkReply):
|
||||
bytes available (int)
|
||||
|
||||
"""
|
||||
logging.debug("bytes available: {}".format(len(self._data)))
|
||||
return len(self._data) + super().bytesAvailable()
|
||||
|
||||
def readData(self, maxlen):
|
||||
@ -108,7 +108,6 @@ class SpecialNetworkReply(QNetworkReply):
|
||||
"""
|
||||
len_ = min(maxlen, len(self._data))
|
||||
buf = bytes(self._data[:len_])
|
||||
logging.debug("readdata, len {}, maxlen {}, buf {}".format(len(self._data), maxlen, buf))
|
||||
self._data = self._data[len_:]
|
||||
return buf
|
||||
|
||||
|
@ -261,7 +261,7 @@ class Config(ConfigParser):
|
||||
not self.always_save):
|
||||
logging.warning("Not saving config (dir {}, config {})".format(
|
||||
self._configdir, 'loaded' if self._config_loaded
|
||||
else 'not loaded'))
|
||||
else 'not loaded'))
|
||||
return
|
||||
if not os.path.exists(self._configdir):
|
||||
os.makedirs(self._configdir, 0o755)
|
||||
|
Loading…
Reference in New Issue
Block a user