OLD | NEW |
1 # This file is part of the Adblock Plus web scripts, | 1 # This file is part of the Adblock Plus web scripts, |
2 # Copyright (C) 2006-present eyeo GmbH | 2 # Copyright (C) 2006-present eyeo GmbH |
3 # | 3 # |
4 # Adblock Plus is free software: you can redistribute it and/or modify | 4 # Adblock Plus is free software: you can redistribute it and/or modify |
5 # it under the terms of the GNU General Public License version 3 as | 5 # it under the terms of the GNU General Public License version 3 as |
6 # published by the Free Software Foundation. | 6 # published by the Free Software Foundation. |
7 # | 7 # |
8 # Adblock Plus is distributed in the hope that it will be useful, | 8 # Adblock Plus is distributed in the hope that it will be useful, |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 def list_localizable_files(self): | 118 def list_localizable_files(self): |
119 default_locale = self.read_config().get('general', 'defaultlocale') | 119 default_locale = self.read_config().get('general', 'defaultlocale') |
120 return filter(lambda f: os.path.splitext(f)[1].lower() != '.json', | 120 return filter(lambda f: os.path.splitext(f)[1].lower() != '.json', |
121 self.list_files('locales/%s' % default_locale)) | 121 self.list_files('locales/%s' % default_locale)) |
122 | 122 |
123 def has_localizable_file(self, locale, filename): | 123 def has_localizable_file(self, locale, filename): |
124 return self.has_file(self.localizable_file_filename(locale, filename)) | 124 return self.has_file(self.localizable_file_filename(locale, filename)) |
125 | 125 |
126 def read_localizable_file(self, locale, filename): | 126 def read_localizable_file(self, locale, filename): |
127 return self.read_file(self.localizable_file_filename(locale, filename),
binary=True)[0] | 127 return self.read_file(self.localizable_file_filename(locale, filename),
True)[0] |
128 | 128 |
129 # | 129 # |
130 # Static file helpers | 130 # Static file helpers |
131 # | 131 # |
132 | 132 |
133 @staticmethod | 133 @staticmethod |
134 def static_filename(filename): | 134 def static_filename(filename): |
135 return 'static/%s' % filename | 135 return 'static/%s' % filename |
136 | 136 |
137 def list_static(self): | 137 def list_static(self): |
138 return self.list_files('static') | 138 return self.list_files('static') |
139 | 139 |
140 def has_static(self, filename): | 140 def has_static(self, filename): |
141 return self.has_file(self.static_filename(filename)) | 141 return self.has_file(self.static_filename(filename)) |
142 | 142 |
143 def read_static(self, filename): | 143 def read_static(self, filename): |
144 return self.read_file(self.static_filename(filename), binary=True)[0] | 144 return self.read_file(self.static_filename(filename), True)[0] |
145 | 145 |
146 # | 146 # |
147 # Locale helpers | 147 # Locale helpers |
148 # | 148 # |
149 | 149 |
150 def locale_filename(self, locale, page): | 150 def locale_filename(self, locale, page): |
151 config = self.read_config() | 151 config = self.read_config() |
152 try: | 152 try: |
153 page = config.get('locale_overrides', page) | 153 page = config.get('locale_overrides', page) |
154 except ConfigParser.Error: | 154 except ConfigParser.Error: |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 387 |
388 if additional_paths: | 388 if additional_paths: |
389 additional_sources = [ | 389 additional_sources = [ |
390 create_source(os.path.join(path, p)) | 390 create_source(os.path.join(path, p)) |
391 for p in additional_paths | 391 for p in additional_paths |
392 ] | 392 ] |
393 source = MultiSource([source] + additional_sources) | 393 source = MultiSource([source] + additional_sources) |
394 | 394 |
395 if cached: | 395 if cached: |
396 for fname in [ | 396 for fname in [ |
| 397 'list_files', |
| 398 'list_locales', |
397 'resolve_link', | 399 'resolve_link', |
398 'read_config', | 400 'read_config', |
399 'read_template', | 401 'read_template', |
400 'read_locale', | 402 'read_locale', |
| 403 'read_file', |
401 'read_include', | 404 'read_include', |
402 'exec_file', | 405 'exec_file', |
403 ]: | 406 ]: |
404 setattr(source, fname, _memoize(getattr(source, fname))) | 407 setattr(source, fname, _memoize(getattr(source, fname))) |
405 | 408 |
406 return source | 409 return source |
OLD | NEW |