From cbd0c014eced9c816528115d0e37022e96460f84 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 23 Jun 2019 08:29:02 -0700 Subject: [PATCH] Hoping this will allow github to resolve the merge conflict with master --- datasette/utils/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/datasette/utils/__init__.py b/datasette/utils/__init__.py index 5ed8dd12..1173d798 100644 --- a/datasette/utils/__init__.py +++ b/datasette/utils/__init__.py @@ -261,6 +261,27 @@ def escape_sqlite(s): return "[{}]".format(s) +_decode_path_component_re = re.compile(r"U\+([\da-h]{4})", re.IGNORECASE) +_encode_path_component_re = re.compile( + "[{}]".format( + "".join( + re.escape(c) + for c in (";", "/", "?", ":", "@", "&", "=", "+", "$", ",", "~") + ) + ) +) + + +def decode_path_component(table_name): + return _decode_path_component_re.sub(lambda m: chr(int(m.group(1), 16)), table_name) + + +def encode_path_component(table_name): + return _encode_path_component_re.sub( + lambda m: "U+{0:0{1}x}".format(ord(m.group(0)), 4).upper(), table_name + ) + + def make_dockerfile( files, metadata_file,