--- a/src/eric7/WebBrowser/Bookmarks/BookmarksImporters/SafariImporter.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/WebBrowser/Bookmarks/BookmarksImporters/SafariImporter.py Wed Jul 13 14:55:47 2022 +0200 @@ -21,7 +21,7 @@ def getImporterInfo(sourceId): """ Module function to get information for the given source id. - + @param sourceId id of the browser ("chrome" or "chromium") @return tuple with an icon (QPixmap), readable name (string), name of the default bookmarks file (string), an info text (string), @@ -30,12 +30,10 @@ @exception ValueError raised to indicate an invalid browser ID """ if sourceId != "safari": - raise ValueError( - "Unsupported browser ID given ({0}).".format(sourceId)) - + raise ValueError("Unsupported browser ID given ({0}).".format(sourceId)) + if Globals.isWindowsPlatform(): - standardDir = os.path.expandvars( - "%APPDATA%\\Apple Computer\\Safari") + standardDir = os.path.expandvars("%APPDATA%\\Apple Computer\\Safari") elif Globals.isMacPlatform(): standardDir = os.path.expanduser("~/Library/Safari") else: @@ -48,10 +46,11 @@ "SafariImporter", """Apple Safari stores its bookmarks in the""" """ <b>Bookmarks.plist</b> file. This file is usually""" - """ located in"""), + """ located in""", + ), QCoreApplication.translate( - "SafariImporter", - """Please choose the file to begin importing bookmarks."""), + "SafariImporter", """Please choose the file to begin importing bookmarks.""" + ), standardDir, ) @@ -60,43 +59,44 @@ """ Class implementing the Apple Safari bookmarks importer. """ + def __init__(self, sourceId="", parent=None): """ Constructor - + @param sourceId source ID (string) @param parent reference to the parent object (QObject) """ super().__init__(sourceId, parent) - + self.__fileName = "" - + def setPath(self, path): """ Public method to set the path of the bookmarks file or directory. - + @param path bookmarks file or directory (string) """ self.__fileName = path - + def open(self): """ Public method to open the bookmarks file. - + @return flag indicating success (boolean) """ if not os.path.exists(self.__fileName): self._error = True - self._errorString = self.tr( - "File '{0}' does not exist." - ).format(self.__fileName) + self._errorString = self.tr("File '{0}' does not exist.").format( + self.__fileName + ) return False return True - + def importedBookmarks(self): """ Public method to get the imported bookmarks. - + @return imported bookmarks (BookmarkNode) """ try: @@ -105,34 +105,36 @@ except (plistlib.InvalidFileException, OSError) as err: self._error = True self._errorString = self.tr( - "Bookmarks file cannot be read.\nReason: {0}".format(str(err))) + "Bookmarks file cannot be read.\nReason: {0}".format(str(err)) + ) return None - + from ..BookmarkNode import BookmarkNode + importRootNode = BookmarkNode(BookmarkNode.Folder) if ( - bookmarksDict["WebBookmarkFileVersion"] == 1 and - bookmarksDict["WebBookmarkType"] == "WebBookmarkTypeList" + bookmarksDict["WebBookmarkFileVersion"] == 1 + and bookmarksDict["WebBookmarkType"] == "WebBookmarkTypeList" ): self.__processChildren(bookmarksDict["Children"], importRootNode) - + if self._id == "safari": importRootNode.title = self.tr("Apple Safari Import") else: - importRootNode.title = self.tr( - "Imported {0}" - ).format(QDate.currentDate().toString( - Qt.DateFormat.SystemLocaleShortDate)) + importRootNode.title = self.tr("Imported {0}").format( + QDate.currentDate().toString(Qt.DateFormat.SystemLocaleShortDate) + ) return importRootNode - + def __processChildren(self, children, rootNode): """ Private method to process the list of children. - + @param children list of child nodes to be processed (list of dict) @param rootNode node to add the bookmarks to (BookmarkNode) """ from ..BookmarkNode import BookmarkNode + for child in children: if child["WebBookmarkType"] == "WebBookmarkTypeList": folder = BookmarkNode(BookmarkNode.Folder, rootNode) @@ -143,9 +145,7 @@ url = child["URLString"] if url.startswith(("place:", "about:")): continue - + bookmark = BookmarkNode(BookmarkNode.Bookmark, rootNode) bookmark.url = url - bookmark.title = ( - child["URIDictionary"]["title"].replace("&", "&&") - ) + bookmark.title = child["URIDictionary"]["title"].replace("&", "&&")