WebBrowser/SafeBrowsing/SafeBrowsingAPIClient.py

Fri, 04 Aug 2017 19:40:48 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 04 Aug 2017 19:40:48 +0200
changeset 5831
536d97e3f1a1
parent 5829
d3448873ced3
child 5832
28f36b9c925f
permissions
-rw-r--r--

Updated translations.

5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2017 Detlev Offenbach <detlev@die-offenbachs.de>
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the low level interface for Google Safe Browsing.
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from __future__ import unicode_literals
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 try:
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 str = unicode # __IGNORE_EXCEPTION__
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 except NameError:
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 pass
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import json
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
17 import base64
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
19 from PyQt5.QtCore import pyqtSignal, QObject, QDateTime, QUrl, QByteArray, \
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
20 QCoreApplication, QEventLoop
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 from WebBrowser.WebBrowserWindow import WebBrowserWindow
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 class SafeBrowsingAPIClient(QObject):
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 Class implementing the low level interface for Google Safe Browsing.
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
29
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
30 @signal networkError(str) emitted to indicate a network error
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 ClientId = "eric6_API_client"
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 ClientVersion = "1.0.0"
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 GsbUrlTemplate = "https://safebrowsing.googleapis.com/v4/{0}?key={1}"
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 networkError = pyqtSignal(str)
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 def __init__(self, apiKey, fairUse=True, parent=None):
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Constructor
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 @param apiKey API key to be used
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @type str
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 @param fairUse flag indicating to follow the fair use policy
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 @type bool
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 @param parent reference to the parent object
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @type QObject
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.__apiKey = apiKey
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.__fairUse = fairUse
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.__nextRequestNoSoonerThan = QDateTime()
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__failCount = 0
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
56 def setApiKey(self, apiKey):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
57 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
58 Public method to set the API key.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
59
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
60 @param apiKey API key to be set
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
61 @type str
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
62 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
63 self.__apiKey = apiKey
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
64
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 def getThreatLists(self):
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Public method to retrieve all available threat lists.
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
68
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
69 @return list of threat lists
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
70 @rtype list of dict containing 'threatType', 'platformType' and
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
71 'threatEntryType'
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 url = QUrl(self.GsbUrlTemplate.format("threatLists", self.__apiKey))
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 req = QNetworkRequest(url)
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 reply = WebBrowserWindow.networkManager().get(req)
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
76
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
77 while reply.isRunning():
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
78 QCoreApplication.processEvents(QEventLoop.AllEvents, 200)
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
79 # max. 200 ms processing
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
80
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
81 res = None
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
82 if reply.error() != QNetworkReply.NoError:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
83 self.networkError.emit(reply.errorString())
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
84 else:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
85 result = self.__extractData(reply)
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
86 res = result["threatLists"]
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
87
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
88 reply.deleteLater()
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
89 return res
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
91 def getThreatsUpdate(self, clientStates):
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
92 """
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
93 Public method to fetch hash prefix updates for the given threat list.
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
94
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
95 @param clientStates dictionary of client states with keys like
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
96 (threatType, platformType, threatEntryType)
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
97 @type dict
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
98 @return list of threat updates
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
99 @rtype list of dict
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
100 """
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
101 requestBody = {
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
102 "client": {
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
103 "clientId": self.ClientId,
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
104 "clientVersion": self.ClientVersion,
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
105 },
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
106 "listUpdateRequests": [],
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
107 }
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
108
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
109 for (threatType, platformType, threatEntryType), currentState in \
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
110 clientStates.items():
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
111 requestBody["listUpdateRequests"].append(
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
112 {
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
113 "threatType": threatType,
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
114 "platformType": platformType,
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
115 "threatEntryType": threatEntryType,
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
116 "state": currentState,
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
117 "constraints": {
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
118 "supportedCompressions": ["RAW"],
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
119 }
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
120 }
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
121 )
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
122
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
123 data = QByteArray(json.dumps(requestBody).encode("utf-8"))
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
124 url = QUrl(self.GsbUrlTemplate.format("threatListUpdates:fetch",
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
125 self.__apiKey))
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
126 req = QNetworkRequest(url)
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
127 req.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
128 reply = WebBrowserWindow.networkManager().post(req, data)
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
129
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
130 while reply.isRunning():
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
131 QCoreApplication.processEvents(QEventLoop.AllEvents, 200)
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
132 # max. 200 ms processing
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
133
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
134 res = None
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
135 if reply.error() != QNetworkReply.NoError:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
136 self.networkError.emit(reply.errorString())
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
137 else:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
138 result = self.__extractData(reply)
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
139 res = result["listUpdateResponses"]
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
140
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
141 reply.deleteLater()
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
142 return res
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
143
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
144 def getFullHashes(self, prefixes, clientState):
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
145 """
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
146 Public method to find full hashes matching hash prefixes.
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
147
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
148 @param prefixes list of hash prefixes to find
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
149 @type list of str (Python 2) or list of bytes (Python 3)
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
150 @param clientState dictionary of client states with keys like
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
151 (threatType, platformType, threatEntryType)
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
152 @type dict
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
153 @return dictionary containing the list of found hashes and the
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
154 negative cache duration
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
155 @rtype dict
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
156 """
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
157 requestBody = {
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
158 "client": {
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
159 "clientId": self.ClientId,
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
160 "clientVersion": self.ClientVersion,
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
161 },
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
162 "clientStates": [],
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
163 "threatInfo": {
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
164 "threatTypes": [],
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
165 "platformTypes": [],
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
166 "threatEntryTypes": [],
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
167 "threatEntries": [],
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
168 },
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
169 }
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
171 for prefix in prefixes:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
172 requestBody["threatInfo"]["threatEntries"].append(
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
173 {"hash": base64.b64encode(prefix).decode("ascii")})
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
174
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
175 for (threatType, platformType, threatEntryType), currentState in \
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
176 clientState.items():
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
177 requestBody["clientStates"].append(currentState)
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
178 if threatType not in requestBody["threatInfo"]["threatTypes"]:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
179 requestBody["threatInfo"]["threatTypes"].append(threatType)
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
180 if platformType not in \
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
181 requestBody["threatInfo"]["platformTypes"]:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
182 requestBody["threatInfo"]["platformTypes"].append(
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
183 platformType)
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
184 if threatEntryType not in \
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
185 requestBody["threatInfo"]["threatEntryTypes"]:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
186 requestBody["threatInfo"]["threatEntryTypes"].append(
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
187 threatEntryType)
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
188
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
189 data = QByteArray(json.dumps(requestBody).encode("utf-8"))
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
190 url = QUrl(self.GsbUrlTemplate.format("fullHashes:find",
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
191 self.__apiKey))
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
192 req = QNetworkRequest(url)
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
193 req.setHeader(QNetworkRequest.ContentTypeHeader, "application/json")
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
194 reply = WebBrowserWindow.networkManager().post(req, data)
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
195
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
196 while reply.isRunning():
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
197 QCoreApplication.processEvents(QEventLoop.AllEvents, 200)
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
198 # max. 200 ms processing
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
199
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
200 res = None
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
201 if reply.error() != QNetworkReply.NoError:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
202 self.networkError.emit(reply.errorString())
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
203 else:
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
204 res = self.__extractData(reply)
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
205
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
206 reply.deleteLater()
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
207 return res
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 def __extractData(self, reply):
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 Private method to extract the data of a network reply.
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 @param reply reference to the network reply object
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 @type QNetworkReply
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
215 @return extracted data
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
216 @type list or dict
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 result = json.loads(str(reply.readAll(), "utf-8"))
5811
5358a3c7995f Done implementing the SafeBrowsingAPIClient class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5809
diff changeset
219 self.__setWaitDuration(result.get("minimumWaitDuration"))
5816
93c74269d59e Changed the SafeBrowsingAPIClient class to work synchroneously.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5811
diff changeset
220 return result
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 def __setWaitDuration(self, minimumWaitDuration):
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 Private method to set the minimum wait duration.
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 @param minimumWaitDuration duration to be set
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 @type str
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 """
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 if not self.__fairUse or minimumWaitDuration is None:
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 self.__nextRequestNoSoonerThan = QDateTime()
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 else:
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
232 waitDuration = int(float(minimumWaitDuration.rstrip("s")))
5809
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 self.__nextRequestNoSoonerThan = \
5b53c17b7d93 Done implementing the SafeBrowsingUrl class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 QDateTime.currentDateTime().addSecs(waitDuration)
5820
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
235
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
236 def fairUseDelayExpired(self):
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
237 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
238 Public method to check, if the fair use wait period has expired.
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
239
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
240 @return flag indicating expiration
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
241 @rtype bool
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
242 """
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
243 return (
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
244 self.__fairUse and
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
245 QDateTime.currentDateTime() >= self.__nextRequestNoSoonerThan
b610cb5b501a Started implementing the safe browsing manager and management dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5816
diff changeset
246 ) or not self.__fairUse
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
247
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
248 def getFairUseDelayExpirationDateTime(self):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
249 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
250 Public method to get the date and time the fair use delay will expire.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
251
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
252 @return fair use delay expiration date and time
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
253 @rtype QDateTime
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
254 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
255 return self.__nextRequestNoSoonerThan
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
256
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
257 @classmethod
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
258 def getThreatMessage(cls, threatType):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
259 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
260 Class method to get a warning message for the given threat type.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
261
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
262 @param threatType threat type to get the message for
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
263 @type str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
264 @return threat message
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
265 @rtype str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
266 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
267 threatType = threatType.lower()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
268 if threatType == "malware":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
269 msg = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
270 "SafeBrowsingAPI",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
271 "<h3>Malware Warning</h3>"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
272 "<p>The web site you are about to visit may try to install"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
273 " harmful programs on your computer in order to steal or"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
274 " destroy your data.</p>")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
275 elif threatType == "social_engineering":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
276 msg = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
277 "SafeBrowsingAPI",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
278 "<h3>Phishing Warning</h3>"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
279 "<p>The web site you are about to visit may try to trick you"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
280 " into doing something dangerous online, such as revealing"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
281 " passwords or personal information, usually through a fake"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
282 " website.</p>")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
283 elif threatType == "unwanted_software":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
284 msg = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
285 "SafeBrowsingAPI",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
286 "<h3>Unwanted Software Warning</h3>"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
287 "<p>The software you are about to download may negatively"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
288 " affect your browsing or computing experience.</p>")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
289 elif threatType == "potentially_harmful_application":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
290 msg = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
291 "SafeBrowsingAPI",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
292 "<h3>Potentially Harmful Application</h3>"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
293 "<p>The web site you are about to visit may try to trick you"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
294 " into installing applications, that may negatively affect"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
295 " your browsing experience.</p>")
5831
536d97e3f1a1 Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
296 elif threatType == "malicious_binary":
536d97e3f1a1 Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
297 msg = QCoreApplication.translate(
536d97e3f1a1 Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
298 "SafeBrowsingAPI",
536d97e3f1a1 Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
299 "<h3>Malicious Binary Warning</h3>"
536d97e3f1a1 Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
300 "<p>The software you are about to download may be harmful"
536d97e3f1a1 Updated translations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5829
diff changeset
301 " to your computer.</p>")
5829
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
302 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
303 # unknow threat
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
304 msg = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
305 "SafeBrowsingAPI",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
306 "<h3>Unknown Threat Warning</h3>"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
307 "<p>The web site you are about to visit was found in the Safe"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
308 " Browsing Database but was not classified yet.</p>")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
309
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
310 return msg
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
311
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
312 @classmethod
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
313 def getThreatType(cls, threatType):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
314 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
315 Class method to get a display string for a given threat type.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
316
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
317 @param threatType threat type to get display string for
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
318 @type str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
319 @return display string
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
320 @rtype str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
321 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
322 threatType = threatType.lower()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
323 if threatType == "malware":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
324 displayString = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
325 "SafeBrowsingAPI", "Malware")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
326 elif threatType == "social_engineering":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
327 displayString = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
328 "SafeBrowsingAPI", "Phishing")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
329 elif threatType == "unwanted_software":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
330 displayString = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
331 "SafeBrowsingAPI", "Unwanted Software")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
332 elif threatType == "potentially_harmful_application":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
333 displayString = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
334 "SafeBrowsingAPI", "Harmful Application")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
335 elif threatType == "malcious_binary":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
336 displayString = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
337 "SafeBrowsingAPI", "Malicious Binary")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
338 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
339 displayString = QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
340 "SafeBrowsingAPI", "Unknown Threat")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
341
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
342 return displayString
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
343
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
344 @classmethod
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
345 def getPlatformString(cls, platformType):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
346 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
347 Class method to get the platform string for a given platform type.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
348
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
349 @param platformType platform type as defined in the v4 API
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
350 @type str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
351 @return platform string
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
352 @rtype str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
353 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
354 platformStrings = {
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
355 "WINDOWS": "Windows",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
356 "LINUX": "Linux",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
357 "ANDROID": "Android",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
358 "OSX": "macOS",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
359 "IOS": "iOS",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
360 "CHROME": "Chrome OS",
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
361 }
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
362 if platformType in platformStrings:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
363 return platformStrings[platformType]
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
364
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
365 if platformType == "ANY_PLATFORM":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
366 return QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
367 "SafeBrowsingAPI", "any defined platform")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
368 elif platformType == "ALL_PLATFORMS":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
369 return QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
370 "SafeBrowsingAPI", "all defined platforms")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
371 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
372 return QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
373 "SafeBrowsingAPI", "unknown platform")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
374
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
375 @classmethod
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
376 def getThreatEntryString(cls, threatEntry):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
377 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
378 Class method to get the threat entry string.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
379
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
380 @param threatEntry threat entry type as defined in the v4 API
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
381 @type str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
382 @return threat entry string
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
383 @rtype str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
384 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
385 if threatEntry == "URL":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
386 return "URL"
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
387 elif threatEntry == "EXECUTABLE":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
388 return QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
389 "SafeBrowsingAPI", "executable program")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
390 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
391 return QCoreApplication.translate(
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
392 "SafeBrowsingAPI", "unknown type")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
393
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
394 @classmethod
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
395 def getPlatformTypes(cls, platform):
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
396 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
397 Class method to get the platform types for a given platform.
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
398
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
399 @param platform platform string
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
400 @type str (one of 'linux', 'windows', 'macos')
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
401 @return list of platform types as defined in the v4 API for the
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
402 given platform
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
403 @rtype list of str
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
404 @exception ValueError raised to indicate an invalid platform string
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
405 """
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
406 platform = platform.lower()
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
407
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
408 platformTypes = ["ANY_PLATFORM", "ALL_PLATFORMS"]
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
409 if platform == "linux":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
410 platformTypes.append("LINUX")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
411 elif platform == "windows":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
412 platformTypes.append("WINDOWS")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
413 elif platform == "macos":
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
414 platformTypes.append("OSX")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
415 else:
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
416 raise ValueError("Unsupported platform")
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
417
d3448873ced3 Finished coding the safe browsing module of the new web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5820
diff changeset
418 return platformTypes

eric ide

mercurial