Commit e97ca73b authored by Michael Murtaugh's avatar Michael Murtaugh
Browse files

deal with surrogates in utf-8

parent 3fc62e4d
......@@ -93,7 +93,7 @@ def make_folder_meta (target, source, env):
d = {}
d['type'] = "directory"
d['filename'] = os.path.split(path)[1]
d['id'] = urlquote(d['filename'], errors="replace")+"/"
d['id'] = urlquote(d['filename'], errors="surrogatepass")+"/"
files = 0
folders = 0
total_bytes = 0
......@@ -152,7 +152,7 @@ def make_folder_meta (target, source, env):
cc.append(cd)
cd['type'] = "file"
cd['filename'] = os.path.split(src.path)[1]
cd['id'] = urlquote(cd['filename'], errors="replace")
cd['id'] = urlquote(cd['filename'], errors="surrogatepass")
contents_by_id[cd['id']] = cd
cd_mtime_dt = datetime.datetime.fromtimestamp(os.stat(src.path, follow_symlinks=False).st_mtime)
cd['mtime'] = cd_mtime_dt.isoformat()
......@@ -209,9 +209,9 @@ FolderMeta = Builder(action=make_folder_meta)
def ffmpeg_get_meta (target, source, env):
d = ffmpeg_get_info(source[0].path)
d['id'] = urlquote(os.path.basename(source[0].path), errors="replace")
d['id'] = urlquote(os.path.basename(source[0].path), errors="surrogatepass")
def relurl(x):
return urlquote(os.path.relpath(str(x), os.path.dirname(os.path.dirname(os.path.dirname(target[0].path)))), errors="replace")
return urlquote(os.path.relpath(str(x), os.path.dirname(os.path.dirname(os.path.dirname(target[0].path)))), errors="surrogatepass")
for s in source[1:]:
basename = os.path.basename(str(s))
if basename == "thumb.png":
......@@ -275,9 +275,9 @@ ImageThumb = Builder(action=make_image_thumb)
def make_image_meta (target, source, env):
d = image_get_info(source[0].path)
d['id'] = urlquote(os.path.basename(source[0].path), errors="replace")
d['id'] = urlquote(os.path.basename(source[0].path), errors="surrogatepass")
def relurl(x):
return urlquote(os.path.relpath(str(x), os.path.dirname(os.path.dirname(os.path.dirname(target[0].path)))), errors="replace")
return urlquote(os.path.relpath(str(x), os.path.dirname(os.path.dirname(os.path.dirname(target[0].path)))), errors="surrogatepass")
for s in source[1:]:
basename = os.path.basename(str(s))
if basename in ("thumb.jpg", "thumb.png"):
......@@ -292,9 +292,9 @@ ImageMeta = Builder(action=make_image_meta)
def make_pdf_meta (target, source, env):
d = pdf_get_info(source[0].path)
d['id'] = urlquote(os.path.basename(source[0].path), errors="replace")
d['id'] = urlquote(os.path.basename(source[0].path), errors="surrogatepass")
def relurl(x):
return urlquote(os.path.relpath(str(x), os.path.dirname(os.path.dirname(os.path.dirname(target[0].path)))), errors="replace")
return urlquote(os.path.relpath(str(x), os.path.dirname(os.path.dirname(os.path.dirname(target[0].path)))), errors="surrogatepass")
for s in source[1:]:
basename = os.path.basename(str(s))
if basename in ("thumb.jpg", "thumb.png"):
......@@ -361,8 +361,9 @@ def template_action (target, source, env):
data['allkeys'] = allkeys
data['breadcrumbs'] = bc
with open(target[0].path, "w") as fout:
print (template.render(**data), file=fout)
with open(target[0].path, "wb") as fout:
fout.write(template.render(**data).encode("utf-8", errors="surrogateescape"))
# fout.write(template.render(**data).encode("utf-8", errors="replace"))
# Template = Builder(action=template_action)
Template = Builder(action=Action(template_action, varlist=("SCONS_TEMPLATE", "SCONS_ROOT")))
......
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