Helpviewer/UserAgent/UserAgentManager.py

Wed, 15 Feb 2012 16:05:11 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 15 Feb 2012 16:05:11 +0100
changeset 1623
6b9654035a7c
parent 1621
85653d5d3bf9
child 1626
a77c8ea8582c
permissions
-rw-r--r--

Added signals to indicate, that the managed data was saved, to some web browser managers.

1596
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a user agent manager.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt4.QtCore import pyqtSignal, QObject
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from E5Gui import E5MessageBox
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from Utilities.AutoSaver import AutoSaver
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 import Utilities
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class UserAgentManager(QObject):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class implementing a user agent manager.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @signal changed() emitted to indicate a change
1623
6b9654035a7c Added signals to indicate, that the managed data was saved, to some web browser managers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1621
diff changeset
25 @signal userAgentSettingsSaved() emitted after the user agent settings were saved
1596
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 changed = pyqtSignal()
1623
6b9654035a7c Added signals to indicate, that the managed data was saved, to some web browser managers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1621
diff changeset
28 userAgentSettingsSaved = pyqtSignal()
1596
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 def __init__(self, parent=None):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Constructor
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param parent reference to the parent object (QObject)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 super().__init__(parent)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.__agents = {} # dictionary with agent strings indexed by host name
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.__loaded = False
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.__saveTimer = AutoSaver(self, self.save)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 self.changed.connect(self.__saveTimer.changeOccurred)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
1621
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
44 def getFileName(self):
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
45 """
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
46 Public method to get the file name of the user agents file.
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
47
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
48 @return name of the user agents file (string)
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
49 """
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
50 return os.path.join(Utilities.getConfigDir(), "browser", "userAgentSettings")
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
51
1596
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 def save(self):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 Public slot to save the user agent entries to disk.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 if not self.__loaded:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 return
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
1621
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
59 agentFile = self.getFileName()
1596
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 try:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 f = open(agentFile, "w", encoding="utf-8")
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 for host, agent in self.__agents.items():
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 f.write("{0}@@{1}\n".format(host, agent))
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 f.close()
1623
6b9654035a7c Added signals to indicate, that the managed data was saved, to some web browser managers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1621
diff changeset
65 self.userAgentSettingsSaved.emit()
1596
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 except IOError as err:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 E5MessageBox.critical(None,
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.trUtf8("Saving user agent data"),
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.trUtf8("""<p>User agent data could not be saved to <b>{0}</b></p>"""
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 """<p>Reason: {1}</p>""").format(agentFile, str(err)))
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 return
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def __load(self):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 Private method to load the saved user agent settings.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
1621
85653d5d3bf9 Extended some web browser manager objects to provide a method to get the name of their config file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1596
diff changeset
77 agentFile = self.getFileName()
1596
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 if os.path.exists(agentFile):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 try:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 f = open(agentFile, "r", encoding="utf-8")
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 lines = f.read()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 f.close()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 except IOError as err:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 E5MessageBox.critical(None,
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.trUtf8("Loading user agent data"),
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.trUtf8("""<p>User agent data could not be loaded """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 """from <b>{0}</b></p>"""
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 """<p>Reason: {1}</p>""")\
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 .format(agentFile, str(err)))
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 return
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 for line in lines.splitlines():
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 if not line or \
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 line.startswith("#") or \
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 "@@" not in line:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 continue
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 host, agent = line.split("@@", 1)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 self.__agents[host] = agent
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.__loaded = True
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 def close(self):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 Public method to close the user agents manager.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 self.__saveTimer.saveIfNeccessary()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 def removeUserAgent(self, host):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 Public method to remove a user agent entry.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 @param host host name (string)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 if host in self.__agents:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 del self.__agents[host]
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 self.changed.emit()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 def allHostNames(self):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 Public method to get a list of all host names we a user agent setting for.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 @return sorted list of all host names (list of strings)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 if not self.__loaded:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.__load()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 return sorted(self.__agents.keys())
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 def hostsCount(self):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 Public method to get the number of available user agent settings.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 @return number of user agent settings (integer)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 if not self.__loaded:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 self.__load()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 return len(self.__agents)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 def userAgent(self, host):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 Public method to get the user agent setting for a host.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 @param host host name (string)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 @return user agent string (string)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 if not self.__loaded:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.__load()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 if host not in self.__agents:
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 return ""
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 return self.__agents[host]
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 def setUserAgent(self, host, agent):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 Public method to set the user agent string for a host.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 @param host host name (string)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 @param agent user agent string (string)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 if host != "" and agent != "":
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.__agents[host] = agent
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.changed.emit()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 def userAgentForUrl(self, url):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 Publci method to determine the user agent for the given URL.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 @param url URL to determine user agent for (QUrl)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 @return user agent string (string)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 if url.isValid():
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 host = url.host()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 return self.userAgent(host)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 return ""
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 def setUserAgentForUrl(self, url, agent):
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 Public method to set the user agent string for an URL.
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 @param url URL to register user agent setting for (QUrl)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 @param agent new current user agent string (string)
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 if url.isValid():
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 host = url.host()
8d59e4f3c828 Extended the User Agent handling to be able to set the string on a host basis (next to the global user agent string).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 self.setUserAgent(host, agent)

eric ide

mercurial