Skip to content

Commit

Permalink
Python 3 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Burrows committed Oct 23, 2019
1 parent 3028a36 commit a4127aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 8 additions & 3 deletions django_inlinecss/css_loaders.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage

Expand Down Expand Up @@ -25,13 +30,13 @@ def load(self, path):
if expanded_path is None:
raise IOError('{} does not exist'.format(path))

with open(expanded_path) as css_file:
return css_file.read()
with open(expanded_path, 'rb') as css_file:
return css_file.read().decode('utf-8')


class StaticfilesStorageCSSLoader(BaseCSSLoader):
def load(self, path):
"""
Retrieve CSS contents with staticfiles storage
"""
return staticfiles_storage.open(path).read()
return staticfiles_storage.open(path).read().decode('utf-8')
14 changes: 7 additions & 7 deletions django_inlinecss/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def assert_foo_and_bar_rendered(self, rendered):
r'<div class="foo" style="margin: 10px 15px 20px 25px">'
r'\s+This is the "foo" div.\s+'
r'<\/div>')
self.assertRegexpMatches(
self.assertRegex(
rendered,
foo_div_regex)

bar_div_regex = (
r'<div class="bar" style="padding: 10px 15px 20px 25px">'
r'\s+This is the "bar" div.\s+'
r'<\/div>')
self.assertRegexpMatches(
self.assertRegex(
rendered,
bar_div_regex)

Expand Down Expand Up @@ -120,10 +120,10 @@ def test_unicode_context_variables(self):

rendered = template.render({
'unicode_string': u'I love playing with my pi\xf1ata'})
self.assertRegexpMatches(
self.assertRegex(
rendered,
'<div class="bar" style="padding: 10px 15px 20px 25px">')
self.assertRegexpMatches(
self.assertRegex(
rendered,
u'I love playing with my pi\xf1ata')

Expand All @@ -139,13 +139,13 @@ def test_comments_are_ignored(self):
template = get_template('comments_are_ignored.html')

rendered = template.render({})
self.assertRegexpMatches(
self.assertRegex(
rendered,
r'<body>\s+<!-- Here is comment one -->\s+<div')
self.assertRegexpMatches(
self.assertRegex(
rendered,
r'This is the "foo" div.\s+<!-- comment two -->\s+')
self.assertRegexpMatches(
self.assertRegex(
rendered,
r'This is the "bar" div.\s+<!-- comment three -->\s+')

Expand Down

0 comments on commit a4127aa

Please sign in to comment.