diff --git a/sass.py b/sass.py index e9b56040..758de34d 100644 --- a/sass.py +++ b/sass.py @@ -15,7 +15,7 @@ import collections import functools import inspect -from io import open +import io import os import os.path import re @@ -236,8 +236,9 @@ def compile_dirname( if s: v = v.decode('UTF-8') mkdirp(os.path.dirname(output_filename)) - with open(output_filename, 'w', - encoding="UTF-8") as output_file: + with io.open( + output_filename, 'w', encoding='UTF-8', newline='', + ) as output_file: output_file.write(v) else: return False, v diff --git a/sassc.py b/sassc.py index 24fe5265..5d6d578f 100755 --- a/sassc.py +++ b/sassc.py @@ -179,13 +179,15 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr): if len(args) < 2: print(css, file=stdout) else: - with io.open(args[1], 'w', encoding='utf-8') as f: + with io.open(args[1], 'w', encoding='utf-8', newline='') as f: f.write(css) if options.watch: print(filename, 'is just compiled to', args[1], file=stdout) if source_map_filename: - with io.open(source_map_filename, 'w', encoding='utf-8') as f: + with io.open( + source_map_filename, 'w', encoding='utf-8', newline='', + ) as f: f.write(source_map) if options.watch: # pragma: no cover # FIXME: we should utilize inotify on Linux, and FSEvents on Mac diff --git a/sasstests.py b/sasstests.py index 7a91338c..2558913f 100644 --- a/sasstests.py +++ b/sasstests.py @@ -643,25 +643,20 @@ def test_wsgi_sass_middleware(self): client = Client(app, Response) r = client.get('/asdf') assert r.status_code == 200 - self.assert_bytes_equal(b'/asdf', r.data) + self.assertEqual(b'/asdf', r.data) assert r.mimetype == 'text/plain' r = client.get('/static/a.scss.css') assert r.status_code == 200 - self.assert_bytes_equal( + self.assertEqual( b(A_EXPECTED_CSS_WITH_MAP), - r.data + r.data, ) assert r.mimetype == 'text/css' r = client.get('/static/not-exists.sass.css') assert r.status_code == 200 - self.assert_bytes_equal(b'/static/not-exists.sass.css', r.data) + self.assertEqual(b'/static/not-exists.sass.css', r.data) assert r.mimetype == 'text/plain' - def assert_bytes_equal(self, expected, actual, *args): - self.assertEqual(expected.replace(b'\r\n', b'\n'), - actual.replace(b'\r\n', b'\n'), - *args) - class DistutilsTestCase(BaseTestCase): @@ -749,7 +744,7 @@ def test_sassc_output(self): assert exit_code == 0 assert self.err.getvalue() == '' assert self.out.getvalue() == '' - with open(tmp) as f: + with io.open(tmp, encoding='UTF-8', newline='') as f: assert A_EXPECTED_CSS.strip() == f.read().strip() finally: os.remove(tmp) diff --git a/sassutils/builder.py b/sassutils/builder.py index e525f0e1..76d3719d 100644 --- a/sassutils/builder.py +++ b/sassutils/builder.py @@ -61,7 +61,9 @@ def build_directory(sass_path, css_path, output_style='nested', css = compile(filename=sass_fullname, output_style=output_style, include_paths=[_root_sass]) - with io.open(css_fullname, 'w', encoding='utf-8') as css_file: + with io.open( + css_fullname, 'w', encoding='utf-8', newline='', + ) as css_file: css_file.write(css) result[os.path.relpath(sass_fullname, _root_sass)] = \ os.path.relpath(css_fullname, _root_css) @@ -215,10 +217,12 @@ def build_one(self, package_dir, filename, source_map=False): css_folder = os.path.dirname(css_path) if not os.path.exists(css_folder): os.makedirs(css_folder) - with io.open(css_path, 'w', encoding='utf-8') as f: + with io.open(css_path, 'w', encoding='utf-8', newline='') as f: f.write(css) if source_map: # Source maps are JSON, and JSON has to be UTF-8 encoded - with io.open(source_map_path, 'w', encoding='utf-8') as f: + with io.open( + source_map_path, 'w', encoding='utf-8', newline='', + ) as f: f.write(source_map) return css_filename