Commit d53d161e by Timothée Peignier

naive unicode support

parent 6eb299de
...@@ -36,13 +36,13 @@ class Compiler(object): ...@@ -36,13 +36,13 @@ class Compiler(object):
def read_file(self, path): def read_file(self, path):
file = storage.open(path, 'rb') file = storage.open(path, 'rb')
content = file.read() content = file.read().decode('utf-8')
file.close() file.close()
return content return content
def save_file(self, path, content): def save_file(self, path, content):
file = storage.open(path, 'wb') file = storage.open(path, 'wb')
file.write(content) file.write(content.encode('utf-8'))
file.close() file.close()
...@@ -58,7 +58,7 @@ class CompilerBase(object): ...@@ -58,7 +58,7 @@ class CompilerBase(object):
def save_file(self, path, content): def save_file(self, path, content):
file = storage.open(path, 'wb') file = storage.open(path, 'wb')
file.write(content) file.write(content.encode('utf-8'))
file.close() file.close()
return path return path
...@@ -71,10 +71,10 @@ class SubProcessCompiler(CompilerBase): ...@@ -71,10 +71,10 @@ class SubProcessCompiler(CompilerBase):
def execute_command(self, command, content): def execute_command(self, command, content):
pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stdin=subprocess.PIPE, stderr=subprocess.PIPE) stdin=subprocess.PIPE, stderr=subprocess.PIPE)
pipe.stdin.write(content) pipe.stdin.write(content.encode('utf-8'))
pipe.stdin.close() pipe.stdin.close()
compressed_content = pipe.stdout.read() compressed_content = pipe.stdout.read().decode('utf-8')
pipe.stdout.close() pipe.stdout.close()
error = pipe.stderr.read() error = pipe.stderr.read()
......
...@@ -13,7 +13,7 @@ class LessCompiler(CompilerBase): ...@@ -13,7 +13,7 @@ class LessCompiler(CompilerBase):
def compile_file(self, content): def compile_file(self, content):
tmp_file = tempfile.NamedTemporaryFile(mode='w+b') tmp_file = tempfile.NamedTemporaryFile(mode='w+b')
tmp_file.write(content) tmp_file.write(content.encode('utf-8'))
tmp_file.flush() tmp_file.flush()
output_file = tempfile.NamedTemporaryFile(mode='w+b') output_file = tempfile.NamedTemporaryFile(mode='w+b')
...@@ -25,7 +25,7 @@ class LessCompiler(CompilerBase): ...@@ -25,7 +25,7 @@ class LessCompiler(CompilerBase):
command_output = os.popen(command).read() command_output = os.popen(command).read()
compiled_content = output_file.read() compiled_content = output_file.read().decode('utf-8')
output_file.close() output_file.close()
tmp_file.close() tmp_file.close()
......
...@@ -197,7 +197,7 @@ class Compressor(object): ...@@ -197,7 +197,7 @@ class Compressor(object):
def read_file(self, path): def read_file(self, path):
"""Read file content in binary mode""" """Read file content in binary mode"""
file = storage.open(path, 'rb') file = storage.open(path, 'rb')
content = file.read() content = file.read().decode('utf-8')
file.close() file.close()
return content return content
...@@ -222,10 +222,10 @@ class SubProcessCompressor(CompressorBase): ...@@ -222,10 +222,10 @@ class SubProcessCompressor(CompressorBase):
def execute_command(self, command, content): def execute_command(self, command, content):
pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
stdin=subprocess.PIPE, stderr=subprocess.PIPE) stdin=subprocess.PIPE, stderr=subprocess.PIPE)
pipe.stdin.write(content) pipe.stdin.write(content.encode('utf-8'))
pipe.stdin.close() pipe.stdin.close()
compressed_content = pipe.stdout.read() compressed_content = pipe.stdout.read().decode('utf-8')
pipe.stdout.close() pipe.stdout.close()
error = pipe.stderr.read() error = pipe.stderr.read()
......
...@@ -11,7 +11,7 @@ warnings.simplefilter('ignore', RuntimeWarning) ...@@ -11,7 +11,7 @@ warnings.simplefilter('ignore', RuntimeWarning)
class CSSTidyCompressor(CompressorBase): class CSSTidyCompressor(CompressorBase):
def compress_css(self, css): def compress_css(self, css):
tmp_file = tempfile.NamedTemporaryFile(mode='w+b') tmp_file = tempfile.NamedTemporaryFile(mode='w+b')
tmp_file.write(css) tmp_file.write(css.encode('utf-8'))
tmp_file.flush() tmp_file.flush()
output_file = tempfile.NamedTemporaryFile(mode='w+b') output_file = tempfile.NamedTemporaryFile(mode='w+b')
...@@ -23,7 +23,7 @@ class CSSTidyCompressor(CompressorBase): ...@@ -23,7 +23,7 @@ class CSSTidyCompressor(CompressorBase):
command_output = os.popen(command).read() command_output = os.popen(command).read()
filtered_css = output_file.read() filtered_css = output_file.read().decode('utf-8')
output_file.close() output_file.close()
tmp_file.close() tmp_file.close()
......
...@@ -73,7 +73,7 @@ class Packager(object): ...@@ -73,7 +73,7 @@ class Packager(object):
def save_file(self, path, content): def save_file(self, path, content):
file = storage.open(path, 'wb') file = storage.open(path, 'wb')
file.write(content) file.write(content.encode('utf-8'))
file.close() file.close()
return path return path
......
...@@ -29,7 +29,7 @@ class HashVersioningBase(VersioningBase): ...@@ -29,7 +29,7 @@ class HashVersioningBase(VersioningBase):
def read_file(self, path): def read_file(self, path):
"""Read file content in binary mode""" """Read file content in binary mode"""
file = storage.open(path, 'rb') file = storage.open(path, 'rb')
content = file.read() content = file.read().decode('utf-8')
file.close() file.close()
return content return content
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment