src/eric7/WebBrowser/CookieJar/CookieExceptionsModel.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
--- a/src/eric7/WebBrowser/CookieJar/CookieExceptionsModel.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/WebBrowser/CookieJar/CookieExceptionsModel.py	Wed Jul 13 14:55:47 2022 +0200
@@ -15,29 +15,30 @@
     """
     Class implementing the cookie exceptions model.
     """
+
     def __init__(self, cookieJar, parent=None):
         """
         Constructor
-        
+
         @param cookieJar reference to the cookie jar (CookieJar)
         @param parent reference to the parent object (QObject)
         """
         super().__init__(parent)
-        
+
         self.__cookieJar = cookieJar
         self.__allowedCookies = self.__cookieJar.allowedCookies()
         self.__blockedCookies = self.__cookieJar.blockedCookies()
         self.__sessionCookies = self.__cookieJar.allowForSessionCookies()
-        
+
         self.__headers = [
             self.tr("Website"),
             self.tr("Status"),
         ]
-    
+
     def headerData(self, section, orientation, role):
         """
         Public method to get header data from the model.
-        
+
         @param section section number (integer)
         @param orientation orientation (Qt.Orientation)
         @param role role of the data to retrieve (Qt.ItemDataRole)
@@ -48,36 +49,36 @@
             height = fm.height() + fm.height() // 3
             try:
                 width = fm.horizontalAdvance(
-                    self.headerData(section, orientation,
-                                    Qt.ItemDataRole.DisplayRole))
+                    self.headerData(section, orientation, Qt.ItemDataRole.DisplayRole)
+                )
             except AttributeError:
                 width = fm.width(
-                    self.headerData(section, orientation,
-                                    Qt.ItemDataRole.DisplayRole))
+                    self.headerData(section, orientation, Qt.ItemDataRole.DisplayRole)
+                )
             return QSize(width, height)
-        
+
         if (
-            orientation == Qt.Orientation.Horizontal and
-            role == Qt.ItemDataRole.DisplayRole
+            orientation == Qt.Orientation.Horizontal
+            and role == Qt.ItemDataRole.DisplayRole
         ):
             try:
                 return self.__headers[section]
             except IndexError:
                 return None
-        
+
         return QAbstractTableModel.headerData(self, section, orientation, role)
-    
+
     def data(self, index, role):
         """
         Public method to get data from the model.
-        
+
         @param index index to get data for (QModelIndex)
         @param role role of the data to retrieve (integer)
         @return requested data
         """
         if index.row() < 0 or index.row() >= self.rowCount():
             return None
-        
+
         if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole):
             row = index.row()
             if row < len(self.__allowedCookies):
@@ -87,7 +88,7 @@
                     return self.tr("Allow")
                 else:
                     return None
-            
+
             row -= len(self.__allowedCookies)
             if row < len(self.__blockedCookies):
                 if index.column() == 0:
@@ -96,7 +97,7 @@
                     return self.tr("Block")
                 else:
                     return None
-            
+
             row -= len(self.__blockedCookies)
             if row < len(self.__sessionCookies):
                 if index.column() == 0:
@@ -105,49 +106,49 @@
                     return self.tr("Allow For Session")
                 else:
                     return None
-            
+
             return None
-        
+
         return None
-    
+
     def columnCount(self, parent=None):
         """
         Public method to get the number of columns of the model.
-        
+
         @param parent parent index (QModelIndex)
         @return number of columns (integer)
         """
         if parent is None:
             parent = QModelIndex()
-        
+
         if parent.isValid():
             return 0
         else:
             return len(self.__headers)
-    
+
     def rowCount(self, parent=None):
         """
         Public method to get the number of rows of the model.
-        
+
         @param parent parent index (QModelIndex)
         @return number of rows (integer)
         """
         if parent is None:
             parent = QModelIndex()
-        
+
         if parent.isValid() or self.__cookieJar is None:
             return 0
         else:
             return (
-                len(self.__allowedCookies) +
-                len(self.__blockedCookies) +
-                len(self.__sessionCookies)
+                len(self.__allowedCookies)
+                + len(self.__blockedCookies)
+                + len(self.__sessionCookies)
             )
-    
+
     def removeRows(self, row, count, parent=None):
         """
         Public method to remove entries from the model.
