96 def __load(self): |
96 def __load(self): |
97 """ |
97 """ |
98 Private method to load the registered protocol handlers. |
98 Private method to load the registered protocol handlers. |
99 """ |
99 """ |
100 try: |
100 try: |
101 protocolHandlersFile = open(self.__protocolHandlersFileName(), "r") |
101 with open(self.__protocolHandlersFileName(), |
102 protocolHandlersData = json.load(protocolHandlersFile) |
102 "r") as protocolHandlersFile: |
103 protocolHandlersFile.close() |
103 protocolHandlersData = json.load(protocolHandlersFile) |
104 |
104 |
105 if protocolHandlersData: |
105 if protocolHandlersData: |
106 self.__protocolHandlers = {} |
106 self.__protocolHandlers = {} |
107 for scheme, urlStr in protocolHandlersData.items(): |
107 for scheme, urlStr in protocolHandlersData.items(): |
108 url = QUrl(urlStr) |
108 url = QUrl(urlStr) |
117 Private method to save the protocol handlers. |
117 Private method to save the protocol handlers. |
118 """ |
118 """ |
119 protocolHandlers = {scheme: url.toString() |
119 protocolHandlers = {scheme: url.toString() |
120 for scheme, url in self.__protocolHandlers.items()} |
120 for scheme, url in self.__protocolHandlers.items()} |
121 |
121 |
122 protocolHandlersFile = open(self.__protocolHandlersFileName(), "w") |
122 with open(self.__protocolHandlersFileName(), |
123 json.dump(protocolHandlers, protocolHandlersFile, indent=2) |
123 "w") as protocolHandlersFile: |
124 protocolHandlersFile.close() |
124 json.dump(protocolHandlers, protocolHandlersFile, indent=2) |
125 |
125 |
126 def __registerHandler(self, scheme, url): |
126 def __registerHandler(self, scheme, url): |
127 """ |
127 """ |
128 Private method to register a protocol handler for a scheme. |
128 Private method to register a protocol handler for a scheme. |
129 |
129 |