Extended the fTP reply class to support authentication.

Sat, 29 May 2010 15:26:00 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 29 May 2010 15:26:00 +0200
changeset 304
98429932e0c9
parent 303
17906f47712a
child 305
5cf9e308f342

Extended the fTP reply class to support authentication.

Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Helpviewer/Network/FtpReply.py file | annotate | diff | comparison | revisions
Binary file Documentation/Help/source.qch has changed
--- a/Helpviewer/Network/FtpReply.py	Sat May 29 15:25:12 2010 +0200
+++ b/Helpviewer/Network/FtpReply.py	Sat May 29 15:26:00 2010 +0200
@@ -10,7 +10,7 @@
 from PyQt4.QtCore import QByteArray, QIODevice, Qt, QUrl, QTimer, QBuffer
 from PyQt4.QtGui import QPixmap
 from PyQt4.QtNetwork import QFtp, QNetworkReply, QNetworkRequest, QUrlInfo, \
-    QNetworkProxyQuery, QNetworkProxy
+    QNetworkProxyQuery, QNetworkProxy, QAuthenticator
 from PyQt4.QtWebKit import QWebSettings
 
 import UI.PixmapCache
@@ -103,6 +103,8 @@
         """
         QNetworkReply.__init__(self, parent)
         
+        self.__manager = parent
+        
         self.__ftp = QFtp(self)
         self.__ftp.listInfo.connect(self.__processListInfo)
         self.__ftp.readyRead.connect(self.__processData)
@@ -203,19 +205,35 @@
         @param error flag indicating an error condition (boolean)
         """
         if error:
-            if error == QFtp.HostNotFound:
+            if self.__ftp.error() == QFtp.HostNotFound:
                 err = QNetworkReply.HostNotFoundError
-            elif error == QFtp.ConnectionRefused:
+            elif self.__ftp.error() == QFtp.ConnectionRefused:
                 err = QNetworkReply.ConnectionRefusedError
             else:
-                err = QNetworkReply.ContentNotFoundError
+                if self.__ftp.state() != QFtp.LoggedIn and \
+                   self.__ftp.state() == QFtp.Connected:
+                    # authentication is required
+                    newUrl = self.url()
+                    auth = QAuthenticator()
+                    self.__manager.authenticationRequired.emit(self, auth)
+                    if not auth.isNull():
+                        newUrl.setUserName(auth.user())
+                        newUrl.setPassword(auth.password())
+                        self.setUrl(newUrl)
+                        self.__ftp.login(auth.user(), auth.password())
+                        return
+                
+                err = QNetworkReply.ProtocolFailure
             self.setError(err, self.__ftp.errorString())
             self.error.emit(err)
+            self.finished.emit()
+            if self.__ftp.state() != QFtp.Unconnected:
+                self.__ftp.close()
             return
         
         cmd = self.__ftp.currentCommand()
         if cmd == QFtp.ConnectToHost:
-            self.__ftp.login()
+            self.__ftp.login(self.url().userName(), self.url().password())
         elif cmd == QFtp.Login:
             self.__ftp.list(self.url().path())
         elif cmd == QFtp.List:

eric ide

mercurial