-        
+
         @param row start row (integer)
         @param count number of rows to remove (integer)
         @param parent parent index (QModelIndex)
@@ -155,69 +156,78 @@
         """
         if parent is None:
             parent = QModelIndex()
-        
+
         if parent.isValid() or self.__cookieJar is None:
             return False
-        
+
         lastRow = row + count - 1
         self.beginRemoveRows(parent, row, lastRow)
         for i in range(lastRow, row - 1, -1):
             rowToRemove = i
-            
+
             if rowToRemove < len(self.__allowedCookies):
                 del self.__allowedCookies[rowToRemove]
                 continue
-            
+
             rowToRemove -= len(self.__allowedCookies)
             if rowToRemove < len(self.__blockedCookies):
                 del self.__blockedCookies[rowToRemove]
                 continue
-            
+
             rowToRemove -= len(self.__blockedCookies)
             if rowToRemove < len(self.__sessionCookies):
                 del self.__sessionCookies[rowToRemove]
                 continue
-        
+
         self.__cookieJar.setAllowedCookies(self.__allowedCookies)
         self.__cookieJar.setBlockedCookies(self.__blockedCookies)
         self.__cookieJar.setAllowForSessionCookies(self.__sessionCookies)
         self.endRemoveRows()
-        
+
         return True
-    
+
     def addRule(self, host, rule):
         """
         Public method to add an exception rule.
-        
+
         @param host name of the host to add a rule for (string)
         @param rule type of rule to add (CookieJar.Allow, CookieJar.Block or
             CookieJar.AllowForSession)
         """
         if not host:
             return
-        
+
         from .CookieJar import CookieJar
-        
+
         if rule == CookieJar.Allow:
             self.__addHost(
-                host, self.__allowedCookies, self.__blockedCookies,
-                self.__sessionCookies)
+                host,
+                self.__allowedCookies,
+                self.__blockedCookies,
+                self.__sessionCookies,
+            )
             return
         elif rule == CookieJar.Block:
             self.__addHost(
-                host, self.__blockedCookies, self.__allowedCookies,
-                self.__sessionCookies)
+                host,
+                self.__blockedCookies,
+                self.__allowedCookies,
+                self.__sessionCookies,
+            )
             return
         elif rule == CookieJar.AllowForSession:
             self.__addHost(
-                host, self.__sessionCookies, self.__allowedCookies,
-                self.__blockedCookies)
+                host,
+                self.__sessionCookies,
+                self.__allowedCookies,
+                self.__blockedCookies,
+            )
             return
-    
+
     def __addHost(self, host, addList, removeList1, removeList2):
         """
         Private method to add a host to an exception list.
-        
+
         @param host name of the host to add (string)
         @param addList reference to the list to add it to (list of strings)
         @param removeList1 reference to first list to remove it from
@@ -231,20 +241,20 @@
                 removeList1.remove(host)
             if host in removeList2:
                 removeList2.remove(host)
-        
+
         # Avoid to have similar rules (with or without leading dot)
         # e.g. python-projects.org and .python-projects.org
-        otherRule = host[1:] if host.startswith(".") else '.' + host
+        otherRule = host[1:] if host.startswith(".") else "." + host
         if otherRule in addList:
             addList.remove(otherRule)
         if otherRule in removeList1:
             removeList1.remove(otherRule)
         if otherRule in removeList2:
             removeList2.remove(otherRule)
-        
+
         self.__cookieJar.setAllowedCookies(self.__allowedCookies)
         self.__cookieJar.setBlockedCookies(self.__blockedCookies)
         self.__cookieJar.setAllowForSessionCookies(self.__sessionCookies)
-        
+
         self.beginResetModel()
         self.endResetModel()

eric ide

mercurial