Skip to content

Commit

Permalink
remove reg, since it is not yet compatible with Python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Marczinowski committed Jan 18, 2019
1 parent 22d75b9 commit 6fe2008
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 84 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
simplekv>=0.11.9
uritools
toolz
reg
33 changes: 17 additions & 16 deletions storefact/_store_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@
import os.path

from simplekv.fs import FilesystemStore
import reg


@reg.dispatch(reg.match_key('type'))
def create_store(type, params):
if type in ('azure', 'hazure'):
return _create_store_azure(type, params)
if type in ('hs3', 'boto'):
return _create_store_hs3(type, params)
if type in ('s3'):
return _create_store_s3(type, params)
if type in ('hfs', 'hfile', 'filesystem'):
return _create_store_hfs(type, params)
if type in ('fs', 'file'):
return _create_store_fs(type, params)
if type in ('memory'):
return _create_store_mem(type, params)
if type in ('hmemory'):
return _create_store_hmem(type, params)
if type in ('redis'):
return _create_store_redis(type, params)
raise ValueError('Unknown store type: ' + str(type))


@create_store.register(type='hazure')
@create_store.register(type='azure')
def _create_store_azure(type, params):
from simplekv.net.azurestore import AzureBlockBlobStore
from ._hstores import HAzureBlockBlobStore
Expand Down Expand Up @@ -44,52 +56,41 @@ def _create_store_azure(type, params):
)


@create_store.register(type='hs3')
@create_store.register(type='boto')
def _create_store_hs3(type, params):
from ._boto import _get_s3bucket
from ._hstores import HBotoStore
return HBotoStore(_get_s3bucket(**params))


@create_store.register(type='s3')
def _create_store_s3(type, params):
from simplekv.net.botostore import BotoStore
from ._boto import _get_s3bucket
return BotoStore(_get_s3bucket(**params))


@create_store.register(type='hfs')
@create_store.register(type='hfile')
@create_store.register(type='filesystem')
def _create_store_hfs(type, params):
if params['create_if_missing'] and not os.path.exists(params['path']):
os.makedirs(params['path'])
from ._hstores import HFilesystemStore
return HFilesystemStore(params['path'])


@create_store.register(type='fs')
@create_store.register(type='file')
def _create_store_fs(type, params):
if params['create_if_missing'] and not os.path.exists(params['path']):
os.makedirs(params['path'])
return FilesystemStore(params['path'])


@create_store.register(type='memory')
def _create_store_mem(type, params):
from simplekv.memory import DictStore
return DictStore()


@create_store.register(type='hmemory')
def _create_store_mem(type, params):
def _create_store_hmem(type, params):
from ._hstores import HDictStore
return HDictStore()


@create_store.register(type='redis')
def _create_store_redis(type, params):
from simplekv.memory.redisstore import RedisStore
from redis import StrictRedis
Expand Down
17 changes: 5 additions & 12 deletions storefact/_store_decoration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@

from __future__ import (absolute_import, division, print_function)

import reg
from simplekv.decorator import (URLEncodeKeysDecorator, ReadOnlyDecorator)


@reg.dispatch(reg.match_key('decoratorname', lambda decoratorname, store: decoratorname.split('(')[0]))
def decorate_store(store, decoratorname):
decoratorname_part = decoratorname.split('(')[0]
if decoratorname_part == 'urlencode':
return URLEncodeKeysDecorator(store)
if decoratorname_part == 'readonly':
return ReadOnlyDecorator(store)
raise ValueError('Unknown store decorator: ' + str(decoratorname))


@decorate_store.register(decoratorname='urlencode')
def _urlencode(store, decoratorname):
return URLEncodeKeysDecorator(store)


@decorate_store.register(decoratorname='readonly')
def _readonly(store, decoratorname):
return ReadOnlyDecorator(store)
89 changes: 34 additions & 55 deletions storefact/_urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

import reg
from uritools import urisplit


Expand Down Expand Up @@ -51,62 +50,42 @@ def url2dict(url, raise_on_extra_params=False):
return params


@reg.dispatch(reg.match_key('scheme', lambda scheme, host, port, path, query, userinfo: scheme))
def extract_params(scheme, host, port, path, query, userinfo):
raise ValueError('Unknown storage type "{}"'.format(scheme))


@extract_params.register(scheme='hmemory')
@extract_params.register(scheme='memory')
def extract_params_memory(scheme, host, port, path, query, userinfo):
return {}


@extract_params.register(scheme='hredis')
@extract_params.register(scheme='redis')
def extract_params_redis(scheme, host, port, path, query, userinfo):
path = path[1:] if path.startswith(u'/') else path
params = {'host': host or u'localhost'}
if port:
params['port'] = port
if userinfo:
params['password'] = userinfo
if path:
params['db'] = int(path)
return params

if scheme in ('memory', 'hmemory'):
return {}
if scheme in ('redis', 'hredis'):
path = path[1:] if path.startswith(u'/') else path
params = {'host': host or u'localhost'}
if port:
params['port'] = port
if userinfo:
params['password'] = userinfo
if path:
params['db'] = int(path)
return params
if scheme in ('fs', 'hfs'):
return {'type': scheme, 'path': host + path}
if scheme in ('s3', 'hs3'):
access_key, secret_key = _parse_userinfo(userinfo)
params = {
'host': u'{}:{}'.format(host, port) if port else host,
'access_key': access_key,
'secret_key': secret_key,
'bucket': path[1:],
}
return params
if scheme in ('azure', 'hazure'):
account_name, account_key = _parse_userinfo(userinfo)
params = {
'account_name': account_name,
'account_key': account_key,
'container': host,
}
if u'use_sas' in query:
params['use_sas'] = True
return params

@extract_params.register(scheme='fs')
@extract_params.register(scheme='hfs')
def extract_params_fs(scheme, host, port, path, query, userinfo):
return {'type': scheme, 'path': host + path}


@extract_params.register(scheme='s3')
@extract_params.register(scheme='hs3')
def extract_params_s3(scheme, host, port, path, query, userinfo):
access_key, secret_key = _parse_userinfo(userinfo)
params = {
'host': u'{}:{}'.format(host, port) if port else host,
'access_key': access_key,
'secret_key': secret_key,
'bucket': path[1:],
}
return params


@extract_params.register(scheme='hazure')
@extract_params.register(scheme='azure')
def extract_params_azure(scheme, host, port, path, query, userinfo):
account_name, account_key = _parse_userinfo(userinfo)
params = {
'account_name': account_name,
'account_key': account_key,
'container': host,
}
if u'use_sas' in query:
params['use_sas'] = True
return params
raise ValueError('Unknown storage type "{}"'.format(scheme))


def _parse_userinfo(userinfo):
Expand Down

0 comments on commit 6fe2008

Please sign in to comment.