Helpviewer/Network/FtpReply.py

Sun, 10 Feb 2013 18:31:31 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 10 Feb 2013 18:31:31 +0100
changeset 2403
e3d7a861547c
parent 2302
f29e9405c851
child 2525
8b507a9a2d40
child 3002
6ffc581f00f1
permissions
-rw-r--r--

Continued implementing the delayed import.

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
2302
f29e9405c851 Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2082
diff changeset
3 # Copyright (c) 2010 - 2013 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
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
10 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
11 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
12 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
13 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
14
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
15 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
16 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
17 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
18 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
19 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
20
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
21 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
22
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 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
24
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
25 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
26 import Utilities
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
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
28 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
29
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 ftpListPage_html = """\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 <?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
32 <!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
33 "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
34 <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
35 <head>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 <title>{0}</title>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 <style type="text/css">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 body {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 padding: 3em 0em;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 background: -webkit-gradient(linear, left top, left bottom, from(#85784A), to(#FDFDFD), color-stop(0.5, #FDFDFD));
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 background-repeat: repeat-x;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 #box {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 background: white;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 border: 1px solid #85784A;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 width: 80%;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 padding: 30px;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 margin: auto;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 -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
50 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 h1 {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 font-size: 130%;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 font-weight: bold;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 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
55 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 th {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 background-color: #B8B096;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 color: black;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 table {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 border: solid 1px #85784A;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 margin: 5px 0;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 width: 100%;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 tr.odd {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 background-color: white;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 color: black;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 tr.even {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 background-color: #CEC9B8;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 color: black;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 .modified {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 text-align: left;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 vertical-align: top;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 white-space: nowrap;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 .size {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 text-align: right;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 vertical-align: top;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 white-space: nowrap;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 padding-right: 22px;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 .name {{
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 text-align: left;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 vertical-align: top;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 white-space: pre-wrap;
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 width: 100%
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 }}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 {1}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 </style>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 </head>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 <body>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 <div id="box">
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 <h1>{2}</h1>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 {3}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 <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
98 {4}
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 </table>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 </div>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 </body>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 </html>
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
105
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 class FtpReply(QNetworkReply):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 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
109 """
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
110 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
111 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 Constructor
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 @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
115 @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
116 @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
117 """
1131
7781e396c903 Changed the code to use super() to access the superclass.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
118 super().__init__(parent)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
304
98429932e0c9 Extended the fTP reply class to support authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 287
diff changeset
120 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
121 self.__handler = accessHandler
304
98429932e0c9 Extended the fTP reply class to support authentication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 287
diff changeset
122
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
123 self.__ftp = E5Ftp()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 self.__items = []
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.__content = QByteArray()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 self.__units = ["Bytes", "KB", "MB", "GB", "TB", "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
128 self.__dirLineParser = FtpDirLineParser()
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
129 self.__fileBytesReceived = 0
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130
287
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
131 if url.path() == "":
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
132 url.setPath("/")
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 self.setUrl(url)
287
52b4c72080d2 Added proxy support to the FTP reply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 278
diff changeset
134
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
135 # 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
136 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
137 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
138 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
139 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
140 if 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
141 self.__ftp.setProxy(proxyType,
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
142 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
143 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
144 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
145 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
146 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
147 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
148 Preferences.getUI("ProxyAccount/Ftp"))
311
df292f01b392 Fixed lagging in to FTP sites.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 304
diff changeset
149
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
150 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
151
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 def abort(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 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
155 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 # do nothing
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 pass
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 def bytesAvailable(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 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
162
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 @return bytes available (integer)
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 return self.__content.size()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 def isSequential(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 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
170
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 @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
172 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 return True
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 def readData(self, maxlen):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 Protected method to retrieve data from the reply object.
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 @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
180 @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
181 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 if self.__content.size():
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 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
184 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
185 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
186 return buffer
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
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
188 def __doFtpCommands(self):
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 """
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
190 Private slot doing the sequence of FTP commands to get the requested result.
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 """
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
192 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
193 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
194 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
195 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
196 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
197
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
198 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
199 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
200 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
201 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
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 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
214 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
215 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
216 if ok:
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
217 self.__ftp.retrlines("LIST " + self.url().path(), self.__dirCallback)
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
218 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
219 self.__items[0].isFile():
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
220 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
221 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
222 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
223 "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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 errCode = QNetworkReply.HostNotFoundError
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
232 elif isinstance(err, socket.error) and err.errno == errno.ECONNREFUSED:
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
233 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
234 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
235 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
236 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
237 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
238 self.finished.emit()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
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
240 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
241 """
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
242 Private method to do the FTP login with asking for a username and password,
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
243 if the login fails with an error 530.
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
244
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
245 @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
246 @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
247 @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
248 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
249 @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
250 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
251 """
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
252 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
253 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
254 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
255 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
256 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
257 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
258 # 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
259 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
260 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
261 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
262 # found a not supported proxy
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
263 self.setError(QNetworkReply.ProxyConnectionRefusedError,
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
264 self.trUtf8("The proxy type seems to be wrong."
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 " If it is not in the list of supported"
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
266 " proxy types please report it with the"
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 " instructions given by the proxy.\n{0}").format(
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 "\n".join(lines[1:])))
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 self.error.emit(QNetworkReply.ProxyConnectionRefusedError)
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 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
271 else:
2403
e3d7a861547c Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
272 from UI.AuthenticationDialog import AuthenticationDialog
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
273 info = self.trUtf8("<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
274 .format(Utilities.html_encode(
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
275 Preferences.getUI("ProxyHost/Ftp")))
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
276 dlg = AuthenticationDialog(info,
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
277 Preferences.getUI("ProxyUser/Ftp"), 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
278 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
279 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
280 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
281 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
282 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
283 Preferences.setUI("ProxyUser/Ftp", username)
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
284 Preferences.setUI("ProxyPassword/Ftp", password)
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 self.__ftp.setProxyAuthentication(username, password)
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 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
287 return False, False
2082
5d72ca2fbeab Fixed an issue in the FtpReply class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2080
diff changeset
288 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
289 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
290 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
291 # error 530 -> Login incorrect
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
292 # error 421 -> Login may be incorrect (reported by some 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
293 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
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301 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
302 if 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
303 self.__handler.setAuthenticator(self.url().host(), 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
304 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
305 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
306 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
307 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
308 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
309
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
310 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
311 """
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
312 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
313
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
314 @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
315 """
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
316 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
317 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
318 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
319 # 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
320 urlInfo = None
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321
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
322 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
323 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
324
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
325 QCoreApplication.processEvents()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326
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
327 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
328 """
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
329 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
330
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 @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
332 """
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
333 self.__content += QByteArray(data)
2053
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
334 self.__fileBytesReceived += len(data)
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
335 self.downloadProgress.emit(self.__fileBytesReceived, self.__items[0].size())
ef81185e8b89 Improved the FtpReply a bit.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2050
diff changeset
336 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
337
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
338 QCoreApplication.processEvents()
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 def __setContent(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 """
1625
4f03e45703e9 Corrected a source docu string in FtpReply.py.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
342 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
343 """
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
344 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
345 self.open(QIODevice.ReadOnly | QIODevice.Unbuffered)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 self.setHeader(QNetworkRequest.ContentLengthHeader, 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
347 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
348 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
349 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
350 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
351 self.metaDataChanged.emit()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
353 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
354 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 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
356
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 @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
358 @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
359 @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
360 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 cssString = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 """a.{{0}} {{{{\n"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 """ padding-left: {0}px;\n"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 """ background: transparent url(data:image/png;base64,{1}) no-repeat center left;\n"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 """ font-weight: bold;\n"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 """}}}}\n"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 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
368 imageBuffer = QBuffer()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 imageBuffer.open(QIODevice.ReadWrite)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 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
371 # 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
372 pixmap = QPixmap(size, size)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 pixmap.fill(Qt.transparent)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 imageBuffer.buffer().clear()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 pixmap.save(imageBuffer, "PNG")
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 return cssString.format(size + 4,
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 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
378
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 def __setListContent(self):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 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
382 """
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 u = self.url()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 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
385 u.setPath(u.path() + "/")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 baseUrl = self.url().toString()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 basePath = u.path()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 linkClasses = {}
826
2e3e2055e715 Fixed a few PEP 8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
391 iconSize = QWebSettings.globalSettings().fontSize(QWebSettings.DefaultFontSize)
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 parent = u.resolved(QUrl(".."))
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 if parent.isParentOf(u):
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 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
396 linkClasses["link_parent"] = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 self.__cssLinkClass(icon, iconSize).format("link_parent")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 parentStr = self.trUtf8(
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 """ <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
400 """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
401 ).format(parent.toString())
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 else:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 parentStr = ""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 row = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 """ <tr class="{0}">"""\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 """<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
408 """<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
409 """<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
410 """</tr>\n"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 table = self.trUtf8(
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 """ <tr>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 """<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
414 """<th>Size</th>"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 """<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
416 """</tr>\n"""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 )
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 i = 0
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 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
421 name = item.name()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 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
423 name += "/"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
424 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
425
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 if item.isFile():
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 size = item.size()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 unit = 0
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 while size:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 newSize = size // 1024
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 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
432 size = newSize
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
433 unit += 1
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
434 else:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435 break
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
436
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 sizeStr = self.trUtf8("{0} {1}", "size unit")\
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438 .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
439 linkClass = "link_file"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 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
441 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
442 linkClasses[linkClass] = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 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
444 else:
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 sizeStr = ""
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 linkClass = "link_dir"
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
447 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
448 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
449 linkClasses[linkClass] = \
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 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
451 table += row.format(
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 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
453 linkClass,
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
454 child.toString(),
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
455 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
456 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
457 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
458 )
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
459 i = 1 - i
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
460
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
461 content = ftpListPage_html.format(
2080
4b33165dd55b Made the third set of Qt5 compatibility changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
462 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
463 "".join(linkClasses.values()),
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
464 self.trUtf8("Listing of {0}").format(basePath),
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 826
diff changeset
465 parentStr,
278
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
466 table
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
467 )
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
468 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
469 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
470
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
471 self.open(QIODevice.ReadOnly | QIODevice.Unbuffered)
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
472 self.setHeader(QNetworkRequest.ContentTypeHeader, "text/html; charset=UTF-8")
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
473 self.setHeader(QNetworkRequest.ContentLengthHeader, self.__content.size())
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
474 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
475 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
476 self.metaDataChanged.emit()
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
477 self.downloadProgress.emit(self.__content.size(), self.__content.size())
c93823b96faa Added a handler for ftp: URLs to the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
478 self.readyRead.emit()

eric ide

mercurial