| 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) |