Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: filters/get_subscriptions.py

Issue 5662732741246976: Issue 2144 - [adblockplus.org Anwiki to CMS migration] get_subscriptions filter expects a local sub… (Closed)
Patch Set: Created March 13, 2015, 7:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filters/get_subscriptions.py
===================================================================
--- a/filters/get_subscriptions.py
+++ b/filters/get_subscriptions.py
@@ -12,31 +12,39 @@
#
# You should have received a copy of the GNU General Public License
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
import codecs
import os
import tarfile
import urllib
+from ConfigParser import SafeConfigParser
def get_subscriptions(_):
- from sitescripts.subscriptions.subscriptionParser import parse_file, calculate_supplemented
+ import sitescripts.subscriptions.subscriptionParser as subscriptionParser
Sebastian Noack 2015/03/13 19:51:45 Nit: from ... import
Wladimir Palant 2015/03/13 19:58:51 Done.
result = {}
utf8_reader = codecs.getreader('utf8')
source = urllib.urlopen("https://hg.adblockplus.org/subscriptionlist/archive/default.tar.gz")
+ orig_get_settings = subscriptionParser.get_settings
try:
+ # Hack: monkey-patch subscriptionParser.get_settings()
+ settings = SafeConfigParser()
+ settings.readfp(utf8_reader(urllib.urlopen("https://hg.adblockplus.org/subscriptionlist/rawfile/default/settings")))
Sebastian Noack 2015/03/13 19:51:45 The file-like object returned by urllib.urlopen()
Wladimir Palant 2015/03/13 19:58:51 Done.
Sebastian Noack 2015/03/13 20:06:34 I verified that __enter__/__exit__ isnt't implemen
+ subscriptionParser.get_settings = lambda: settings
+
with tarfile.open(fileobj=source, mode="r|gz") as archive:
for fileinfo in archive:
if os.path.splitext(fileinfo.name)[1] != ".subscription":
continue
- filedata = parse_file(fileinfo.name, utf8_reader(archive.extractfile(fileinfo)))
+ filedata = subscriptionParser.parse_file(fileinfo.name, utf8_reader(archive.extractfile(fileinfo)))
if filedata.unavailable:
continue
result[filedata.name] = filedata
finally:
source.close()
+ subscriptionParser.get_settings = orig_get_settings
- calculate_supplemented(result)
+ subscriptionParser.calculate_supplemented(result)
return result.values()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld