OLD | NEW |
(Empty) | |
| 1 # This file is part of the Adblock Plus website, |
| 2 # Copyright (C) 2006-2015 Eyeo GmbH |
| 3 # |
| 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 |
| 6 # published by the Free Software Foundation. |
| 7 # |
| 8 # Adblock Plus is distributed in the hope that it will be useful, |
| 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 # GNU General Public License for more details. |
| 12 # |
| 13 # You should have received a copy of the GNU General Public License |
| 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
| 16 import mimetypes |
| 17 import urllib |
| 18 |
| 19 from jinja2 import contextfilter |
| 20 |
| 21 @contextfilter |
| 22 def inline_file(context, path, mime_type=None): |
| 23 if mime_type is None: |
| 24 mime_type = mimetypes.guess_type(path)[0] or "application/octet-stream" |
| 25 |
| 26 source = context["source"] |
| 27 for locale in (context["locale"], "en"): |
| 28 if source.has_localizable_file(locale, path): |
| 29 file_contents = source.read_localizable_file(locale, path) |
| 30 break |
| 31 else: |
| 32 file_contents = source.read_static(path) |
| 33 |
| 34 return "data:%s;base64,%s" % ( |
| 35 mime_type, |
| 36 urllib.quote(file_contents.encode("base64")) |
| 37 ) |
OLD | NEW |