X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=python%2Fcumulus%2F__init__.py;h=424e38c09b56ec96911c4701b98c69ff26b195ed;hb=5d0038c47ba5926b1e3e8713da75078602a06f62;hp=602e70e7b5546c00bdda59fdf5025cfa684a5f57;hpb=8bff41ddef78fa851b09d141c93bdf387abc1dee;p=cumulus.git diff --git a/python/cumulus/__init__.py b/python/cumulus/__init__.py index 602e70e..424e38c 100644 --- a/python/cumulus/__init__.py +++ b/python/cumulus/__init__.py @@ -23,6 +23,19 @@ MAX_RECURSION_DEPTH = 3 # All segments which have been accessed this session. accessed_segments = set() +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) + class Struct: """A class which merely acts as a data container. @@ -84,7 +97,12 @@ class LowlevelDataStore: """ def __init__(self, path): - self.store = cumulus.store.file.FileStore(path) + if isinstance(path, cumulus.store.Store): + self.store = path + elif path.find(":") >= 0: + self.store = cumulus.store.open(path) + else: + self.store = cumulus.store.file.FileStore(path) def _classify(self, filename): for (t, r) in cumulus.store.type_patterns.items(): @@ -344,8 +362,7 @@ class MetadataItem: @staticmethod def decode_str(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) + return uri_decode(s) @staticmethod def raw_str(s):