WebBrowser/Network/QtHelpSchemeHandler.py

branch
QtWebEngine
changeset 4913
e16573640cb8
parent 4875
4ee26909ac0d
child 5389
9b1c800daff3
equal deleted inserted replaced
4910:e97af1181efd 4913:e16573640cb8
14 14
15 from PyQt5.QtCore import pyqtSignal, QByteArray, QIODevice, QBuffer 15 from PyQt5.QtCore import pyqtSignal, QByteArray, QIODevice, QBuffer
16 from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler, \ 16 from PyQt5.QtWebEngineCore import QWebEngineUrlSchemeHandler, \
17 QWebEngineUrlRequestJob 17 QWebEngineUrlRequestJob
18 18
19 ##from .SchemeAccessHandler import SchemeAccessHandler
20 ##
21 ##from .NetworkReply import NetworkReply
22 ##
23 QtDocPath = "qthelp://org.qt-project." 19 QtDocPath = "qthelp://org.qt-project."
24 20
25 ExtensionMap = { 21 ExtensionMap = {
26 ".bmp": "image/bmp", 22 ".bmp": "image/bmp",
27 ".css": "text/css", 23 ".css": "text/css",
204 200
205 @return mime type of the reply 201 @return mime type of the reply
206 @rtype bytes 202 @rtype bytes
207 """ 203 """
208 return self.__mimeType.encode("utf-8") 204 return self.__mimeType.encode("utf-8")
209 ##
210 ##
211 ##
212 ##
213 ##
214 ##class QtHelpAccessHandler(SchemeAccessHandler):
215 ## """
216 ## Class implementing a scheme access handler for QtHelp.
217 ## """
218 ## def __init__(self, engine, parent=None):
219 ## """
220 ## Constructor
221 ##
222 ## @param engine reference to the help engine (QHelpEngine)
223 ## @param parent reference to the parent object (QObject)
224 ## """
225 ## SchemeAccessHandler.__init__(self, parent)
226 ##
227 ## self.__engine = engine
228 ##
229 ## def __mimeFromUrl(self, url):
230 ## """
231 ## Private method to guess the mime type given an URL.
232 ##
233 ## @param url URL to guess the mime type from (QUrl)
234 ## @return mime type for the given URL (string)
235 ## """
236 ## path = url.path()
237 ## ext = os.path.splitext(path)[1].lower()
238 ## if ext in ExtensionMap:
239 ## return ExtensionMap[ext]
240 ## else:
241 ## return "application/octet-stream"
242 ##
243 ## def createRequest(self, op, request, outgoingData=None):
244 ## """
245 ## Public method to create a request.
246 ##
247 ## @param op the operation to be performed
248 ## (QNetworkAccessManager.Operation)
249 ## @param request reference to the request object (QNetworkRequest)
250 ## @param outgoingData reference to an IODevice containing data to be sent
251 ## (QIODevice)
252 ## @return reference to the created reply object (QNetworkReply)
253 ## """
254 ## url = request.url()
255 ## strUrl = url.toString()
256 ##
257 ## # For some reason the url to load is already wrong (passed from webkit)
258 ## # though the css file and the references inside should work that way.
259 ## # One possible problem might be that the css is loaded at the same
260 ## # level as the html, thus a path inside the css like
261 ## # (../images/foo.png) might cd out of the virtual folder
262 ## if not self.__engine.findFile(url).isValid():
263 ## if strUrl.startswith(QtDocPath):
264 ## newUrl = request.url()
265 ## if not newUrl.path().startswith("/qdoc/"):
266 ## newUrl.setPath("qdoc" + newUrl.path())
267 ## url = newUrl
268 ## strUrl = url.toString()
269 ##
270 ## mimeType = mimetypes.guess_type(strUrl)[0]
271 ## if mimeType is None:
272 ## # do our own (limited) guessing
273 ## mimeType = self.__mimeFromUrl(url)
274 ##
275 ## if self.__engine.findFile(url).isValid():
276 ## data = self.__engine.fileData(url)
277 ## else:
278 ## data = QByteArray(self.tr(
279 ## """<title>Error 404...</title>"""
280 ## """<div align="center"><br><br>"""
281 ## """<h1>The page could not be found</h1><br>"""
282 ## """<h3>'{0}'</h3></div>""").format(strUrl).encode("utf-8"))
283 ## return NetworkReply(request, data, mimeType, self.parent())

eric ide

mercurial