diff --git a/casimport/__init__.py b/casimport/__init__.py index 6ddbcd8..a515726 100644 --- a/casimport/__init__.py +++ b/casimport/__init__.py @@ -124,6 +124,20 @@ class CASFinder(MetaPathFinder, Loader): def __exit__(self, exc_type, exc_value, traceback): self.disconnect() + @staticmethod + def _parsealiases(data): + ret = {} + + lines = data.split('\n') + for i in lines: + if not i: + continue + + name, hash = i.split() + ret.setdefault(name, []).append(hash) + + return ret + def disconnect(self): '''Disconnect this Finder from being used to load modules. @@ -276,6 +290,17 @@ class Test(unittest.TestCase): # if we try to create a second, it fails self.assertRaises(RuntimeError, CASFinder) + def test_parsealiases(self): + with open(self.fixtures / 'randpkg' / 'cas_aliases.txt') as fp: + aliasdata = fp.read() + res = CASFinder._parsealiases(aliasdata) + self.assertEqual(res, { + 'hello': [ + 'hash://sha256/330884aa2febb5e19fb7194ec6a69ed11dd3d77122f1a5175ee93e73cf0161c3?type=text/x-python', + 'ipfs://bafkreibtbcckul7lwxqz7nyzj3dknhwrdxj5o4jc6gsroxxjhzz46albym', + ] + }) + def test_loaderpriority(self): # XXX - write test to allow you to specify the priority of # a loader, to ensure that cache stays at top. diff --git a/fixtures/randpkg/cas_aliases.txt b/fixtures/randpkg/cas_aliases.txt new file mode 100644 index 0000000..f5dd8e4 --- /dev/null +++ b/fixtures/randpkg/cas_aliases.txt @@ -0,0 +1,2 @@ +hello hash://sha256/330884aa2febb5e19fb7194ec6a69ed11dd3d77122f1a5175ee93e73cf0161c3?type=text/x-python +hello ipfs://bafkreibtbcckul7lwxqz7nyzj3dknhwrdxj5o4jc6gsroxxjhzz46albym