Commit 3c1bde8b authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Use UTF-8 when accessing the file system.

parent 9fefd2e3
......@@ -165,14 +165,14 @@ class PathHandler(object):
path_parts = self.path_parts(ext_override)
real_file = os.path.join(mp3wavcfg.BASE, *path_parts)
try:
return os.stat(real_file), real_file
return os.stat(real_file.encode("utf-8")), real_file
except FileNotFoundError:
pass
if self.extension(ext_override) == ".mp3":
mp3file = os.path.join(mp3wavcfg.BASE, "mp3-cache", *path_parts)
try:
return os.stat(mp3file), mp3file
return os.stat(mp3file.encode("utf-8")), mp3file
except FileNotFoundError:
pass
......@@ -221,7 +221,9 @@ def handle_directory(environ, start_response, ph, real_dir):
mp3s = {}
dirs = set()
for fn in os.listdir(real_dir):
for fn in os.listdir(real_dir.encode("utf-8")):
fn = fn.decode("utf-8")
# Don't expose the cache directory directly.
if fn == "mp3-cache":
......@@ -229,7 +231,7 @@ def handle_directory(environ, start_response, ph, real_dir):
realfile = os.path.join(real_dir, fn)
try:
status = os.stat(realfile)
status = os.stat(realfile.encode("utf-8"))
except os.error:
continue
......@@ -299,7 +301,7 @@ def handle_file(environ, start_response, ph, real_file):
start_response("403 Forbidden", [])
return []
file = open(real_file, "r")
file = open(real_file.encode("utf-8"), "r")
start_response("200 OK", [("Content-Type", content_type)])
if 'wsgi.file_wrapper' in environ:
......
......@@ -54,7 +54,7 @@ def work():
handle_message(sock, msg)
def exists(fn):
return os.path.isfile(os.path.join(mp3wavcfg.BASE, fn))
return os.path.isfile(os.path.join(mp3wavcfg.BASE, fn).encode("utf-8"))
def handle_message(client, msg):
global queue
......@@ -96,14 +96,14 @@ def encode(fn):
result_file = os.path.join(mp3wavcfg.BASE, "mp3-cache", fn + ".mp3")
result_dir = os.path.dirname(result_file)
try:
os.makedirs(result_dir)
os.makedirs(result_dir.encode("utf-8"))
except os.error as e:
if e.errno != errno.EEXIST:
raise
cmd = ["lame", "--preset", "standard", "--nohist",
os.path.join(mp3wavcfg.BASE, fn + ".wav"),
result_file + ".tmp"]
os.path.join(mp3wavcfg.BASE, fn + ".wav").encode("utf-8"),
(result_file + ".tmp").encode("utf-8")]
lame = subprocess.Popen(args=cmd, bufsize=0, stdin=subprocess.DEVNULL,
stderr=subprocess.PIPE)
percent_match = re.compile(".*\\(([0-9]+)%\\)")
......@@ -117,10 +117,11 @@ def encode(fn):
c.send(("progress", m.group(1)))
x = lame.wait()
if x == 0:
os.rename(result_file + ".tmp", result_file)
os.rename((result_file + ".tmp").encode("utf-8"),
result_file.encode("utf-8"))
else:
try:
os.remove(result_file + ".tmp")
os.remove((result_file + ".tmp").encode("utf-8"))
except OSError:
pass
sys.exit(x)
......
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