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

Delta Between Two Patch Sets: filters/inline_file.py

Issue 4661048523096064: Issue 2120 - Add support for animations. (Closed)
Left Patch Set: Improved license header for animation.js. Created April 12, 2015, 5 p.m.
Right Patch Set: Addressed feedback. Created April 13, 2015, 9:03 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | static/js/animation.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus website, 1 # This file is part of the Adblock Plus website,
2 # Copyright (C) 2006-2015 Eyeo GmbH 2 # Copyright (C) 2006-2015 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
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 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/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import base64 16 import base64
17 import mimetypes
18 import urllib 17 import urllib
18 from mimetypes import MimeTypes
19 19
20 from jinja2 import contextfilter 20 from jinja2 import contextfilter
21
22
23 mime = MimeTypes()
21 24
22 @contextfilter 25 @contextfilter
23 def inline_file(context, path, mime_type=None): 26 def inline_file(context, path, mime_type=None):
24 if mime_type is None: 27 if mime_type is None:
25 mime_type = mimetypes.guess_type(path)[0] or "application/octet-stream" 28 mime_type = mime.guess_type(path)[0]
Wladimir Palant 2015/04/12 18:45:27 Please create your own MimeTypes instance rather t
kzar 2015/04/13 09:05:35 Done.
29 if mime_type is None:
30 raise ValueError("Unknown mime type for file '%s', please specify." % path )
26 31
27 source = context["source"] 32 source = context["source"]
28 for locale in (context["locale"], "en"): 33 for locale in (context["locale"], "en"):
29 if source.has_localizable_file(locale, path): 34 if source.has_localizable_file(locale, path):
30 file_contents = source.read_localizable_file(locale, path) 35 file_contents = source.read_localizable_file(locale, path)
31 break 36 break
32 else: 37 else:
33 file_contents = source.read_static(path) 38 file_contents = source.read_static(path)
34 39
35 return "data:%s;base64,%s" % ( 40 return "data:%s;base64,%s" % (
36 mime_type, 41 mime_type,
37 urllib.quote(base64.b64encode(file_contents)) 42 urllib.quote(base64.b64encode(file_contents))
38 ) 43 )
LEFTRIGHT

Powered by Google App Engine
This is Rietveld