eric6/Helpviewer/Network/FileAccessHandler.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric6/Helpviewer/Network/FileAccessHandler.py	Sun Apr 14 15:09:21 2019 +0200
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2012 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a scheme access handler for file.
+"""
+
+from __future__ import unicode_literals
+
+from PyQt5.QtCore import QFileInfo
+from PyQt5.QtNetwork import QNetworkAccessManager
+
+from .SchemeAccessHandler import SchemeAccessHandler
+
+
+class FileAccessHandler(SchemeAccessHandler):
+    """
+    Class implementing a scheme access handler for FTP.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent object (QObject)
+        """
+        super(FileAccessHandler, self).__init__(parent)
+    
+    def createRequest(self, op, request, outgoingData=None):
+        """
+        Public method to create a request.
+        
+        @param op the operation to be performed
+            (QNetworkAccessManager.Operation)
+        @param request reference to the request object (QNetworkRequest)
+        @param outgoingData reference to an IODevice containing data to be sent
+            (QIODevice)
+        @return reference to the created reply object (QNetworkReply)
+        """
+        if op == QNetworkAccessManager.GetOperation:
+            fileInfo = QFileInfo(request.url().toLocalFile())
+            if not fileInfo.isDir() or \
+               not fileInfo.isReadable() or \
+               not fileInfo.exists():
+                return None
+            from .FileReply import FileReply
+            return FileReply(request.url(), self.parent())
+        else:
+            return None

eric ide

mercurial