src/eric7/WebBrowser/Network/QtHelpSchemeHandler.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
--- a/src/eric7/WebBrowser/Network/QtHelpSchemeHandler.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/WebBrowser/Network/QtHelpSchemeHandler.py	Wed Jul 13 14:55:47 2022 +0200
@@ -10,12 +10,8 @@
 import mimetypes
 import os
 
-from PyQt6.QtCore import (
-    pyqtSignal, QByteArray, QIODevice, QBuffer, QMutex
-)
-from PyQt6.QtWebEngineCore import (
-    QWebEngineUrlSchemeHandler, QWebEngineUrlRequestJob
-)
+from PyQt6.QtCore import pyqtSignal, QByteArray, QIODevice, QBuffer, QMutex
+from PyQt6.QtWebEngineCore import QWebEngineUrlSchemeHandler, QWebEngineUrlRequestJob
 
 from EricUtilities.EricMutexLocker import EricMutexLocker
 
@@ -58,25 +54,26 @@
     """
     Class implementing a scheme handler for the qthelp: scheme.
     """
+
     def __init__(self, engine, parent=None):
         """
         Constructor
-        
+
         @param engine reference to the help engine
         @type QHelpEngine
         @param parent reference to the parent object
         @type QObject
         """
         super().__init__(parent)
-        
+
         self.__engine = engine
-        
+
         self.__replies = []
-    
+
     def requestStarted(self, job):
         """
         Public method handling the URL request.
-        
+
         @param job URL request job
         @type QWebEngineUrlRequestJob
         """
@@ -87,11 +84,11 @@
             job.reply(reply.mimeType(), reply)
         else:
             job.fail(QWebEngineUrlRequestJob.Error.UrlInvalid)
-    
+
     def __replyClosed(self, reply):
         """
         Private slot handling the closed signal of a reply.
-        
+
         @param reply reference to the network reply
         @type QtHelpSchemeReply
         """
@@ -102,16 +99,17 @@
 class QtHelpSchemeReply(QIODevice):
     """
     Class implementing a reply for a requested qthelp: page.
-    
+
     @signal closed emitted to signal that the web engine has read
         the data
     """
+
     closed = pyqtSignal()
-    
+
     def __init__(self, job, engine, parent=None):
         """
         Constructor
-        
+
         @param job reference to the URL request
         @type QWebEngineUrlRequestJob
         @param engine reference to the help engine
@@ -120,97 +118,98 @@
         @type QObject
         """
         super().__init__(parent)
-        
+
         self.__job = job
         self.__engine = engine
         self.__mutex = QMutex()
-        
+
         self.__buffer = QBuffer()
-        
+
         # determine mimetype
         url = self.__job.requestUrl()
         strUrl = url.toString()
-        
+
         # For some reason the url to load maybe wrong (passed from web engine)
         # though the css file and the references inside should work that way.
         # One possible problem might be that the css is loaded at the same
         # level as the html, thus a path inside the css like
         # (../images/foo.png) might cd out of the virtual folder
-        if (
-            not self.__engine.findFile(url).isValid() and
-            strUrl.startswith(QtDocPath)
-        ):
+        if not self.__engine.findFile(url).isValid() and strUrl.startswith(QtDocPath):
             newUrl = self.__job.requestUrl()
             if not newUrl.path().startswith("/qdoc/"):
                 newUrl.setPath("/qdoc" + newUrl.path())
                 url = newUrl
                 strUrl = url.toString()
-        
+
         self.__mimeType = mimetypes.guess_type(strUrl)[0]
         if self.__mimeType is None:
             # do our own (limited) guessing
             self.__mimeType = self.__mimeFromUrl(url)
-        
+
         self.__loadQtHelpPage(url)
-    
+
     def __loadQtHelpPage(self, url):
         """
         Private method to load the requested QtHelp page.
-        
+
         @param url URL of the requested page
         @type QUrl
         """
         data = (
             self.__engine.fileData(url)
-            if self.__engine.findFile(url).isValid() else
-            QByteArray(self.tr(
-                """<html>"""
-                """<head><title>Error 404...</title></head>"""
-                """<body><div align="center"><br><br>"""
-                """<h1>The page could not be found</h1><br>"""
-                """<h3>'{0}'</h3></div></body>"""
-                """</html>""").format(url.toString())
-                .encode("utf-8"))
+            if self.__engine.findFile(url).isValid()
+            else QByteArray(
+                self.tr(
+                    """<html>"""
+                    """<head><title>Error 404...</title></head>"""
+                    """<body><div align="center"><br><br>"""
+                    """<h1>The page could not be found</h1><br>"""
+                    """<h3>'{0}'</h3></div></body>"""
+                    """</html>"""
+                )
+                .format(url.toString())
+                .encode("utf-8")
+            )
         )
-        
+
         with EricMutexLocker(self.__mutex):
             self.__buffer.setData(data)
             self.__buffer.open(QIODevice.OpenModeFlag.ReadOnly)
             self.open(QIODevice.OpenModeFlag.ReadOnly)
-        
+
         self.readyRead.emit()
-    
+
     def bytesAvailable(self):
         """
         Public method to get the number of available bytes.
-        
+
         @return number of available bytes
         @rtype int
         """
         with EricMutexLocker(self.__mutex):
             return self.__buffer.bytesAvailable()
-    
+
     def readData(self, maxlen):
         """
         Public method to retrieve data from the reply object.
-        
+
         @param maxlen maximum number of bytes to read (integer)
         @return string containing the data (bytes)
         """
         with EricMutexLocker(self.__mutex):
             return self.__buffer.read(maxlen)
-    
+
     def close(self):
         """
         Public method used to cloase the reply.
         """
         super().close()
         self.closed.emit()
-    
+
     def __mimeFromUrl(self, url):
         """
         Private method to guess the mime type given an URL.
-        
+
         @param url URL to guess the mime type from (QUrl)
         @return mime type for the given URL (string)
         """
@@ -220,11 +219,11 @@
             return ExtensionMap[ext]
         else:
             return "application/octet-stream"
-    
+
     def mimeType(self):
         """
         Public method to get the reply mime type.
-        
+
         @return mime type of the reply
         @rtype bytes
         """

eric ide

mercurial