|
|
@@ -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. |
|
|
|