| OLD | NEW | 
|---|
| 1 # coding: utf-8 | 1 # coding: utf-8 | 
| 2 | 2 | 
| 3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, | 
| 4 # Copyright (C) 2006-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 Eyeo GmbH | 
| 5 # | 5 # | 
| 6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify | 
| 7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as | 
| 8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. | 
| 9 # | 9 # | 
| 10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, | 
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. | 
| 14 # | 14 # | 
| 15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License | 
| 16 # along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
| 17 | 17 | 
| 18 import codecs | 18 import codecs | 
| 19 import collections | 19 import collections | 
| 20 import ConfigParser | 20 import ConfigParser | 
| 21 import json | 21 import json | 
| 22 import os | 22 import os | 
| 23 from StringIO import StringIO | 23 from StringIO import StringIO | 
| 24 import subprocess | 24 import subprocess | 
| 25 import urlparse | 25 import urlparse | 
| 26 import zipfile | 26 import zipfile | 
| 27 import logging | 27 import logging | 
| 28 | 28 | 
|  | 29 import jinja2 | 
|  | 30 | 
|  | 31 TEMPLATE_SUFFIX = '.tmpl' | 
|  | 32 | 
|  | 33 class SuffixTemplateLoader(jinja2.BaseLoader): | 
|  | 34   def __init__(self, loader, suffix=TEMPLATE_SUFFIX): | 
|  | 35     self.loader = loader | 
|  | 36     self.suffix = suffix | 
|  | 37 | 
|  | 38   def get_source(self, environment, template): | 
|  | 39     return self.loader.get_source(environment, template + self.suffix) | 
|  | 40 | 
| 29 class Source: | 41 class Source: | 
| 30   def resolve_link(self, url, locale): | 42   def resolve_link(self, url, locale): | 
| 31     parsed = urlparse.urlparse(url) | 43     parsed = urlparse.urlparse(url) | 
| 32     page = parsed.path | 44     page = parsed.path | 
| 33     if parsed.scheme != "" or page.startswith("/") or page.startswith("."): | 45     if parsed.scheme != "" or page.startswith("/") or page.startswith("."): | 
| 34       # Not a page link | 46       # Not a page link | 
| 35       return None, None | 47       return None, None | 
| 36 | 48 | 
| 37     if page == "" and url != "": | 49     if page == "" and url != "": | 
| 38       # Page-relative link | 50       # Page-relative link | 
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 180         result[key] = value["message"] | 192         result[key] = value["message"] | 
| 181 | 193 | 
| 182     return result | 194     return result | 
| 183 | 195 | 
| 184   # | 196   # | 
| 185   # Template helpers | 197   # Template helpers | 
| 186   # | 198   # | 
| 187 | 199 | 
| 188   @staticmethod | 200   @staticmethod | 
| 189   def template_filename(template): | 201   def template_filename(template): | 
| 190     return "templates/%s.tmpl" % template | 202     return "templates/%s%s" % (template, TEMPLATE_SUFFIX) | 
| 191 | 203 | 
| 192   def read_template(self, template): | 204   def read_template(self, template): | 
| 193     return self.read_file(self.template_filename(template)) | 205     return self.read_file(self.template_filename(template)) | 
| 194 | 206 | 
|  | 207   def get_template_loader(self): | 
|  | 208     return SuffixTemplateLoader(jinja2.FunctionLoader(self.read_file)) | 
|  | 209 | 
| 195   # | 210   # | 
| 196   # Include helpers | 211   # Include helpers | 
| 197   # | 212   # | 
| 198 | 213 | 
| 199   @staticmethod | 214   @staticmethod | 
| 200   def include_filename(include, format): | 215   def include_filename(include, format): | 
| 201     return "includes/%s.%s" % (include, format) | 216     return "includes/%s.%s" % (include, format) | 
| 202 | 217 | 
| 203   def has_include(self, include, format): | 218   def has_include(self, include, format): | 
| 204     return self.has_file(self.include_filename(include, format)) | 219     return self.has_file(self.include_filename(include, format)) | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 287         path = os.path.join(dir, filename) | 302         path = os.path.join(dir, filename) | 
| 288         if os.path.isfile(path): | 303         if os.path.isfile(path): | 
| 289           result.append(relpath + filename) | 304           result.append(relpath + filename) | 
| 290         elif os.path.isdir(path): | 305         elif os.path.isdir(path): | 
| 291           do_list(path, relpath + filename + "/") | 306           do_list(path, relpath + filename + "/") | 
| 292     do_list(self.get_path(subdir), "") | 307     do_list(self.get_path(subdir), "") | 
| 293     return result | 308     return result | 
| 294 | 309 | 
| 295   def get_cache_dir(self): | 310   def get_cache_dir(self): | 
| 296     return os.path.join(self._dir, "cache") | 311     return os.path.join(self._dir, "cache") | 
|  | 312 | 
|  | 313   def get_template_loader(self): | 
|  | 314     return SuffixTemplateLoader(jinja2.FileSystemLoader(self._dir)) | 
| OLD | NEW | 
|---|