Web Browser NG, Safe Browsing: refactored the code to prepare the implementation of the Lookup API (v4)

Tue, 10 Apr 2018 19:39:13 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 10 Apr 2018 19:39:13 +0200
changeset 6229
72b40274a3b6
parent 6228
9c3fbf39ec9b
child 6230
77a1b22c8a1f

Web Browser NG, Safe Browsing: refactored the code to prepare the implementation of the Lookup API (v4)

WebBrowser/SafeBrowsing/SafeBrowsingCache.py file | annotate | diff | comparison | revisions
WebBrowser/SafeBrowsing/SafeBrowsingManager.py file | annotate | diff | comparison | revisions
WebBrowser/SafeBrowsing/SafeBrowsingThreatList.py file | annotate | diff | comparison | revisions
--- a/WebBrowser/SafeBrowsing/SafeBrowsingCache.py	Mon Apr 09 19:47:16 2018 +0200
+++ b/WebBrowser/SafeBrowsing/SafeBrowsingCache.py	Tue Apr 10 19:39:13 2018 +0200
@@ -23,97 +23,7 @@
 from PyQt5.QtSql import QSql, QSqlDatabase, QSqlQuery
 
 from .SafeBrowsingUtilities import toHex
-
-
-class ThreatList(object):
-    """
-    Class implementing the threat list info.
-    """
-    def __init__(self, threatType, platformType, threatEntryType):
-        """
-        Constructor
-        
-        @param threatType threat type
-        @type str
-        @param platformType platform type
-        @type str
-        @param threatEntryType threat entry type
-        @type str
-        """
-        self.threatType = threatType
-        self.platformType = platformType
-        self.threatEntryType = threatEntryType
-
-    @classmethod
-    def fromApiEntry(cls, entry):
-        """
-        Class method to instantiate a threat list given a threat list entry
-        dictionary.
-        
-        @param entry threat list entry dictionary
-        @type dict
-        @return instantiated object
-        @rtype ThreatList
-        """
-        return cls(entry['threatType'], entry['platformType'],
-                   entry['threatEntryType'])
-
-    def asTuple(self):
-        """
-        Public method to convert the object to a tuple.
-        
-        @return tuple containing the threat list info
-        @rtype tuple of (str, str, str)
-        """
-        return (self.threatType, self.platformType, self.threatEntryType)
-
-    def __repr__(self):
-        """
-        Special method to generate a printable representation.
-        
-        @return printable representation
-        @rtype str
-        """
-        return '/'.join(self.asTuple())
-
-
-class HashPrefixList(object):
-    """
-    Class implementing a container for threat list data.
-    """
-    def __init__(self, prefixLength, rawHashes):
-        """
-        Constructor
-        
-        @param prefixLength length of each hash prefix
-        @type int
-        @param rawHashes raw hash prefixes of given length concatenated and
-            sorted in lexicographical order
-        @type str
-        """
-        self.__prefixLength = prefixLength
-        self.__rawHashes = rawHashes
-    
-    def __len__(self):
-        """
-        Special method to calculate the number of entries.
-        
-        @return length
-        @rtype int
-        """
-        return len(self.__rawHashes) // self.__prefixLength
-    
-    def __iter__(self):
-        """
-        Special method to iterate over the raw hashes.
-        
-        @return iterator object
-        @rtype iterator
-        """
-        n = self.__prefixLength
-        return (self.__rawHashes[index:index + n]
-                for index in range(0, len(self.__rawHashes), n)
-                )
+from .SafeBrowsingThreatList import ThreatList
 
 
 class SafeBrowsingCache(QObject):
--- a/WebBrowser/SafeBrowsing/SafeBrowsingManager.py	Mon Apr 09 19:47:16 2018 +0200
+++ b/WebBrowser/SafeBrowsing/SafeBrowsingManager.py	Tue Apr 10 19:39:13 2018 +0200
@@ -28,7 +28,8 @@
 import UI.PixmapCache
 
 from .SafeBrowsingAPIClient import SafeBrowsingAPIClient
-from .SafeBrowsingCache import SafeBrowsingCache, ThreatList, HashPrefixList
+from .SafeBrowsingCache import SafeBrowsingCache
+from .SafeBrowsingThreatList import ThreatList, HashPrefixList
 from .SafeBrowsingUrl import SafeBrowsingUrl
 from .SafeBrowsingUtilities import toHex
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebBrowser/SafeBrowsing/SafeBrowsingThreatList.py	Tue Apr 10 19:39:13 2018 +0200
@@ -0,0 +1,101 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2018 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the threat list info class.
+"""
+
+from __future__ import unicode_literals, division
+
+
+class ThreatList(object):
+    """
+    Class implementing the threat list info.
+    """
+    def __init__(self, threatType, platformType, threatEntryType):
+        """
+        Constructor
+        
+        @param threatType threat type
+        @type str
+        @param platformType platform type
+        @type str
+        @param threatEntryType threat entry type
+        @type str
+        """
+        self.threatType = threatType
+        self.platformType = platformType
+        self.threatEntryType = threatEntryType
+
+    @classmethod
+    def fromApiEntry(cls, entry):
+        """
+        Class method to instantiate a threat list given a threat list entry
+        dictionary.
+        
+        @param entry threat list entry dictionary
+        @type dict
+        @return instantiated object
+        @rtype ThreatList
+        """
+        return cls(entry['threatType'], entry['platformType'],
+                   entry['threatEntryType'])
+
+    def asTuple(self):
+        """
+        Public method to convert the object to a tuple.
+        
+        @return tuple containing the threat list info
+        @rtype tuple of (str, str, str)
+        """
+        return (self.threatType, self.platformType, self.threatEntryType)
+
+    def __repr__(self):
+        """
+        Special method to generate a printable representation.
+        
+        @return printable representation
+        @rtype str
+        """
+        return '/'.join(self.asTuple())
+
+
+class HashPrefixList(object):
+    """
+    Class implementing a container for threat list data.
+    """
+    def __init__(self, prefixLength, rawHashes):
+        """
+        Constructor
+        
+        @param prefixLength length of each hash prefix
+        @type int
+        @param rawHashes raw hash prefixes of given length concatenated and
+            sorted in lexicographical order
+        @type str
+        """
+        self.__prefixLength = prefixLength
+        self.__rawHashes = rawHashes
+    
+    def __len__(self):
+        """
+        Special method to calculate the number of entries.
+        
+        @return length
+        @rtype int
+        """
+        return len(self.__rawHashes) // self.__prefixLength
+    
+    def __iter__(self):
+        """
+        Special method to iterate over the raw hashes.
+        
+        @return iterator object
+        @rtype iterator
+        """
+        n = self.__prefixLength
+        return (self.__rawHashes[index:index + n]
+                for index in range(0, len(self.__rawHashes), n)
+                )

eric ide

mercurial