Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Unified Diff: tools/android/loading/content_classification_lens.py

Issue 1645953002: Conditional import of adblocker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/android/loading/content_classification_lens_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/loading/content_classification_lens.py
diff --git a/tools/android/loading/content_classification_lens.py b/tools/android/loading/content_classification_lens.py
index 2e8f0bdceab1a93bd44defbe80ec35023a7a8855..b12b9afe7d238f67c2194497d747bc31b47ac841 100644
--- a/tools/android/loading/content_classification_lens.py
+++ b/tools/android/loading/content_classification_lens.py
@@ -4,8 +4,8 @@
"""Labels requests according to the type of content they represent."""
-import adblockparser # Available on PyPI, through pip.
import collections
+import logging
import os
import loading_trace
@@ -93,10 +93,23 @@ class _RulesMatcher(object):
no_whitelist: (bool) Whether the whitelisting rules should be ignored.
"""
self._rules = self._FilterRules(rules, no_whitelist)
- self._matcher = adblockparser.AdblockRules(self._rules)
+ if self._rules:
blundell 2016/01/28 11:55:36 Maybe a comment above this like "Only try to inclu
+ try:
+ import adblockparser
+ self._matcher = adblockparser.AdblockRules(self._rules)
+ except ImportError:
+ logging.critical('Likely you need to install adblockparser. Try:\n'
+ ' pip install --user adblockparser\n'
+ 'For 10-100x better performance, also try:\n'
+ " pip install --user 're2 >= 0.2.21'")
+ raise
+ else:
+ self._matcher = None
def Matches(self, request):
"""Returns whether a request matches one of the rules."""
+ if self._matcher is None:
+ return False
url = request.url
return self._matcher.should_block(url, self._GetOptions(request))
« no previous file with comments | « no previous file | tools/android/loading/content_classification_lens_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698