From 6fe20080f96c92975dfb34bfdef8bfbeaf9c2c30 Mon Sep 17 00:00:00 2001 From: Felix Marczinowski Date: Fri, 18 Jan 2019 18:38:45 +0100 Subject: [PATCH] remove reg, since it is not yet compatible with Python 3.6 --- requirements.txt | 1 - storefact/_store_creation.py | 33 +++++++------ storefact/_store_decoration.py | 17 ++----- storefact/_urls.py | 89 +++++++++++++--------------------- 4 files changed, 56 insertions(+), 84 deletions(-) diff --git a/requirements.txt b/requirements.txt index 27b300b..ac2efc8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ simplekv>=0.11.9 uritools toolz -reg diff --git a/storefact/_store_creation.py b/storefact/_store_creation.py index fe08daf..eed5355 100644 --- a/storefact/_store_creation.py +++ b/storefact/_store_creation.py @@ -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 @@ -44,24 +56,18 @@ 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']) @@ -69,27 +75,22 @@ def _create_store_hfs(type, params): 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 diff --git a/storefact/_store_decoration.py b/storefact/_store_decoration.py index 74d7b1a..b87b212 100644 --- a/storefact/_store_decoration.py +++ b/storefact/_store_decoration.py @@ -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) diff --git a/storefact/_urls.py b/storefact/_urls.py index e80135c..cfb0b97 100644 --- a/storefact/_urls.py +++ b/storefact/_urls.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -import reg from uritools import urisplit @@ -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):