Skip to content

Commit

Permalink
enable better keymap configuration to accept kwds such as protocol fo…
Browse files Browse the repository at this point in the history
…r pickler;

comment out test corresponding to issue #53


git-svn-id: svn+ssh://svn.mystic.cacr.caltech.edu/pathos/klepto@974 8bfda07e-5b16-0410-ab1d-fd04ec2748df
  • Loading branch information
mmckerns committed May 30, 2017
1 parent 631fb59 commit 2339ead
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions klepto/keymaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ def __init__(self, typed=False, flat=True, sentinel=NOSENTINEL, **kwds):
self._fasttypes = (int,str,bytes,frozenset,type(None))
except NameError:
self._fasttypes = (int,str,frozenset,type(None))
self._fasttypes = kwds.get('fasttypes', set(self._fasttypes))
self._sorted = kwds.get('sorted', sorted)
self._tuple = kwds.get('tuple', tuple)
self._type = kwds.get('type', type)
self._len = kwds.get('len', len)
self._fasttypes = kwds.pop('fasttypes', set(self._fasttypes))
self._sorted = kwds.pop('sorted', sorted)
self._tuple = kwds.pop('tuple', tuple)
self._type = kwds.pop('type', type)
self._len = kwds.pop('len', len)

# the rest of the kwds are for customizaton of the encoder
self._config = kwds.copy()
return

def __get_outer(self):
Expand Down Expand Up @@ -233,10 +236,10 @@ def __init__(self, typed=False, flat=True, sentinel=NOSENTINEL, **kwds):
return
def encode(self, *args, **kwds):
"""use a flattened scheme for generating a key"""
return hash(keymap.encode(self, *args, **kwds), algorithm=self.__type__)
return hash(keymap.encode(self, *args, **kwds), algorithm=self.__type__, **self._config)
def encrypt(self, *args, **kwds):
"""use a non-flat scheme for generating a key"""
return hash(keymap.encrypt(self, *args, **kwds), algorithm=self.__type__)
return hash(keymap.encrypt(self, *args, **kwds), algorithm=self.__type__, **self._config)

class stringmap(keymap):
"""tool for converting a function's input signature to an unique key
Expand Down Expand Up @@ -272,12 +275,12 @@ def __init__(self, typed=False, flat=True, sentinel=NOSENTINEL, **kwds):
return
def encode(self, *args, **kwds):
"""use a flattened scheme for generating a key"""
return string(keymap.encode(self, *args, **kwds), encoding=self.__type__)
return string(keymap.encode(self, *args, **kwds), encoding=self.__type__, **self._config)
def encrypt(self, *args, **kwds):
"""use a non-flat scheme for generating a key"""
return string(keymap.encrypt(self, *args, **kwds), encoding=self.__type__)
return string(keymap.encrypt(self, *args, **kwds), encoding=self.__type__, **self._config)

class picklemap(keymap):
class picklemap(keymap)
"""tool for converting a function's input signature to an unique key

This keymap serializes objects by pickling the object. Serializing an
Expand All @@ -304,6 +307,7 @@ def __init__(self, typed=False, flat=True, sentinel=NOSENTINEL, **kwds):
Use kelpto.crypto.serializers() to get the names of available picklers.
NOTE: the serializer kwd expects a <module> object, and not a <str>.
'''
kwds['byref'] = kwds.get('byref',True) #XXX: for dill
self.__type__ = kwds.pop('serializer', None)
#XXX: better not convert __type__ to string, so don't __import__ ?
if not isinstance(self.__type__, (str, type(None))):
Expand All @@ -313,10 +317,10 @@ def __init__(self, typed=False, flat=True, sentinel=NOSENTINEL, **kwds):
return
def encode(self, *args, **kwds):
"""use a flattened scheme for generating a key"""
return pickle(keymap.encode(self, *args, **kwds), serializer=self.__type__, byref=True)# for dill # separator=(',',':') for json
return pickle(keymap.encode(self, *args, **kwds), serializer=self.__type__, **self._config) # separator=(',',':') for json
def encrypt(self, *args, **kwds):
"""use a non-flat scheme for generating a key"""
return pickle(keymap.encrypt(self, *args, **kwds), serializer=self.__type__, byref=True)# for dill # separator=(',',':') for json
return pickle(keymap.encrypt(self, *args, **kwds), serializer=self.__type__, **self._config) # separator=(',',':') for json


# EOF
2 changes: 1 addition & 1 deletion tests/test_readwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_archive():

archive = dir_archive(cached=False,serialized=False)
check_basic(archive)
check_numpy(archive)
#check_numpy(archive) #FIXME: see issue #53
rmtree('memo')


Expand Down

0 comments on commit 2339ead

Please sign in to comment.