From 9f08147bf907b7fc2412438ba138e7f58e4af8a4 Mon Sep 17 00:00:00 2001 From: Ben Spaulding Date: Fri, 31 Jan 2020 22:21:12 -0700 Subject: [PATCH] Keep mimetypes as str on all versions of Python. As noted in jazzband/django-pipeline#297 the mimetypes should not be `unicode` *on Python 2*. But they should be `str` on Python 3. Caused by: jazzband/django-pipeline#297 Effecting: - pallets/werkzeug#636 - pallets/werkzeug#637 --- AUTHORS | 1 + docs/configuration.rst | 10 +++++----- pipeline/conf.py | 10 +++++----- tests/tests/test_utils.py | 10 ++++++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index bc97f997..648921ac 100644 --- a/AUTHORS +++ b/AUTHORS @@ -21,6 +21,7 @@ or just made Pipeline more awesome. * Austin Pua * Axel Haustant * Balazs Kossovics + * Ben Spaulding * Ben Vinegar * Brad Pitcher * Brant Young diff --git a/docs/configuration.rst b/docs/configuration.rst index a2d4ead9..13c807c9 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -231,11 +231,11 @@ Tuple that match file extension with their corresponding mimetypes. Defaults to :: ( - (b'text/coffeescript', '.coffee'), - (b'text/less', '.less'), - (b'text/javascript', '.js'), - (b'text/x-sass', '.sass'), - (b'text/x-scss', '.scss') + ('text/coffeescript', '.coffee'), + ('text/less', '.less'), + ('text/javascript', '.js'), + ('text/x-sass', '.sass'), + ('text/x-scss', '.scss') ) .. warning:: diff --git a/pipeline/conf.py b/pipeline/conf.py index 2bb854a5..f84da5d3 100644 --- a/pipeline/conf.py +++ b/pipeline/conf.py @@ -71,11 +71,11 @@ 'LESS_ARGUMENTS': '', 'MIMETYPES': ( - (b'text/coffeescript', '.coffee'), - (b'text/less', '.less'), - (b'text/javascript', '.js'), - (b'text/x-sass', '.sass'), - (b'text/x-scss', '.scss') + (str('text/coffeescript'), str('.coffee')), + (str('text/less'), str('.less')), + (str('text/javascript'), str('.js')), + (str('text/x-sass'), str('.sass')), + (str('text/x-scss'), str('.scss')) ), 'EMBED_MAX_IMAGE_SIZE': 32700, diff --git a/tests/tests/test_utils.py b/tests/tests/test_utils.py index 3490a2e2..a3db9b7b 100644 --- a/tests/tests/test_utils.py +++ b/tests/tests/test_utils.py @@ -1,3 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import mimetypes + from django.test import TestCase from pipeline.utils import guess_type @@ -8,3 +13,8 @@ def test_guess_type(self): self.assertEqual('text/css', guess_type('stylesheet.css')) self.assertEqual('text/coffeescript', guess_type('application.coffee')) self.assertEqual('text/less', guess_type('stylesheet.less')) + + def test_mimetypes_are_str(self): + for ext, mtype in mimetypes.types_map.items(): + self.assertIsInstance(ext, str) + self.assertIsInstance(mtype, str)