242 """ |
242 """ |
243 return ( |
243 return ( |
244 self.__fairUse and |
244 self.__fairUse and |
245 QDateTime.currentDateTime() >= self.__nextRequestNoSoonerThan |
245 QDateTime.currentDateTime() >= self.__nextRequestNoSoonerThan |
246 ) or not self.__fairUse |
246 ) or not self.__fairUse |
|
247 |
|
248 def getFairUseDelayExpirationDateTime(self): |
|
249 """ |
|
250 Public method to get the date and time the fair use delay will expire. |
|
251 |
|
252 @return fair use delay expiration date and time |
|
253 @rtype QDateTime |
|
254 """ |
|
255 return self.__nextRequestNoSoonerThan |
|
256 |
|
257 @classmethod |
|
258 def getThreatMessage(cls, threatType): |
|
259 """ |
|
260 Class method to get a warning message for the given threat type. |
|
261 |
|
262 @param threatType threat type to get the message for |
|
263 @type str |
|
264 @return threat message |
|
265 @rtype str |
|
266 """ |
|
267 threatType = threatType.lower() |
|
268 if threatType == "malware": |
|
269 msg = QCoreApplication.translate( |
|
270 "SafeBrowsingAPI", |
|
271 "<h3>Malware Warning</h3>" |
|
272 "<p>The web site you are about to visit may try to install" |
|
273 " harmful programs on your computer in order to steal or" |
|
274 " destroy your data.</p>") |
|
275 elif threatType == "social_engineering": |
|
276 msg = QCoreApplication.translate( |
|
277 "SafeBrowsingAPI", |
|
278 "<h3>Phishing Warning</h3>" |
|
279 "<p>The web site you are about to visit may try to trick you" |
|
280 " into doing something dangerous online, such as revealing" |
|
281 " passwords or personal information, usually through a fake" |
|
282 " website.</p>") |
|
283 elif threatType == "unwanted_software": |
|
284 msg = QCoreApplication.translate( |
|
285 "SafeBrowsingAPI", |
|
286 "<h3>Unwanted Software Warning</h3>" |
|
287 "<p>The software you are about to download may negatively" |
|
288 " affect your browsing or computing experience.</p>") |
|
289 elif threatType == "potentially_harmful_application": |
|
290 msg = QCoreApplication.translate( |
|
291 "SafeBrowsingAPI", |
|
292 "<h3>Potentially Harmful Application</h3>" |
|
293 "<p>The web site you are about to visit may try to trick you" |
|
294 " into installing applications, that may negatively affect" |
|
295 " your browsing experience.</p>") |
|
296 else: |
|
297 # unknow threat |
|
298 msg = QCoreApplication.translate( |
|
299 "SafeBrowsingAPI", |
|
300 "<h3>Unknown Threat Warning</h3>" |
|
301 "<p>The web site you are about to visit was found in the Safe" |
|
302 " Browsing Database but was not classified yet.</p>") |
|
303 |
|
304 return msg |
|
305 |
|
306 @classmethod |
|
307 def getThreatType(cls, threatType): |
|
308 """ |
|
309 Class method to get a display string for a given threat type. |
|
310 |
|
311 @param threatType threat type to get display string for |
|
312 @type str |
|
313 @return display string |
|
314 @rtype str |
|
315 """ |
|
316 threatType = threatType.lower() |
|
317 if threatType == "malware": |
|
318 displayString = QCoreApplication.translate( |
|
319 "SafeBrowsingAPI", "Malware") |
|
320 elif threatType == "social_engineering": |
|
321 displayString = QCoreApplication.translate( |
|
322 "SafeBrowsingAPI", "Phishing") |
|
323 elif threatType == "unwanted_software": |
|
324 displayString = QCoreApplication.translate( |
|
325 "SafeBrowsingAPI", "Unwanted Software") |
|
326 elif threatType == "potentially_harmful_application": |
|
327 displayString = QCoreApplication.translate( |
|
328 "SafeBrowsingAPI", "Harmful Application") |
|
329 elif threatType == "malcious_binary": |
|
330 displayString = QCoreApplication.translate( |
|
331 "SafeBrowsingAPI", "Malicious Binary") |
|
332 else: |
|
333 displayString = QCoreApplication.translate( |
|
334 "SafeBrowsingAPI", "Unknown Threat") |
|
335 |
|
336 return displayString |
|
337 |
|
338 @classmethod |
|
339 def getPlatformString(cls, platformType): |
|
340 """ |
|
341 Class method to get the platform string for a given platform type. |
|
342 |
|
343 @param platformType platform type as defined in the v4 API |
|
344 @type str |
|
345 @return platform string |
|
346 @rtype str |
|
347 """ |
|
348 platformStrings = { |
|
349 "WINDOWS": "Windows", |
|
350 "LINUX": "Linux", |
|
351 "ANDROID": "Android", |
|
352 "OSX": "macOS", |
|
353 "IOS": "iOS", |
|
354 "CHROME": "Chrome OS", |
|
355 } |
|
356 if platformType in platformStrings: |
|
357 return platformStrings[platformType] |
|
358 |
|
359 if platformType == "ANY_PLATFORM": |
|
360 return QCoreApplication.translate( |
|
361 "SafeBrowsingAPI", "any defined platform") |
|
362 elif platformType == "ALL_PLATFORMS": |
|
363 return QCoreApplication.translate( |
|
364 "SafeBrowsingAPI", "all defined platforms") |
|
365 else: |
|
366 return QCoreApplication.translate( |
|
367 "SafeBrowsingAPI", "unknown platform") |
|
368 |
|
369 @classmethod |
|
370 def getThreatEntryString(cls, threatEntry): |
|
371 """ |
|
372 Class method to get the threat entry string. |
|
373 |
|
374 @param threatEntry threat entry type as defined in the v4 API |
|
375 @type str |
|
376 @return threat entry string |
|
377 @rtype str |
|
378 """ |
|
379 if threatEntry == "URL": |
|
380 return "URL" |
|
381 elif threatEntry == "EXECUTABLE": |
|
382 return QCoreApplication.translate( |
|
383 "SafeBrowsingAPI", "executable program") |
|
384 else: |
|
385 return QCoreApplication.translate( |
|
386 "SafeBrowsingAPI", "unknown type") |
|
387 |
|
388 @classmethod |
|
389 def getPlatformTypes(cls, platform): |
|
390 """ |
|
391 Class method to get the platform types for a given platform. |
|
392 |
|
393 @param platform platform string |
|
394 @type str (one of 'linux', 'windows', 'macos') |
|
395 @return list of platform types as defined in the v4 API for the |
|
396 given platform |
|
397 @rtype list of str |
|
398 @exception ValueError raised to indicate an invalid platform string |
|
399 """ |
|
400 platform = platform.lower() |
|
401 |
|
402 platformTypes = ["ANY_PLATFORM", "ALL_PLATFORMS"] |
|
403 if platform == "linux": |
|
404 platformTypes.append("LINUX") |
|
405 elif platform == "windows": |
|
406 platformTypes.append("WINDOWS") |
|
407 elif platform == "macos": |
|
408 platformTypes.append("OSX") |
|
409 else: |
|
410 raise ValueError("Unsupported platform") |
|
411 |
|
412 return platformTypes |