Browse Source

add support for parsing aliases...

main
John-Mark Gurney 5 years ago
parent
commit
692f020e42
2 changed files with 27 additions and 0 deletions
  1. +25
    -0
      casimport/__init__.py
  2. +2
    -0
      fixtures/randpkg/cas_aliases.txt

+ 25
- 0
casimport/__init__.py View File

@@ -124,6 +124,20 @@ class CASFinder(MetaPathFinder, Loader):
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):
self.disconnect() 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): def disconnect(self):
'''Disconnect this Finder from being used to load modules. '''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 # if we try to create a second, it fails
self.assertRaises(RuntimeError, CASFinder) 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): def test_loaderpriority(self):
# XXX - write test to allow you to specify the priority of # XXX - write test to allow you to specify the priority of
# a loader, to ensure that cache stays at top. # a loader, to ensure that cache stays at top.


+ 2
- 0
fixtures/randpkg/cas_aliases.txt View File

@@ -0,0 +1,2 @@
hello hash://sha256/330884aa2febb5e19fb7194ec6a69ed11dd3d77122f1a5175ee93e73cf0161c3?type=text/x-python
hello ipfs://bafkreibtbcckul7lwxqz7nyzj3dknhwrdxj5o4jc6gsroxxjhzz46albym

Loading…
Cancel
Save