60 self.__location = QByteArray() |
60 self.__location = QByteArray() |
61 self.__lastUpdate = QDateTime() |
61 self.__lastUpdate = QDateTime() |
62 self.__requiresLocation = "" |
62 self.__requiresLocation = "" |
63 self.__requiresTitle = "" |
63 self.__requiresTitle = "" |
64 |
64 |
|
65 self.__updatePeriod = 0 # update period in hours, 0 = use default |
|
66 |
65 self.__rules = [] # list containing all AdBlock rules |
67 self.__rules = [] # list containing all AdBlock rules |
66 |
68 |
67 self.__networkExceptionRules = [] |
69 self.__networkExceptionRules = [] |
68 self.__networkBlockRules = [] |
70 self.__networkBlockRules = [] |
69 self.__domainRestrictedCssRules = [] |
71 self.__domainRestrictedCssRules = [] |
71 self.__documentRules = [] |
73 self.__documentRules = [] |
72 self.__elemhideRules = [] |
74 self.__elemhideRules = [] |
73 |
75 |
74 self.__checksumRe = re.compile(r"""^\s*!\s*checksum[\s\-:]+([\w\+\/=]+).*\n""", |
76 self.__checksumRe = re.compile(r"""^\s*!\s*checksum[\s\-:]+([\w\+\/=]+).*\n""", |
75 re.IGNORECASE | re.MULTILINE) |
77 re.IGNORECASE | re.MULTILINE) |
|
78 self.__expiresRe = re.compile( |
|
79 r"""(?:expires:|expires after)\s*(\d+)\s*(hour|h)?""", |
|
80 re.IGNORECASE) |
|
81 |
76 |
82 |
77 |
83 |
78 self.__parseUrl(url) |
84 self.__parseUrl(url) |
79 |
85 |
80 def __parseUrl(self, url): |
86 def __parseUrl(self, url): |
261 self.__rules = [] |
267 self.__rules = [] |
262 self.__rules.append(AdBlockRule(header, self)) |
268 self.__rules.append(AdBlockRule(header, self)) |
263 while not textStream.atEnd(): |
269 while not textStream.atEnd(): |
264 line = textStream.readLine() |
270 line = textStream.readLine() |
265 self.__rules.append(AdBlockRule(line, self)) |
271 self.__rules.append(AdBlockRule(line, self)) |
|
272 expires = self.__expiresRe.search(line) |
|
273 if expires: |
|
274 period, kind = expires.groups() |
|
275 if kind: |
|
276 # hours |
|
277 self.__updatePeriod = int(period) |
|
278 else: |
|
279 # days |
|
280 self.__updatePeriod = int(period) * 24 |
266 self.__populateCache() |
281 self.__populateCache() |
267 self.changed.emit() |
282 self.changed.emit() |
268 elif not fileName.endswith("_custom"): |
283 elif not fileName.endswith("_custom"): |
269 self.__lastUpdate = QDateTime() |
284 self.__lastUpdate = QDateTime() |
270 |
285 |
272 |
287 |
273 def checkForUpdate(self): |
288 def checkForUpdate(self): |
274 """ |
289 """ |
275 Public method to check for an update. |
290 Public method to check for an update. |
276 """ |
291 """ |
|
292 if self.__updatePeriod: |
|
293 updatePeriod = self.__updatePeriod |
|
294 else: |
|
295 updatePeriod = Preferences.getHelp("AdBlockUpdatePeriod") * 24 |
277 if not self.__lastUpdate.isValid() or \ |
296 if not self.__lastUpdate.isValid() or \ |
278 self.__lastUpdate.addDays(Preferences.getHelp("AdBlockUpdatePeriod")) < \ |
297 self.__lastUpdate.addSecs(updatePeriod * 3600) < \ |
279 QDateTime.currentDateTime(): |
298 QDateTime.currentDateTime(): |
280 self.updateNow() |
299 self.updateNow() |
281 |
300 |
282 def updateNow(self): |
301 def updateNow(self): |
283 """ |
302 """ |