Fix faulty module name in test, enforce cursor on have
This commit is contained in:
parent
6768bd326d
commit
9981ff277f
@ -1,2 +1,4 @@
|
||||
- 0.0.2
|
||||
* Fix rename module name errors
|
||||
- 0.0.1
|
||||
* Add bases states and aliases
|
||||
|
27
setup.cfg
Normal file
27
setup.cfg
Normal file
@ -0,0 +1,27 @@
|
||||
[metadata]
|
||||
name = shep
|
||||
version = 0.0.1
|
||||
description = Multi-state key value stores using bitmaskings
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
url = https://git.defalsify.org/python-shep
|
||||
keywords =
|
||||
dict
|
||||
queue
|
||||
classifiers =
|
||||
Programming Language :: Python :: 3
|
||||
Operating System :: OS Independent
|
||||
Development Status :: 3 - Alpha
|
||||
Topic :: Software Development :: Libraries
|
||||
Intended Audience :: Developers
|
||||
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
||||
# Topic :: Blockchain :: EVM
|
||||
license = GPL3
|
||||
licence_files =
|
||||
LICENSE
|
||||
|
||||
[options]
|
||||
include_package_data = True
|
||||
python_requires = >= 3.6
|
||||
packages =
|
||||
shep
|
@ -3,7 +3,7 @@ import enum
|
||||
import logging
|
||||
|
||||
# local imports
|
||||
from schiz.error import (
|
||||
from shep.error import (
|
||||
StateExists,
|
||||
StateInvalid,
|
||||
)
|
||||
@ -44,30 +44,25 @@ class State:
|
||||
return k
|
||||
|
||||
|
||||
def __check_cover(self, v):
|
||||
z = 0
|
||||
c = 1
|
||||
for i in range(self.__bits):
|
||||
if c & v > 0:
|
||||
if self.__reverse.get(c) == None:
|
||||
raise StateInvalid(v)
|
||||
c <<= 1
|
||||
return c == v
|
||||
|
||||
|
||||
def __check_value(self, v):
|
||||
def __check_valid(self, v):
|
||||
v = int(v)
|
||||
if self.__reverse.get(v):
|
||||
raise StateValueExists(v)
|
||||
return v
|
||||
|
||||
|
||||
def __check_value(self, v):
|
||||
v = self.__check_valid(v)
|
||||
if v > self.__limit:
|
||||
raise OverflowError(v)
|
||||
return v
|
||||
|
||||
|
||||
def __check(self, k, v):
|
||||
k = self.__check_name(k)
|
||||
v = self.__check_value(v)
|
||||
return (k, v,)
|
||||
def __check_value_cursor(self, v):
|
||||
v = self.__check_valid(v)
|
||||
if v > 1 << self.__c:
|
||||
raise StateInvalid(v)
|
||||
return v
|
||||
|
||||
|
||||
def __set(self, k, v):
|
||||
@ -78,15 +73,16 @@ class State:
|
||||
|
||||
def add(self, k):
|
||||
v = 1 << self.__c
|
||||
(k, v) = self.__check(k, v)
|
||||
k = self.__check_name(k)
|
||||
v = self.__check_value(v)
|
||||
self.__set(k, v)
|
||||
|
||||
|
||||
def alias(self, k, v):
|
||||
(k, v) = self.__check(k, v)
|
||||
k = self.__check_name(k)
|
||||
v = self.__check_value_cursor(v)
|
||||
if self.__is_pure(v):
|
||||
raise ValueError('use add to add pure values')
|
||||
self.__check_cover(v)
|
||||
self.__set(k, v)
|
||||
|
||||
|
||||
@ -100,3 +96,19 @@ class State:
|
||||
l.append(k)
|
||||
l.sort()
|
||||
return l
|
||||
|
||||
|
||||
def have(self, v):
|
||||
r = []
|
||||
m = self.__reverse.get(k)
|
||||
if m != None:
|
||||
r.append(m)
|
||||
c = 1
|
||||
for i in range(self.__bits):
|
||||
if v & c > 0:
|
||||
self.__check_value_cursor(c)
|
||||
k = self.__reverse[c]
|
||||
r.append(k)
|
||||
c <<= 1
|
||||
|
||||
return r
|
@ -2,8 +2,8 @@
|
||||
import unittest
|
||||
|
||||
# local imports
|
||||
from schiz import State
|
||||
from schiz.error import (
|
||||
from shep import State
|
||||
from shep.error import (
|
||||
StateExists,
|
||||
StateInvalid,
|
||||
)
|
||||
|
@ -2,8 +2,8 @@
|
||||
import unittest
|
||||
|
||||
# local imports
|
||||
from schiz import State
|
||||
from schiz.error import (
|
||||
from shep import State
|
||||
from shep.error import (
|
||||
StateExists,
|
||||
StateInvalid,
|
||||
)
|
||||
@ -65,7 +65,7 @@ class TestState(unittest.TestCase):
|
||||
def test_alias_nopure(self):
|
||||
states = State(3)
|
||||
with self.assertRaises(ValueError):
|
||||
states.alias('foo', 4)
|
||||
states.alias('foo', 1)
|
||||
|
||||
|
||||
def test_alias_cover(self):
|
||||
|
Loading…
Reference in New Issue
Block a user