Helpviewer/Network/FtpReply.py

Sun, 18 May 2014 14:13:09 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 18 May 2014 14:13:09 +0200
changeset 3591
2f2a4a76dd22
parent 3484
645c12de6b0c
child 3656
441956d8fce5
permissions
-rw-r--r--

Corrected a bunch of source docu issues.

278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
3 # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a network reply class for FTP resources.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3058
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
11 try:
3484
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3178 3190
diff changeset
12 str = unicode
645c12de6b0c Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3178 3190
diff changeset
13 except NameError:
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
14 pass
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
15
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
16 import ftplib
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
17 import socket
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
18 import errno
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
19 import mimetypes
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
20
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
21 from PyQt4.QtCore import QByteArray, QIODevice, Qt, QUrl, QTimer, QBuffer, \
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
22 QCoreApplication
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
23 from PyQt4.QtGui import QPixmap, QDialog
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
24 from PyQt4.QtNetwork import QNetworkReply, QNetworkRequest, QAuthenticator
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 from PyQt4.QtWebKit import QWebSettings
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
27 from E5Network.E5Ftp import E5Ftp, E5FtpProxyError, E5FtpProxyType
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
28
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 import UI.PixmapCache
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
30
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
31 from Utilities.FtpUtilities import FtpDirLineParser, FtpDirLineParserError
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
32 import Utilities
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
34 import Preferences
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
35
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 ftpListPage_html = """\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 <?xml version="1.0" encoding="UTF-8" ?>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 <head>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 <title>{0}</title>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 <style type="text/css">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 body {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 padding: 3em 0em;
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
46 background: -webkit-gradient(linear, left top, left bottom, from(#85784A),
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
47 to(#FDFDFD), color-stop(0.5, #FDFDFD));
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 background-repeat: repeat-x;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 #box {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 background: white;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 border: 1px solid #85784A;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 width: 80%;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 padding: 30px;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 margin: auto;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 -webkit-border-radius: 0.8em;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 h1 {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 font-size: 130%;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 font-weight: bold;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 border-bottom: 1px solid #85784A;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 th {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 background-color: #B8B096;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 color: black;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 table {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 border: solid 1px #85784A;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 margin: 5px 0;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 width: 100%;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 tr.odd {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 background-color: white;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 color: black;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 tr.even {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 background-color: #CEC9B8;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 color: black;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 .modified {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 text-align: left;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 vertical-align: top;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 white-space: nowrap;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 .size {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 text-align: right;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 vertical-align: top;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 white-space: nowrap;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 padding-right: 22px;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 .name {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 text-align: left;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 vertical-align: top;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 white-space: pre-wrap;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 width: 100%
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 {1}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 </style>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 </head>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 <body>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 <div id="box">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 <h1>{2}</h1>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 {3}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 <table align="center" cellspacing="0" width="90%">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 {4}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 </table>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 </div>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 </body>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 </html>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
112
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 class FtpReply(QNetworkReply):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 Class implementing a network reply for FTP resources.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 """
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
117 def __init__(self, url, accessHandler, parent=None):
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 Constructor
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 @param url requested FTP URL (QUrl)
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
122 @param accessHandler reference to the access handler (FtpAccessHandler)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 @param parent reference to the parent object (QObject)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2403
diff changeset
125 super(FtpReply, self).__init__(parent)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126
304
98429932e0c9 Extended the fTP reply class to support authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 287
diff changeset
127 self.__manager = parent
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
128 self.__handler = accessHandler
304
98429932e0c9 Extended the fTP reply class to support authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 287
diff changeset
129
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
130 self.__ftp = E5Ftp()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.__items = []
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 self.__content = QByteArray()
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
134 self.__units = ["Bytes", "KB", "MB", "GB", "TB",
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
135 "PB", "EB", "ZB", "YB"]
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
136 self.__dirLineParser = FtpDirLineParser()
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
137 self.__fileBytesReceived = 0
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
287
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
139 if url.path() == "":
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
140 url.setPath("/")
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 self.setUrl(url)
287
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
142
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
143 # do proxy setup
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
144 if not Preferences.getUI("UseProxy"):
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
145 proxyType = E5FtpProxyType.NoProxy
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
146 else:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
147 proxyType = Preferences.getUI("ProxyType/Ftp")
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
148 if proxyType != E5FtpProxyType.NoProxy:
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
149 self.__ftp.setProxy(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
150 proxyType,
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
151 Preferences.getUI("ProxyHost/Ftp"),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
152 Preferences.getUI("ProxyPort/Ftp"))
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
153 if proxyType != E5FtpProxyType.NonAuthorizing:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
154 self.__ftp.setProxyAuthentication(
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
155 Preferences.getUI("ProxyUser/Ftp"),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
156 Preferences.getUI("ProxyPassword/Ftp"),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
157 Preferences.getUI("ProxyAccount/Ftp"))
311
df292f01b392 Fixed lagging in to FTP sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 304
diff changeset
158
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
159 QTimer.singleShot(0, self.__doFtpCommands)
287
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
160
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 def abort(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 Public slot to abort the operation.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 # do nothing
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 pass
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 def bytesAvailable(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 Public method to determined the bytes available for being read.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 @return bytes available (integer)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 return self.__content.size()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 def isSequential(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 Public method to check for sequential access.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 @return flag indicating sequential access (boolean)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 return True
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 def readData(self, maxlen):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
186 Public method to retrieve data from the reply object.
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 @param maxlen maximum number of bytes to read (integer)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @return string containing the data (bytes)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 if self.__content.size():
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 len_ = min(maxlen, self.__content.size())
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 buffer = bytes(self.__content[:len_])
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 self.__content.remove(0, len_)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 return buffer
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
197 def __doFtpCommands(self):
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
199 Private slot doing the sequence of FTP commands to get the requested
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
200 result.
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 """
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
202 retry = True
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
203 try:
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
204 username = self.url().userName()
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
205 password = self.url().password()
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
206 byAuth = False
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
207
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
208 while retry:
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
209 try:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
210 self.__ftp.connect(self.url().host(),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
211 self.url().port(ftplib.FTP_PORT),
2054
099993935e6d Added the forgotten timeout parameter when connecting to an FTP proxy.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2053
diff changeset
212 timeout=10)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
213 except E5FtpProxyError as err:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
214 self.setError(QNetworkReply.ProxyNotFoundError, str(err))
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
215 self.error.emit(QNetworkReply.ProxyNotFoundError)
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
216 self.finished.emit()
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
217 ok, retry = self.__doFtpLogin(username, password, byAuth)
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
218 if not ok and retry:
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
219 auth = self.__handler.getAuthenticator(self.url().host())
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
220 if auth and not auth.isNull() and auth.user():
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
221 username = auth.user()
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
222 password = auth.password()
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
223 byAuth = True
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
224 else:
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
225 retry = False
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
226 if ok:
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
227 self.__ftp.retrlines("LIST " + self.url().path(),
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
228 self.__dirCallback)
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
229 if len(self.__items) == 1 and \
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
230 self.__items[0].isFile():
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
231 self.__fileBytesReceived = 0
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
232 self.__setContent()
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
233 self.__ftp.retrbinary(
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
234 "RETR " + self.url().path(), self.__retrCallback)
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
235 self.__content.append(512 * b' ')
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
236 self.readyRead.emit()
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
237 else:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
238 self.__setListContent()
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
239 self.__ftp.quit()
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
240 except ftplib.all_errors as err:
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
241 if isinstance(err, socket.gaierror):
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
242 errCode = QNetworkReply.HostNotFoundError
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
243 elif isinstance(err, socket.error) and \
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
244 err.errno == errno.ECONNREFUSED:
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
245 errCode = QNetworkReply.ConnectionRefusedError
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
246 else:
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
247 errCode = QNetworkReply.ProtocolFailure
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
248 self.setError(errCode, str(err))
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
249 self.error.emit(errCode)
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
250 self.finished.emit()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
252 def __doFtpLogin(self, username, password, byAuth=False):
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
253 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
254 Private method to do the FTP login with asking for a username and
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
255 password, if the login fails with an error 530.
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
256
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
257 @param username user name to use for the login (string)
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
258 @param password password to use for the login (string)
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
259 @param byAuth flag indicating that the login data was provided by an
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
260 authenticator (boolean)
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
261 @return tuple of two flags indicating a successful login and
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
262 if the login should be retried (boolean, boolean)
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
263 """
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
264 try:
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
265 self.__ftp.login(username, password)
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
266 return True, False
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
267 except E5FtpProxyError as err:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
268 code = str(err)[:3]
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
269 if code[1] == "5":
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
270 # could be a 530, check second line
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
271 lines = str(err).splitlines()
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
272 if lines[1][:3] == "530":
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
273 if "usage" in "\n".join(lines[1:].lower()):
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
274 # found a not supported proxy
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
275 self.setError(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
276 QNetworkReply.ProxyConnectionRefusedError,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
277 self.tr("The proxy type seems to be wrong."
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
278 " If it is not in the list of"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
279 " supported proxy types please report"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
280 " it with the instructions given by"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
281 " the proxy.\n{0}").format(
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
282 "\n".join(lines[1:])))
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
283 self.error.emit(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
284 QNetworkReply.ProxyConnectionRefusedError)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
285 return False, False
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
286 else:
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
287 from UI.AuthenticationDialog import \
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
288 AuthenticationDialog
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
289 info = self.tr(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
290 "<b>Connect to proxy '{0}' using:</b>")\
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
291 .format(Utilities.html_encode(
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
292 Preferences.getUI("ProxyHost/Ftp")))
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
293 dlg = AuthenticationDialog(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
294 info, Preferences.getUI("ProxyUser/Ftp"), True)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
295 dlg.setData(Preferences.getUI("ProxyUser/Ftp"),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
296 Preferences.getUI("ProxyPassword/Ftp"))
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
297 if dlg.exec_() == QDialog.Accepted:
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
298 username, password = dlg.getData()
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
299 if dlg.shallSave():
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
300 Preferences.setUI("ProxyUser/Ftp", username)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
301 Preferences.setUI(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
302 "ProxyPassword/Ftp", password)
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
303 self.__ftp.setProxyAuthentication(username,
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
304 password)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
305 return False, True
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
306 return False, False
2082
5d72ca2fbeab Fixed an issue in the FtpReply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2080
diff changeset
307 except (ftplib.error_perm, ftplib.error_temp) as err:
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
308 code = err.args[0].strip()[:3]
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
309 if code in ["530", "421"]:
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
310 # error 530 -> Login incorrect
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
311 # error 421 -> Login may be incorrect (reported by some
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
312 # proxies)
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
313 if byAuth:
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
314 self.__handler.setAuthenticator(self.url().host(), None)
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
315 auth = None
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
316 else:
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
317 auth = self.__handler.getAuthenticator(self.url().host())
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
318 if not auth or auth.isNull() or not auth.user():
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
319 auth = QAuthenticator()
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
320 self.__manager.authenticationRequired.emit(self, auth)
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
321 if not auth.isNull():
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
322 if auth.user():
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
323 self.__handler.setAuthenticator(self.url().host(),
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
324 auth)
2050
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
325 return False, True
585f6646bf50 Changed the FtpReply to support proxy access and to not show user and password in the URL.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2047
diff changeset
326 return False, False
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2054
diff changeset
327 return False, True
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
328 else:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
329 raise
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
330
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
331 def __dirCallback(self, line):
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
332 """
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
333 Private slot handling the receipt of directory listings.
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
334
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
335 @param line the received line of the directory listing (string)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 """
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
337 try:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
338 urlInfo = self.__dirLineParser.parseLine(line)
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
339 except FtpDirLineParserError:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
340 # silently ignore parser errors
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
341 urlInfo = None
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
343 if urlInfo:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
344 self.__items.append(urlInfo)
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
345
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
346 QCoreApplication.processEvents()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
348 def __retrCallback(self, data):
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 """
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
350 Private slot handling the reception of data.
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
351
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
352 @param data data received from the FTP server (bytes)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 """
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
354 self.__content += QByteArray(data)
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
355 self.__fileBytesReceived += len(data)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
356 self.downloadProgress.emit(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
357 self.__fileBytesReceived, self.__items[0].size())
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
358 self.readyRead.emit()
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
359
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
360 QCoreApplication.processEvents()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 def __setContent(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 """
1625
4f03e45703e9 Corrected a source docu string in FtpReply.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
364 Private method to finish the setup of the data.
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 """
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
366 mtype, encoding = mimetypes.guess_type(self.url().toString())
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 self.open(QIODevice.ReadOnly | QIODevice.Unbuffered)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
368 self.setHeader(QNetworkRequest.ContentLengthHeader,
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
369 self.__items[0].size())
2047
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
370 if mtype:
739aa1717df5 Extended the new FtpReply class to handle various directory listing styles and to ask for a username and password, if the FTP login fails with an error code of 530.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2044
diff changeset
371 self.setHeader(QNetworkRequest.ContentTypeHeader, mtype)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 self.setAttribute(QNetworkRequest.HttpStatusCodeAttribute, 200)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 self.setAttribute(QNetworkRequest.HttpReasonPhraseAttribute, "Ok")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 self.metaDataChanged.emit()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
376 def __cssLinkClass(self, icon, size=32):
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 Private method to generate a link class with an icon.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 @param icon icon to be included (QIcon)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 @param size size of the icon to be generated (integer)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 @return CSS class string (string)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 cssString = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 """a.{{0}} {{{{\n"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 """ padding-left: {0}px;\n"""\
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
387 """ background: transparent url(data:image/png;base64,{1})"""\
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
388 """ no-repeat center left;\n"""\
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 """ font-weight: bold;\n"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 """}}}}\n"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 pixmap = icon.pixmap(size, size)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 imageBuffer = QBuffer()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 imageBuffer.open(QIODevice.ReadWrite)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 if not pixmap.save(imageBuffer, "PNG"):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 # write a blank pixmap on error
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 pixmap = QPixmap(size, size)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 pixmap.fill(Qt.transparent)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 imageBuffer.buffer().clear()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 pixmap.save(imageBuffer, "PNG")
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
400 return cssString.format(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
401 size + 4,
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 str(imageBuffer.buffer().toBase64(), encoding="ascii"))
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 def __setListContent(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 Private method to prepare the content for the reader.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 u = self.url()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 if not u.path().endswith("/"):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 u.setPath(u.path() + "/")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 baseUrl = self.url().toString()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 basePath = u.path()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 linkClasses = {}
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
416 iconSize = QWebSettings.globalSettings().fontSize(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
417 QWebSettings.DefaultFontSize)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 parent = u.resolved(QUrl(".."))
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 if parent.isParentOf(u):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421 icon = UI.PixmapCache.getIcon("up.png")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 linkClasses["link_parent"] = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 self.__cssLinkClass(icon, iconSize).format("link_parent")
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
424 parentStr = self.tr(
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 """ <p><a class="link_parent" href="{0}">"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 """Change to parent directory</a></p>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 ).format(parent.toString())
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 else:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 parentStr = ""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 row = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
432 """ <tr class="{0}">"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 """<td class="name"><a class="{1}" href="{2}">{3}</a></td>"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 """<td class="size">{4}</td>"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 """<td class="modified">{5}</td>"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436 """</tr>\n"""
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
437 table = self.tr(
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 """ <tr>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 """<th align="left">Name</th>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 """<th>Size</th>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 """<th align="left">Last modified</th>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 """</tr>\n"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 )
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 i = 0
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 for item in self.__items:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 name = item.name()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
448 if item.isDir() and not name.endswith("/"):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 name += "/"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 child = u.resolved(QUrl(name.replace(":", "%3A")))
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 if item.isFile():
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 size = item.size()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
454 unit = 0
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
455 while size:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
456 newSize = size // 1024
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
457 if newSize and unit < len(self.__units):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
458 size = newSize
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 unit += 1
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460 else:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 break
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
462
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
463 sizeStr = self.tr("{0} {1}", "size unit")\
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
464 .format(size, self.__units[unit])
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
465 linkClass = "link_file"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 if linkClass not in linkClasses:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 icon = UI.PixmapCache.getIcon("fileMisc.png")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 linkClasses[linkClass] = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
469 self.__cssLinkClass(icon, iconSize).format(linkClass)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
470 else:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 sizeStr = ""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 linkClass = "link_dir"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473 if linkClass not in linkClasses:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 icon = UI.PixmapCache.getIcon("dirClosed.png")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
475 linkClasses[linkClass] = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
476 self.__cssLinkClass(icon, iconSize).format(linkClass)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 table += row.format(
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 i == 0 and "odd" or "even",
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
479 linkClass,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
480 child.toString(),
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
481 Utilities.html_encode(item.name()),
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
482 sizeStr,
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
483 item.lastModified().toString("yyyy-MM-dd hh:mm"),
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
484 )
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
485 i = 1 - i
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
486
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
487 content = ftpListPage_html.format(
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
488 Utilities.html_encode(baseUrl),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
489 "".join(linkClasses.values()),
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
490 self.tr("Listing of {0}").format(basePath),
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
491 parentStr,
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
492 table
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
493 )
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
494 self.__content = QByteArray(content.encode("utf8"))
2044
9d229b584c49 Change the FtpReply class to use Python ftplib instead of QFtp because the later is not available in Qt5 anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1625
diff changeset
495 self.__content.append(512 * b' ')
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
496
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
497 self.open(QIODevice.ReadOnly | QIODevice.Unbuffered)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
498 self.setHeader(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
499 QNetworkRequest.ContentTypeHeader, "text/html; charset=UTF-8")
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
500 self.setHeader(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
501 QNetworkRequest.ContentLengthHeader, self.__content.size())
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502 self.setAttribute(QNetworkRequest.HttpStatusCodeAttribute, 200)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 self.setAttribute(QNetworkRequest.HttpReasonPhraseAttribute, "Ok")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
504 self.metaDataChanged.emit()
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
505 self.downloadProgress.emit(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2403
diff changeset
506 self.__content.size(), self.__content.size())
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 self.readyRead.emit()

eric ide

mercurial