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

Unified Diff: filters/inline_image.py

Issue 4661048523096064: Issue 2120 - Add support for animations. (Closed)
Patch Set: Forgot to give localise_path filter a default return! Created April 9, 2015, 8:44 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | filters/localise_path.py » ('j') | filters/localise_path.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filters/inline_image.py
diff --git a/filters/inline_image.py b/filters/inline_image.py
new file mode 100644
index 0000000000000000000000000000000000000000..fcdd8a4dfa846b49ab2955bf0fba1fc47ebd4aa4
--- /dev/null
+++ b/filters/inline_image.py
@@ -0,0 +1,23 @@
+# This file is part of the Adblock Plus website,
+# Copyright (C) 2006-2015 Eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+import mimetypes
+import urllib
+
+def inline_image(path):
Sebastian Noack 2015/04/10 07:55:46 The code here isn't specific to images. So you mig
+ mime_type = mimetypes.guess_type(path)[0]
Sebastian Noack 2015/04/10 07:55:46 Note that mimetype.guess_type() might return None.
kzar 2015/04/11 13:32:01 You're right, if we make this filter generic for a
+ with open(path, "rb") as f:
Sebastian Noack 2015/04/10 07:55:46 Do we really want to resolve the path relative to
kzar 2015/04/11 13:32:01 Good point, I now make use of the cms.Source metho
+ encoded = urllib.quote(f.read().encode("base64"))
Sebastian Noack 2015/04/10 09:50:25 I'm not a fan of Python's str-to-str encodings. Ca
kzar 2015/04/11 13:32:01 I'm not sure this is possible now that I'm using t
kzar 2015/04/11 14:05:21 Done.
+ return "data:%s;base64,%s" % (mime_type, encoded)
« no previous file with comments | « no previous file | filters/localise_path.py » ('j') | filters/localise_path.py » ('J')

Powered by Google App Engine
This is Rietveld