|
@@ -141,16 +141,19 @@ class HTTPSCAS(object): |
|
|
return urlfetch(url) |
|
|
return urlfetch(url) |
|
|
|
|
|
|
|
|
class IPFSCAS(object): |
|
|
class IPFSCAS(object): |
|
|
gwhost = 'gateway.ipfs.io' |
|
|
|
|
|
gwhost = 'cloudflare-ipfs.com' |
|
|
|
|
|
|
|
|
gwurl = 'https://gateway.ipfs.io/ipfs/' |
|
|
|
|
|
gwurl = 'https://cloudflare-ipfs.com/ipfs/' |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, gw=None): |
|
|
|
|
|
if gw is not None: |
|
|
|
|
|
self.gwurl = gw |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
def fromconfig(cls, conf): |
|
|
def fromconfig(cls, conf): |
|
|
return cls() |
|
|
|
|
|
|
|
|
return cls(conf.get('gateway', None)) |
|
|
|
|
|
|
|
|
def make_url(self, url): |
|
|
def make_url(self, url): |
|
|
return urllib.parse.urlunparse(('https', self.gwhost, |
|
|
|
|
|
'/ipfs/' + url.netloc) + ('', ) * 3) |
|
|
|
|
|
|
|
|
return urllib.parse.urljoin(self.gwurl, url.netloc) |
|
|
|
|
|
|
|
|
def fetch_data(self, url): |
|
|
def fetch_data(self, url): |
|
|
if url.scheme != 'ipfs': |
|
|
if url.scheme != 'ipfs': |
|
@@ -536,6 +539,14 @@ class Test(unittest.TestCase): |
|
|
# and that the second loader is the IPFSCAS |
|
|
# and that the second loader is the IPFSCAS |
|
|
self.assertIsInstance(f._loaders[1], IPFSCAS) |
|
|
self.assertIsInstance(f._loaders[1], IPFSCAS) |
|
|
|
|
|
|
|
|
|
|
|
def test_ipfsgwfromconfig(self): |
|
|
|
|
|
gwurl = 'https://www.example.com/somepath/' |
|
|
|
|
|
ipfsconf = dict(gateway=gwurl) |
|
|
|
|
|
ipfsobj = IPFSCAS.fromconfig(ipfsconf) |
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(ipfsobj.make_url(urllib.parse.urlparse('ipfs://someobj')), |
|
|
|
|
|
'https://www.example.com/somepath/someobj') |
|
|
|
|
|
|
|
|
def test_defaultinit(self): |
|
|
def test_defaultinit(self): |
|
|
temphome = self.tempdir / 'home' |
|
|
temphome = self.tempdir / 'home' |
|
|
temphome.mkdir() |
|
|
temphome.mkdir() |
|
|