wheepy 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wheepy-0.0.3/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
+ Version 2, December 2004
3
+
4
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
5
+
6
+ Everyone is permitted to copy and distribute verbatim or modified
7
+ copies of this license document, and changing it is allowed as long
8
+ as the name is changed.
9
+
10
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+
13
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
14
+
wheepy-0.0.3/PKG-INFO ADDED
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: wheepy
3
+ Version: 0.0.3
4
+ Summary: Unified interface to key value with locking and transactions.
5
+ Home-page: https://holbrook.no/src/whee/
6
+ Author: Louis Holbrook
7
+ Author-email: dev@holbrook.no
8
+ License: WTFPL
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Provides-Extra: couchdb
17
+ Requires-Dist: couchdb~=1.2; extra == "couchdb"
18
+ Provides-Extra: valkey
19
+ Requires-Dist: valkey~=6.1.1; extra == "valkey"
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: description-content-type
23
+ Dynamic: home-page
24
+ Dynamic: license
25
+ Dynamic: license-file
26
+ Dynamic: provides-extra
27
+ Dynamic: summary
wheepy-0.0.3/README.md ADDED
File without changes
wheepy-0.0.3/setup.cfg ADDED
@@ -0,0 +1,14 @@
1
+ [metadata]
2
+ classifiers =
3
+ Programming Language :: Python :: 3
4
+ Operating System :: OS Independent
5
+ Development Status :: 3 - Alpha
6
+ Intended Audience :: Developers
7
+ Topic :: Software Development :: Libraries
8
+ license_files =
9
+ LICENSE
10
+
11
+ [egg_info]
12
+ tag_build =
13
+ tag_date = 0
14
+
wheepy-0.0.3/setup.py ADDED
@@ -0,0 +1,26 @@
1
+ from setuptools import setup
2
+
3
+ f = open('./README.md', 'r')
4
+ long_description = f.read()
5
+ f.close()
6
+
7
+ setup(
8
+ name='wheepy',
9
+ version='0.0.3',
10
+ description='Unified interface to key value with locking and transactions.',
11
+ author='Louis Holbrook',
12
+ author_email='dev@holbrook.no',
13
+ license='WTFPL',
14
+ long_description=long_description,
15
+ long_description_content_type='text/markdown',
16
+ extras_require={
17
+ 'couchdb': ['couchdb~=1.2'],
18
+ 'valkey': ['valkey~=6.1.1'],
19
+ },
20
+ packages=[
21
+ 'whee',
22
+ 'whee.couchdb',
23
+ 'whee.valkey',
24
+ ],
25
+ url='https://holbrook.no/src/whee/',
26
+ )
@@ -0,0 +1,20 @@
1
+ import logging
2
+ import unittest
3
+
4
+ from whee.couchdb import CouchDBStore
5
+
6
+ logging.basicConfig(level=logging.DEBUG)
7
+ logg = logging.getLogger()
8
+
9
+ class TestCouchDB(unittest.TestCase):
10
+
11
+ def setUp(self):
12
+ self.store = CouchDBStore('test', 'ya0JK6)hp')
13
+
14
+
15
+ def test_get_put(self):
16
+ pass
17
+
18
+
19
+ if __name__ == '__main__':
20
+ unittest.main()
@@ -0,0 +1,35 @@
1
+ import logging
2
+ import unittest
3
+
4
+ from whee.mem import MemStore
5
+
6
+ logging.basicConfig(level=logging.DEBUG)
7
+ logg = logging.getLogger()
8
+
9
+
10
+ class TestMem(unittest.TestCase):
11
+
12
+ def setUp(self):
13
+ self.store = MemStore()
14
+
15
+
16
+ def test_get_put(self):
17
+ r = self.store.have(b'foo')
18
+ self.assertFalse(r)
19
+ self.store.put(b'foo', b'bar')
20
+ r = self.store.have(b'foo')
21
+ self.assertTrue(r)
22
+ r = self.store.get(b'foo')
23
+ self.assertEqual(r, b'bar')
24
+ r = self.store.get(b'foo'.hex())
25
+ self.assertEqual(r, b'bar')
26
+ with self.assertRaises(FileExistsError):
27
+ self.store.put(b'foo', b'baz')
28
+ self.store.put(b'foo', b'baz', exist_ok=True)
29
+ self.store.delete(b'foo')
30
+ with self.assertRaises(FileNotFoundError):
31
+ self.store.delete(b'foo')
32
+
33
+
34
+ if __name__ == '__main__':
35
+ unittest.main()
@@ -0,0 +1,38 @@
1
+ import logging
2
+ import unittest
3
+
4
+ from whee.valkey import ValkeyStore
5
+
6
+ logging.basicConfig(level=logging.DEBUG)
7
+ logg = logging.getLogger()
8
+
9
+ class TestValkey(unittest.TestCase):
10
+
11
+ def setUp(self):
12
+ self.store = ValkeyStore(124)
13
+
14
+ def test_get_put(self):
15
+ # remove the initial delete once we are creating temporary test dbs
16
+ try:
17
+ self.store.delete(b'foo')
18
+ except:
19
+ pass
20
+ r = self.store.have(b'foo')
21
+ self.assertFalse(r)
22
+ self.store.put(b'foo', b'bar')
23
+ r = self.store.have(b'foo')
24
+ self.assertTrue(r)
25
+ r = self.store.get(b'foo')
26
+ self.assertEqual(r, b'bar')
27
+ r = self.store.get(b'foo'.hex())
28
+ self.assertEqual(r, b'bar')
29
+ with self.assertRaises(FileExistsError):
30
+ self.store.put(b'foo', b'baz')
31
+ self.store.put(b'foo', b'baz', exist_ok=True)
32
+ self.store.delete(b'foo')
33
+ with self.assertRaises(FileNotFoundError):
34
+ self.store.delete(b'foo')
35
+
36
+
37
+ if __name__ == '__main__':
38
+ unittest.main()
@@ -0,0 +1,29 @@
1
+ from .base import Interface
2
+
3
+
4
+ def ensure_hex_key(v):
5
+ """Return hex for bytes, or verify valid hex.
6
+
7
+ :param v: Value to check or convert.
8
+ :type v: bytes or str
9
+ :raises: ValueError if invalid hexadecimal value (and not bytes).
10
+ :returns: Corresponding hexadecimal data.
11
+ :rtype: str
12
+ """
13
+ if isinstance(v, bytes):
14
+ return v.hex()
15
+ bytes.fromhex(v)
16
+ return v
17
+
18
+
19
+ def ensure_bytes_key(v):
20
+ """Return bytes key if hex is given.
21
+
22
+ :param v: Value to check or convert.
23
+ :type v: bytes or str
24
+ :returns: Corresponding bytes data
25
+ :rtype: bytes
26
+ """
27
+ if isinstance(v, bytes):
28
+ return v
29
+ return bytes.fromhex(v)
@@ -0,0 +1,104 @@
1
+ class Interface:
2
+ """This is Interface class abstracts transactional store operations on key-value-based backends.
3
+ """
4
+
5
+ def get(self, k):
6
+ """Retrieve value for key.
7
+
8
+ :raises: FileNotFoundError if key does not exist.
9
+ :raises: ConnectionRefusedError if store is locked.
10
+ :raises: IOError if key is found but read fails for any reason.
11
+ :returns: Value
12
+ :rtype: bytes
13
+ """
14
+ raise NotImplementedError()
15
+
16
+
17
+ def put(self, k, v, exist_ok=False):
18
+ """Retrieve value for key.
19
+
20
+ :raises: ValueError if value is in a format that cannot be stored.
21
+ :raises: ConnectionRefusedError if store is locked.
22
+ :raises: FileExistsError if key already exists and exist_ok is not True.
23
+ :raises: IOError if value is valid and key is available, but write fails for any other reason.
24
+ :returns: Value
25
+ :rtype: bytes
26
+ """
27
+ raise NotImplementedError()
28
+
29
+
30
+ def have(self, k):
31
+ """Check if key exists in store.
32
+
33
+ :raises: FileNotFoundError if key does not exist.
34
+ :raises: ConnectionRefusedError if store is locked.
35
+ :raises: IOError if value is valid and key is available, but write fails for any other reason.
36
+ """
37
+ raise NotImplementedError()
38
+
39
+
40
+ def start(self):
41
+ """Start a store transaction.
42
+
43
+ :raises: ConnectionError if the transaction cannot be made due to missing connection with the backend.
44
+ :raises: ConnectionRefusedError if store is locked.
45
+ :raises: PermissionError if a transaction is already in place, and/or the backend does not support (multiple) transactions.
46
+ :raises: IOError if lock cannot be placed for any other reason.
47
+ """
48
+ raise NotImplementedError()
49
+
50
+
51
+ def stop(self):
52
+ """Commit and end a store transaction.
53
+
54
+ :raises: ConnectionError if no transaction exists.
55
+ :raises: ConnectionRefusedError if store is locked.
56
+ :raises: ConnectionAbortedError if transaction could not be committed. After this, the transaction has been dropped.
57
+ :raises: IOError if transaction abort fails for any reason (transaction will still be pending).
58
+ """
59
+ raise NotImplementedError()
60
+
61
+
62
+ def delete(self, k):
63
+ """Delete key and its corresponding value. This action is not reversible.
64
+
65
+ :raises: FileNotFoundError if key does not exist.
66
+ :raises: ConnectionRefusedError if store is locked.
67
+ :raises: IOError if key is valid but operation fails for any other reason.
68
+ """
69
+ raise NotImplementedError()
70
+
71
+
72
+ def lock(self):
73
+ """Lock the store for any operation by any process.
74
+
75
+ :raises: ConnectionRefusedError if store is already locked.
76
+ :raises: IOError if lock fails for any other reason.
77
+ """
78
+ raise NotImplementedError()
79
+
80
+
81
+ def abort(self):
82
+ """Stop a store transaction without committing.
83
+
84
+ :raises: ConnectionError if no transaction exists.
85
+ :raises: ConnectionRefusedError if store is locked.
86
+ :raises: IOError if transaction abort fails for any reason (transaction will still be pending).
87
+ """
88
+ raise NotImplementedError()
89
+
90
+
91
+ def flush(self):
92
+ """Write changes to store and unlock.
93
+
94
+ :raises: IOError if write fails for any reason.
95
+ """
96
+ raise NotImplementedError()
97
+
98
+
99
+ def cap(self):
100
+ """Return bytes available for storage.
101
+
102
+ :raises: IOError if query fails for any reason.
103
+ """
104
+ return 0
@@ -0,0 +1,33 @@
1
+ import logging
2
+
3
+ import couchdb
4
+
5
+ from whee import Interface, ensure_hex_key
6
+
7
+ logg = logging.getLogger('whee.couchdb')
8
+
9
+
10
+ class CouchDBStore(Interface):
11
+ """Implements whee.Interface for Apache CouchDB
12
+ """
13
+
14
+ dbname_prefix = 'whee-'
15
+
16
+ def __init__(self, dbname, passphrase, user='admin', host='localhost', port=5984, ssl=False):
17
+ self.dbname = self.dbname_prefix + dbname
18
+ connstr = 'http'
19
+ if ssl:
20
+ connstr += 's'
21
+ connstr += '://'
22
+ connstr += '{}:{}@{}:{}/'.format(user, passphrase, host, port)
23
+ self.conn = couchdb.Server(connstr)
24
+ try:
25
+ self.db = self.conn.create(self.dbname)
26
+ except couchdb.http.PreconditionFailed:
27
+ self.db = self.conn[self.dbname]
28
+
29
+
30
+ def get(self, k):
31
+ #try:
32
+ # self.db.find('selector': {'type': 'wheekv'},
33
+ pass
@@ -0,0 +1,55 @@
1
+ import logging
2
+
3
+ from whee import Interface, ensure_hex_key
4
+
5
+ logg = logging.getLogger('memstore')
6
+
7
+
8
+ class MemStore(Interface):
9
+ """Memstore implements the whee.Interface for python dicts in in-process memory.
10
+ """
11
+
12
+ def __init__(self):
13
+ self.v = {}
14
+ self.__to_store_key = ensure_hex_key
15
+
16
+
17
+ def have(self, k):
18
+ k = self.__to_store_key(k)
19
+ return bool(self.v.get(k))
20
+
21
+
22
+ def get(self, k):
23
+ k = self.__to_store_key(k)
24
+ r = self.v.get(k)
25
+ if r == None:
26
+ raise FileNotFoundError()
27
+ logg.debug('memstore get {} -> {}'.format(k, r))
28
+ return r
29
+
30
+
31
+ def put(self, k, v, exist_ok=False):
32
+ k = self.__to_store_key(k)
33
+ if self.have(k):
34
+ if not exist_ok:
35
+ raise FileExistsError()
36
+ logg.debug('memstore put (replace) {} <- {}'.format(k, v))
37
+ else:
38
+ logg.debug('memstore put {} <- {}'.format(k, v))
39
+ self.v[k] = v
40
+
41
+
42
+ def delete(self, k):
43
+ k = self.__to_store_key(k)
44
+ if not self.have(k):
45
+ raise FileNotFoundError
46
+ logg.debug('memstore delete {}'.format(k))
47
+ del self.v[k]
48
+
49
+
50
+ def start(self):
51
+ raise PermissionError()
52
+
53
+
54
+ def stop(self):
55
+ raise PermissionError()
@@ -0,0 +1,55 @@
1
+ import logging
2
+
3
+ import valkey
4
+
5
+ from whee import Interface, ensure_bytes_key
6
+
7
+ logg = logging.getLogger('whee.valkey')
8
+
9
+
10
+ class ValkeyStore(Interface):
11
+ """Implements whee.Interface for Valkey
12
+ """
13
+
14
+ dbno_default = 0
15
+
16
+ def __init__(self, passphrase, user=None, host='localhost', port=6379, dbno=None):
17
+ if dbno == None:
18
+ dbno = self.dbno_default
19
+ self.db = valkey.Valkey(host=host, port=port, db=dbno)
20
+ if user != None:
21
+ self.db.auth(user, passphrase)
22
+ self.db.ping()
23
+
24
+
25
+ def have(self, k):
26
+ k = ensure_bytes_key(k)
27
+ return bool(self.db.get(k))
28
+
29
+
30
+ def get(self, k):
31
+ k = ensure_bytes_key(k)
32
+ r = self.db.get(k)
33
+ if r == None:
34
+ raise FileNotFoundError()
35
+ logg.debug('valkeystore get {} -> {}'.format(k, r))
36
+ return r
37
+
38
+
39
+ def put(self, k, v, exist_ok=False):
40
+ k = ensure_bytes_key(k)
41
+ if self.have(k):
42
+ if not exist_ok:
43
+ raise FileExistsError()
44
+ logg.debug('valkeystore put (replace) {} <- {}'.format(k, v))
45
+ else:
46
+ logg.debug('valkeystore put {} <- {}'.format(k, v))
47
+ self.db.set(k, v)
48
+
49
+
50
+ def delete(self, k):
51
+ k = ensure_bytes_key(k)
52
+ if not self.have(k):
53
+ raise FileNotFoundError
54
+ logg.debug('valkeystore delete {}'.format(k))
55
+ self.db.delete(k)
@@ -0,0 +1,27 @@
1
+ Metadata-Version: 2.4
2
+ Name: wheepy
3
+ Version: 0.0.3
4
+ Summary: Unified interface to key value with locking and transactions.
5
+ Home-page: https://holbrook.no/src/whee/
6
+ Author: Louis Holbrook
7
+ Author-email: dev@holbrook.no
8
+ License: WTFPL
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Provides-Extra: couchdb
17
+ Requires-Dist: couchdb~=1.2; extra == "couchdb"
18
+ Provides-Extra: valkey
19
+ Requires-Dist: valkey~=6.1.1; extra == "valkey"
20
+ Dynamic: author
21
+ Dynamic: author-email
22
+ Dynamic: description-content-type
23
+ Dynamic: home-page
24
+ Dynamic: license
25
+ Dynamic: license-file
26
+ Dynamic: provides-extra
27
+ Dynamic: summary
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ README.md
3
+ setup.cfg
4
+ setup.py
5
+ tests/test_couchdb.py
6
+ tests/test_mem.py
7
+ tests/test_valkey.py
8
+ whee/__init__.py
9
+ whee/base.py
10
+ whee/mem.py
11
+ whee/couchdb/__init__.py
12
+ whee/valkey/__init__.py
13
+ wheepy.egg-info/PKG-INFO
14
+ wheepy.egg-info/SOURCES.txt
15
+ wheepy.egg-info/dependency_links.txt
16
+ wheepy.egg-info/requires.txt
17
+ wheepy.egg-info/top_level.txt
@@ -0,0 +1,6 @@
1
+
2
+ [couchdb]
3
+ couchdb~=1.2
4
+
5
+ [valkey]
6
+ valkey~=6.1.1
@@ -0,0 +1 @@
1
+ whee