WebBrowser/CookieJar/CookieJar.py

Mon, 03 Jul 2017 19:23:54 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 03 Jul 2017 19:23:54 +0200
changeset 5783
44a9f08de394
parent 5474
3df49db6a347
child 6048
82ad8ec9548c
permissions
-rw-r--r--

Continued implementing session support for the new web browser.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
5389
9b1c800daff3 Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5030
diff changeset
3 # Copyright (c) 2009 - 2017 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a QNetworkCookieJar subclass with various accept policies.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
11
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
14 from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSettings
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
15 from PyQt5.QtNetwork import QNetworkCookieJar, QNetworkCookie
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
16
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
17 from WebBrowser.WebBrowserWindow import WebBrowserWindow
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 from Utilities.AutoSaver import AutoSaver
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 import Utilities
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 import Preferences
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
23
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 class CookieJar(QNetworkCookieJar):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
26 Class implementing a QNetworkCookieJar subclass with various accept
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
27 policies.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @signal cookiesChanged() emitted after the cookies have been changed
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
31 cookiesChanged = pyqtSignal()
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
32
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
33 AcceptAlways = 0
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
34 AcceptNever = 1
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
35 AcceptOnlyFromSitesNavigatedTo = 2
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
36 AcceptMax = 2
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
38 KeepUntilExpire = 0
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
39 KeepUntilExit = 1
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
40 KeepMax = 1
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
42 Allow = 0
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
43 Block = 1
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 AllowForSession = 2
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
46 def __init__(self, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 @param parent reference to the parent object (QObject)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
52 super(CookieJar, self).__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__loaded = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__acceptCookies = self.AcceptOnlyFromSitesNavigatedTo
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
56 self.__saveTimer = AutoSaver(self, self.__save)
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
57
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
58 self.__cookiesFile = os.path.join(Utilities.getConfigDir(),
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
59 "web_browser", "cookies.ini")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
61 self.__store = WebBrowserWindow.webProfile().cookieStore()
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
62 self.__store.cookieAdded.connect(self.__cookieAdded)
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
63 self.__store.cookieRemoved.connect(self.__cookieRemoved)
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
64
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
65 self.__load()
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
66 self.__store.loadAllCookies()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 def close(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Public slot to close the cookie jar.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
72 if not self.__loaded:
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
73 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
74
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
75 if self.__keepCookies == self.KeepUntilExit:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.__saveTimer.saveIfNeccessary()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 def clear(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 Public method to clear all cookies.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
84 self.__load()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
86 self.setAllCookies([])
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
87 self.__store.deleteAllCookies()
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
88 self.cookiesChanged.emit()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
90 def removeCookies(self, cookies):
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
91 """
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
92 Public method to remove a list of cookies.
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
93
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
94 @param cookies list of cookies to be removed
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
95 @type list of QNetworkCookie
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
97 wasBlocked = self.blockSignals(True)
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
98 for cookie in cookies:
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
99 self.__store.deleteCookie(cookie)
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
100 self.blockSignals(wasBlocked)
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
101
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
102 self.cookiesChanged.emit()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
103
5030
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
104 def removeCookie(self, cookie):
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
105 """
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
106 Public method to remove a cookie.
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
107
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
108 @param cookie cookie to be removed
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
109 @type QNetworkCookie
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
110 """
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
111 self.__store.deleteCookie(cookie)
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
112 self.cookiesChanged.emit()
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
113
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
114 def __load(self):
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
115 """
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
116 Private method to load the cookies settings.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 if self.__loaded:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 cookieSettings = QSettings(self.__cookiesFile, QSettings.IniFormat)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 # load exceptions
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
124 self.__exceptionsBlock = Preferences.toList(
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
125 cookieSettings.value("Exceptions/block"))
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
126 self.__exceptionsAllow = Preferences.toList(
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
127 cookieSettings.value("Exceptions/allow"))
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
128 self.__exceptionsAllowForSession = Preferences.toList(
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
129 cookieSettings.value("Exceptions/allowForSession"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 self.__exceptionsBlock.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 self.__exceptionsAllow.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.__exceptionsAllowForSession.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
134 self.__acceptCookies = Preferences.getWebBrowser("AcceptCookies")
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135 self.__keepCookies = Preferences.getWebBrowser("KeepCookiesUntil")
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 if self.__keepCookies == self.KeepUntilExit:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
137 self.clear()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
65
ca6449ba4824 Fixed a few porting bugs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
139 self.__filterTrackingCookies = Preferences.toBool(
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
140 Preferences.getWebBrowser("FilterTrackingCookies"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 self.__loaded = True
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
143 self.cookiesChanged.emit()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
145 def __save(self):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
147 Private method to save the cookies settings.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 if not self.__loaded:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 cookieSettings = QSettings(self.__cookiesFile, QSettings.IniFormat)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
154 cookieSettings.setValue("Exceptions/block", self.__exceptionsBlock)
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
155 cookieSettings.setValue("Exceptions/allow", self.__exceptionsAllow)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
156 cookieSettings.setValue("Exceptions/allowForSession",
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
157 self.__exceptionsAllowForSession)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
159 Preferences.setWebBrowser("AcceptCookies", self.__acceptCookies)
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
160 Preferences.setWebBrowser("KeepCookiesUntil", self.__keepCookies)
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
161 Preferences.setWebBrowser("FilterTrackingCookies",
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
162 self.__filterTrackingCookies)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
164 @pyqtSlot(QNetworkCookie)
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
165 def __cookieAdded(self, cookie):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
167 Private slot handling the addition of a cookie.
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
168
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
169 @param cookie cookie which was added
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
170 @type QNetworkCookie
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
172 if self.__rejectCookie(cookie, cookie.domain()):
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
173 self.__store.deleteCookie(cookie)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
176 self.insertCookie(cookie)
487
4d41d03d3d00 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
177 self.cookiesChanged.emit()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
179 @pyqtSlot(QNetworkCookie)
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
180 def __cookieRemoved(self, cookie):
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
181 """
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
182 Private slot handling the removal of a cookie.
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
183
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
184 @param cookie cookie which was removed
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
185 @type QNetworkCookie
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
187 if self.deleteCookie(cookie):
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
188 self.cookiesChanged.emit()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
189
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
190 def __rejectCookie(self, cookie, cookieDomain):
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
191 """
4917
682750cc7bd5 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4886
diff changeset
192 Private method to test, if a cookie shall be rejected.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
194 @param cookie cookie to be tested
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
195 @type QNetworkCookie
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
196 @param cookieDomain domain of the cookie
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
197 @type str
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
198 @return flag indicating the cookie shall be rejected
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
199 @rtype bool
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
202 self.__load()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
204 if self.__acceptCookies == self.AcceptNever:
5028
f7ea46dd1b7e Fixed bugs in the cookie handling of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5025
diff changeset
205 res = self.__isOnDomainList(self.__exceptionsAllow, cookieDomain)
f7ea46dd1b7e Fixed bugs in the cookie handling of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5025
diff changeset
206 if not res:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
207 return True
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
208
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
209 if self.__acceptCookies == self.AcceptAlways:
5028
f7ea46dd1b7e Fixed bugs in the cookie handling of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5025
diff changeset
210 res = self.__isOnDomainList(self.__exceptionsBlock, cookieDomain)
f7ea46dd1b7e Fixed bugs in the cookie handling of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5025
diff changeset
211 if res:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
212 return True
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
214 if self.__acceptCookies == self.AcceptOnlyFromSitesNavigatedTo:
5474
3df49db6a347 Fixed an issue in the Web browser cookie jar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
215 mainWindow = WebBrowserWindow.mainWindow()
3df49db6a347 Fixed an issue in the Web browser cookie jar.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
216 if mainWindow is not None:
5783
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
217 browser = mainWindow.getWindow().currentBrowser()
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
218 if browser is not None:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
219 url = browser.url()
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
220 if url.isValid():
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
221 host = url.host()
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
222 else:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
223 host = ""
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
224 res = self.__matchDomain(cookieDomain, host)
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
225 if not res:
44a9f08de394 Continued implementing session support for the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5474
diff changeset
226 return True
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
228 if self.__filterTrackingCookies and cookie.name().startsWith(b"__utm"):
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
229 return True
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
231 return False
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 def acceptPolicy(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235 Public method to get the accept policy.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 @return current accept policy
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
240 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
241
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 return self.__acceptCookies
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 def setAcceptPolicy(self, policy):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 Public method to set the accept policy.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 @param policy accept policy to be set
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
251 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
252
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
253 if policy > self.AcceptMax:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 if policy == self.__acceptCookies:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 return
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
257
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 self.__acceptCookies = policy
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 self.__saveTimer.changeOccurred()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 def keepPolicy(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
263 Public method to get the keep policy.
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
264
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
265 @return keep policy
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
268 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
269
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 return self.__keepCookies
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 def setKeepPolicy(self, policy):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 Public method to set the keep policy.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 @param policy keep policy to be set
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
279 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
280
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
281 if policy > self.KeepMax:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 if policy == self.__keepCookies:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 return
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
285
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 self.__keepCookies = policy
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 self.__saveTimer.changeOccurred()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 def blockedCookies(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
291 Public method to return the list of blocked domains.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
293 @return list of blocked domains (list of strings)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
296 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
297
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 return self.__exceptionsBlock
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 def allowedCookies(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
302 Public method to return the list of allowed domains.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
304 @return list of allowed domains (list of strings)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
307 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
308
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 return self.__exceptionsAllow
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 def allowForSessionCookies(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
313 Public method to return the list of allowed session cookie domains.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
315 @return list of allowed session cookie domains (list of strings)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
318 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
319
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 return self.__exceptionsAllowForSession
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322 def setBlockedCookies(self, list_):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
324 Public method to set the list of blocked domains.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
326 @param list_ list of blocked domains (list of strings)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
329 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
330
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 self.__exceptionsBlock = list_[:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 self.__exceptionsBlock.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 self.__saveTimer.changeOccurred()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 def setAllowedCookies(self, list_):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
337 Public method to set the list of allowed domains.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
339 @param list_ list of allowed domains (list of strings)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
342 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
343
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 self.__exceptionsAllow = list_[:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 self.__exceptionsAllow.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346 self.__saveTimer.changeOccurred()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 def setAllowForSessionCookies(self, list_):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
350 Public method to set the list of allowed session cookie domains.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
352 @param list_ list of allowed session cookie domains (list of strings)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 if not self.__loaded:
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
355 self.__load()
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
356
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 self.__exceptionsAllowForSession = list_[:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 self.__exceptionsAllowForSession.sort()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 self.__saveTimer.changeOccurred()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 def filterTrackingCookies(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 Public method to get the filter tracking cookies flag.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 @return filter tracking cookies flag (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 return self.__filterTrackingCookies
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 def setFilterTrackingCookies(self, filterTrackingCookies):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 Public method to set the filter tracking cookies flag.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 @param filterTrackingCookies filter tracking cookies flag (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 """
5025
2060a0f66c51 Fixed issues in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
375 if filterTrackingCookies == self.__filterTrackingCookies:
2060a0f66c51 Fixed issues in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
376 return
2060a0f66c51 Fixed issues in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
377
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378 self.__filterTrackingCookies = filterTrackingCookies
5025
2060a0f66c51 Fixed issues in the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4917
diff changeset
379 self.__saveTimer.changeOccurred()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 def __isOnDomainList(self, rules, domain):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
383 Private method to check, if either the rule matches the domain exactly
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 or the domain ends with ".rule".
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 @param rules list of rules (list of strings)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 @param domain domain name to check (string)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 @return flag indicating a match (boolean)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 for rule in rules:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 if rule.startswith("."):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 if domain.endswith(rule):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 return True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 withoutDot = rule[1:]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 if domain == withoutDot:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 return True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399 domainEnding = domain[-(len(rule) + 1):]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 if domainEnding and \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 domainEnding[0] == "." and \
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 domain.endswith(rule):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 return True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405 if rule == domain:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
406 return True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 return False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
410 def __matchDomain(self, cookieDomain, siteDomain):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411 """
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
412 Private method to check, if a URLs host matches a cookie domain
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
413 according to RFC 6265.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
414
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
415 @param cookieDomain domain of the cookie
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
416 @type str
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
417 @param siteDomain domain or host of an URL
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
418 @type str
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
419 @return flag indicating a match
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
420 @rtype bool
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
421 """
5028
f7ea46dd1b7e Fixed bugs in the cookie handling of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5025
diff changeset
422 if not siteDomain:
f7ea46dd1b7e Fixed bugs in the cookie handling of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5025
diff changeset
423 # empty URLs always match
f7ea46dd1b7e Fixed bugs in the cookie handling of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5025
diff changeset
424 return True
f7ea46dd1b7e Fixed bugs in the cookie handling of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5025
diff changeset
425
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
426 if cookieDomain.startswith("."):
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
427 cookieDomain = cookieDomain[1:]
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
428 if siteDomain.startswith("."):
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
429 siteDomain = siteDomain[1:]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430
4845
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
431 if cookieDomain == siteDomain:
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
432 return True
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
433
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
434 if not siteDomain.endswith(cookieDomain):
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
435 return False
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
436
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
437 index = siteDomain.find(cookieDomain)
2d22ff71c005 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
438 return index > 0 and siteDomain[index - 1] == "."
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 def cookies(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 Public method to get the cookies of the cookie jar.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 @return list of all cookies (list of QNetworkCookie)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 """
4886
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
446 if not self.__loaded:
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
447 self.__load()
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
448
b56735d36159 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4845
diff changeset
449 return self.allCookies()
5030
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
450
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
451 def cookieDomains(self):
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
452 """
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
453 Public method to get a list of all domains used by the cookies.
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
454
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
455 @return list of domain names
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
456 @rtype list of str
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
457 """
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
458 domains = []
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
459 for cookie in self.cookies():
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
460 domain = cookie.domain()
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
461 if domain not in domains:
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
462 domains.append(domain)
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
463
b728bb00886e Finished reworking the cookies dialog of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5028
diff changeset
464 return domains

eric ide

mercurial