Skip to content

Commit a4127aa

Browse files
author
Stephen Burrows
committed
Python 3 cleanup
1 parent 3028a36 commit a4127aa

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

django_inlinecss/css_loaders.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from __future__ import absolute_import
2+
from __future__ import division
3+
from __future__ import print_function
4+
from __future__ import unicode_literals
5+
16
from django.contrib.staticfiles import finders
27
from django.contrib.staticfiles.storage import staticfiles_storage
38

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

28-
with open(expanded_path) as css_file:
29-
return css_file.read()
33+
with open(expanded_path, 'rb') as css_file:
34+
return css_file.read().decode('utf-8')
3035

3136

3237
class StaticfilesStorageCSSLoader(BaseCSSLoader):
3338
def load(self, path):
3439
"""
3540
Retrieve CSS contents with staticfiles storage
3641
"""
37-
return staticfiles_storage.open(path).read()
42+
return staticfiles_storage.open(path).read().decode('utf-8')

django_inlinecss/tests/test_templatetags.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def assert_foo_and_bar_rendered(self, rendered):
2828
r'<div class="foo" style="margin: 10px 15px 20px 25px">'
2929
r'\s+This is the "foo" div.\s+'
3030
r'<\/div>')
31-
self.assertRegexpMatches(
31+
self.assertRegex(
3232
rendered,
3333
foo_div_regex)
3434

3535
bar_div_regex = (
3636
r'<div class="bar" style="padding: 10px 15px 20px 25px">'
3737
r'\s+This is the "bar" div.\s+'
3838
r'<\/div>')
39-
self.assertRegexpMatches(
39+
self.assertRegex(
4040
rendered,
4141
bar_div_regex)
4242

@@ -120,10 +120,10 @@ def test_unicode_context_variables(self):
120120

121121
rendered = template.render({
122122
'unicode_string': u'I love playing with my pi\xf1ata'})
123-
self.assertRegexpMatches(
123+
self.assertRegex(
124124
rendered,
125125
'<div class="bar" style="padding: 10px 15px 20px 25px">')
126-
self.assertRegexpMatches(
126+
self.assertRegex(
127127
rendered,
128128
u'I love playing with my pi\xf1ata')
129129

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

141141
rendered = template.render({})
142-
self.assertRegexpMatches(
142+
self.assertRegex(
143143
rendered,
144144
r'<body>\s+<!-- Here is comment one -->\s+<div')
145-
self.assertRegexpMatches(
145+
self.assertRegex(
146146
rendered,
147147
r'This is the "foo" div.\s+<!-- comment two -->\s+')
148-
self.assertRegexpMatches(
148+
self.assertRegex(
149149
rendered,
150150
r'This is the "bar" div.\s+<!-- comment three -->\s+')
151151

0 commit comments

Comments
 (0)