9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 import os |
12 import os |
13 |
13 |
14 from PyQt5.QtCore import pyqtSignal, QObject, QByteArray, QUrl, \ |
14 from PyQt5.QtCore import pyqtSignal, QObject, QByteArray, QUrl, QUrlQuery, \ |
15 QCoreApplication, QXmlStreamReader |
15 QCoreApplication, QXmlStreamReader |
16 from PyQt5.QtWidgets import QApplication |
16 from PyQt5.QtWidgets import QApplication |
17 from PyQt5.QtNetwork import QNetworkRequest |
17 from PyQt5.QtNetwork import QNetworkRequest |
18 from PyQt5.QtWebKit import QWebSettings |
18 from PyQt5.QtWebKit import QWebSettings |
19 from PyQt5.QtWebKitWidgets import QWebPage |
19 from PyQt5.QtWebKitWidgets import QWebPage |
115 |
115 |
116 @param url URL to get the credentials for (QUrl) |
116 @param url URL to get the credentials for (QUrl) |
117 @param realm realm to get the credentials for (string) |
117 @param realm realm to get the credentials for (string) |
118 @return key string (string) |
118 @return key string (string) |
119 """ |
119 """ |
|
120 authority = url.authority() |
|
121 if authority.startswith("@"): |
|
122 authority = authority[1:] |
120 if realm: |
123 if realm: |
121 key = "{0}://{1} ({2})".format( |
124 key = "{0}://{1} ({2})".format( |
122 url.scheme(), url.authority(), realm) |
125 url.scheme(), authority, realm) |
123 else: |
126 else: |
124 key = "{0}://{1}".format(url.scheme(), url.authority()) |
127 key = "{0}://{1}".format(url.scheme(), authority) |
125 return key |
128 return key |
126 |
129 |
127 def getFileName(self): |
130 def getFileName(self): |
128 """ |
131 """ |
129 Public method to get the file name of the passwords file. |
132 Public method to get the file name of the passwords file. |
433 @param url URL to be stripped (QUrl) |
436 @param url URL to be stripped (QUrl) |
434 @return stripped URL (QUrl) |
437 @return stripped URL (QUrl) |
435 """ |
438 """ |
436 cleanUrl = QUrl(url) |
439 cleanUrl = QUrl(url) |
437 cleanUrl.setQuery("") |
440 cleanUrl.setQuery("") |
|
441 cleanUrl.setUserInfo("") |
|
442 |
|
443 authority = cleanUrl.authority() |
|
444 if authority.startswith("@"): |
|
445 authority = authority[1:] |
|
446 cleanUrl = QUrl("{0}://{1}{2}".format( |
|
447 cleanUrl.scheme(), authority, cleanUrl.path())) |
438 cleanUrl.setFragment("") |
448 cleanUrl.setFragment("") |
439 cleanUrl.setUserInfo("") |
|
440 return cleanUrl |
449 return cleanUrl |
441 |
450 |
442 def __findForm(self, webPage, data, boundary=None): |
451 def __findForm(self, webPage, data, boundary=None): |
443 """ |
452 """ |
444 Private method to find the form used for logging in. |
453 Private method to find the form used for logging in. |
453 form = LoginForm() |
462 form = LoginForm() |
454 if boundary is not None: |
463 if boundary is not None: |
455 args = self.__extractMultipartQueryItems(data, boundary) |
464 args = self.__extractMultipartQueryItems(data, boundary) |
456 else: |
465 else: |
457 argsUrl = QUrl.fromEncoded( |
466 argsUrl = QUrl.fromEncoded( |
458 QByteArray("foo://bar.com/?" + data.replace(b"+", b"%20"))) |
467 QByteArray("foo://bar.com/?" + QUrl.fromPercentEncoding( |
459 encodedArgs = argsUrl.queryItems() |
468 data.replace(b"+", b"%20")))) |
|
469 encodedArgs = QUrlQuery(argsUrl).queryItems() |
460 args = set() |
470 args = set() |
461 for arg in encodedArgs: |
471 for arg in encodedArgs: |
462 key = arg[0] |
472 key = arg[0] |
463 value = arg[1] |
473 value = arg[1] |
464 args.add((key, value)) |
474 args.add((key, value)) |