Helpviewer/FlashCookieManager/FlashCookieManager.py

changeset 4361
9eec3a532d59
parent 4359
ac1dda9f3f19
child 4370
54dbb658f9e6
equal deleted inserted replaced
4360:b8bdb7cd4a92 4361:9eec3a532d59
17 import shutil 17 import shutil
18 18
19 from PyQt5.QtCore import QObject, QTimer, QDir, QFileInfo, QFile 19 from PyQt5.QtCore import QObject, QTimer, QDir, QFileInfo, QFile
20 20
21 from .FlashCookie import FlashCookie 21 from .FlashCookie import FlashCookie
22 from .FlashCookieReader import FlashCookieReader, FlashCookieReaderError
22 23
23 import Helpviewer.HelpWindow 24 import Helpviewer.HelpWindow
24 25
25 import Preferences 26 import Preferences
26 27
257 Private slot to load the Flash cookies from a path. 258 Private slot to load the Flash cookies from a path.
258 259
259 @param path Flash cookies path 260 @param path Flash cookies path
260 @type str 261 @type str
261 """ 262 """
262 if path.endswith(("#SharedObjects", "#AppContainer")): 263 if path.endswith("#AppContainer"):
263 # specific to IE and Windows 264 # specific to IE and Windows
264 return 265 return
265 266
266 path = path.replace("\\", "/") 267 path = path.replace("\\", "/")
267 solDir = QDir(path) 268 solDir = QDir(path)
284 """ 285 """
285 solFile = QFile(path) 286 solFile = QFile(path)
286 if not solFile.open(QFile.ReadOnly): 287 if not solFile.open(QFile.ReadOnly):
287 return 288 return
288 289
289 # TODO: dissect the flash cookie (see gnash s2x.py for example) 290 dataStr = ""
290 data = bytearray(solFile.readAll()) 291 data = bytes(solFile.readAll())
291 for i in range(len(data)): 292 if data:
292 if not ((data[i] >= ord("a") and data[i] <= ord("z")) or 293 try:
293 (data[i] >= ord("A") and data[i] <= ord("Z")) or 294 reader = FlashCookieReader()
294 (data[i] >= ord("0") and data[i] <= ord("9"))): 295 reader.setBytes(data)
295 data[i] = 32 296 reader.parse()
296 dataStr = str(data, "utf-8", "replace") 297 dataStr = reader.toString()
297 dataStr = "\n".join([s for s in dataStr.split(".") if s]) 298 except FlashCookieReaderError as err:
299 dataStr = err.msg
298 300
299 solFileInfo = QFileInfo(solFile) 301 solFileInfo = QFileInfo(solFile)
300 302
301 cookie = FlashCookie() 303 cookie = FlashCookie()
302 cookie.contents = dataStr 304 cookie.contents = dataStr

eric ide

mercurial