| 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-2013 Eyeo GmbH |    4 # Copyright (C) 2006-2013 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 sys, os, subprocess, zipfile, json, urlparse, codecs |   18 import sys, os, subprocess, zipfile, json, urlparse, codecs | 
|   19 from StringIO import StringIO |   19 from StringIO import StringIO | 
|   20 from ConfigParser import SafeConfigParser |   20 from ConfigParser import SafeConfigParser | 
|   21  |   21  | 
|   22 class Source: |   22 class Source: | 
|   23   def resolve_link(self, url, locale): |   23   def resolve_link(self, url, locale): | 
|   24     parsed = urlparse.urlparse(url) |   24     parsed = urlparse.urlparse(url) | 
|   25     page = parsed.path |   25     page = parsed.path | 
|   26     if parsed.scheme != "" or page.startswith("/") or page.startswith("."): |   26     if parsed.scheme != "" or page.startswith("/") or page.startswith("."): | 
|   27       # Not a page link |   27       # Not a page link | 
|   28       return None, None |   28       return None, None | 
|   29  |   29  | 
 |   30     if parsed.path == "" and url != "": | 
 |   31       # Page-relative link | 
 |   32       return None, None | 
 |   33  | 
|   30     config = self.read_config() |   34     config = self.read_config() | 
|   31     default_locale = config.get("general", "defaultlocale") |   35     default_locale = config.get("general", "defaultlocale") | 
|   32     default_page = config.get("general", "defaultpage") |   36     default_page = config.get("general", "defaultpage") | 
|   33  |   37  | 
|   34     checked_page = page |   38     checked_page = page | 
|   35     if config.has_option("locale_overrides", page): |   39     if config.has_option("locale_overrides", page): | 
|   36       checked_page = config.get("locale_overrides", page) |   40       checked_page = config.get("locale_overrides", page) | 
|   37  |   41  | 
|   38     if self.has_localizable_file(default_locale, checked_page): |   42     if self.has_localizable_file(default_locale, checked_page): | 
|   39       if not self.has_localizable_file(locale, checked_page): |   43       if not self.has_localizable_file(locale, checked_page): | 
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  235     return os.path.isfile(self.get_path(filename)) |  239     return os.path.isfile(self.get_path(filename)) | 
|  236  |  240  | 
|  237   def read_file(self, filename, binary=False): |  241   def read_file(self, filename, binary=False): | 
|  238     encoding = None if binary else "utf-8" |  242     encoding = None if binary else "utf-8" | 
|  239     with codecs.open(self.get_path(filename), "rb", encoding=encoding) as handle
     : |  243     with codecs.open(self.get_path(filename), "rb", encoding=encoding) as handle
     : | 
|  240       return handle.read() |  244       return handle.read() | 
|  241  |  245  | 
|  242   def list_files(self, subdir): |  246   def list_files(self, subdir): | 
|  243     result = [] |  247     result = [] | 
|  244     def do_list(dir, relpath): |  248     def do_list(dir, relpath): | 
|  245       files = os.listdir(dir) |  249       try: | 
 |  250         files = os.listdir(dir) | 
 |  251       except OSError: | 
 |  252         return | 
 |  253  | 
|  246       for filename in files: |  254       for filename in files: | 
|  247         path = os.path.join(dir, filename) |  255         path = os.path.join(dir, filename) | 
|  248         if os.path.isfile(path): |  256         if os.path.isfile(path): | 
|  249           result.append(relpath + filename) |  257           result.append(relpath + filename) | 
|  250         elif os.path.isdir(path): |  258         elif os.path.isdir(path): | 
|  251           do_list(path, relpath + filename + "/") |  259           do_list(path, relpath + filename + "/") | 
|  252     do_list(self.get_path(subdir), "") |  260     do_list(self.get_path(subdir), "") | 
|  253     return result |  261     return result | 
| OLD | NEW |