cache.py (764B)
1 # standard imports 2 import logging 3 from urllib.parse import urlparse 4 5 logg = logging.getLogger(__name__) 6 7 8 def from_cache_spec(chain_spec, s): 9 o = urlparse(s) 10 path = '.' 11 scheme = None 12 if o.scheme == '': 13 scheme = 'file' 14 else: 15 scheme = o.scheme 16 17 if o.path != '': 18 if o.path[0] != '/': 19 path = os.path.join(path, o.path) 20 else: 21 path = o.path 22 23 logg.debug('parsed scheme {} from cache spec'.format(scheme)) 24 25 if scheme == 'file': 26 from eth_cache.store.fs import FileStore 27 return FsStore(chain_spec, cache_root=path) 28 29 if scheme == 'lmdb': 30 from eth_cache.store.lmdb import LmdbStore 31 return LmdbStore(chain_spec, cache_root=path) 32 33 return None