+# Table of methods used to filter segments before storage, and corresponding
+# filename extensions. These are listed in priority order (methods earlier in
+# the list are tried first).
+SEGMENT_FILTERS = [
+ (".gpg", "cumulus-filter-gpg --decrypt"),
+ (".gz", "gzip -dc"),
+ (".bz2", "bzip2 -dc"),
+]
+
+def uri_decode(s):
+ """Decode a URI-encoded (%xx escapes) string."""
+ def hex_decode(m): return chr(int(m.group(1), 16))
+ return re.sub(r"%([0-9a-f]{2})", hex_decode, s)
+def uri_encode(s):
+ """Encode a string to URI-encoded (%xx escapes) form."""
+ def hex_encode(c):
+ if c > '+' and c < '\x7f' and c != '@':
+ return c
+ else:
+ return "%%%02x" % (ord(c),)
+ return ''.join(hex_encode(c) for c in s)
+