naming refactoring
This commit is contained in:
parent
547b233c97
commit
db1c8ab9aa
@ -3,7 +3,7 @@ from typing import Generic, Iterable, TypeVar
|
||||
from nacl.bindings import crypto_hash_sha256
|
||||
from nacl.secret import SecretBox
|
||||
|
||||
from rainbowadn.hashing.hashmentionable import HashMentionable
|
||||
from rainbowadn.hashing.mentionable import Mentionable
|
||||
from rainbowadn.hashing.hashpoint import HashPoint
|
||||
from rainbowadn.hashing.hashresolver import HashResolver
|
||||
from rainbowadn.hashing.origin import Origin
|
||||
@ -29,7 +29,7 @@ class Encrypted(RecursiveMentionable, Generic[EncryptedType]):
|
||||
assert isinstance(key, bytes)
|
||||
assert isinstance(resolution, tuple)
|
||||
assert isinstance(mapping, dict)
|
||||
assert isinstance(decrypted, HashMentionable)
|
||||
assert isinstance(decrypted, Mentionable)
|
||||
|
||||
self.factory: RainbowFactory[EncryptedType] = decrypted.__factory__()
|
||||
self.key = key
|
||||
@ -196,7 +196,8 @@ class ShortcutResolver(HashResolver):
|
||||
|
||||
def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']:
|
||||
assert isinstance(point, bytes)
|
||||
resolved: Encrypted = self.mapping[point].resolve()
|
||||
return (
|
||||
HashPoint.bytes_of_mentioned(self.mapping[point].resolve()),
|
||||
ShortcutResolver(self.mapping[point].resolve())
|
||||
HashPoint.bytes_of_mentioned(resolved),
|
||||
ShortcutResolver(resolved)
|
||||
)
|
||||
|
@ -1,15 +1,14 @@
|
||||
import hashlib
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from rainbowadn.hashing.hashmentionable import HashMentionable
|
||||
from rainbowadn.hashing.mentionable import Mentionable
|
||||
from rainbowadn.hashing.localorigin import LocalOrigin
|
||||
from rainbowadn.hashing.origin import Origin
|
||||
from rainbowadn.hashing.rainbow_factory import RainbowFactory
|
||||
|
||||
__all__ = ('HashPoint',)
|
||||
|
||||
HashMentioned = TypeVar('HashMentioned')
|
||||
ReHashMentioned = TypeVar('ReHashMentioned')
|
||||
Mentioned = TypeVar('Mentioned')
|
||||
|
||||
|
||||
def _hash(source: bytes) -> bytes:
|
||||
@ -17,11 +16,11 @@ def _hash(source: bytes) -> bytes:
|
||||
return hashlib.sha256(source).digest()
|
||||
|
||||
|
||||
class HashPoint(Generic[HashMentioned]):
|
||||
class HashPoint(Generic[Mentioned]):
|
||||
def __init__(
|
||||
self,
|
||||
point: bytes,
|
||||
origin: Origin[HashMentioned]
|
||||
origin: Origin[Mentioned]
|
||||
):
|
||||
assert isinstance(point, bytes)
|
||||
assert isinstance(origin, Origin)
|
||||
@ -43,23 +42,23 @@ class HashPoint(Generic[HashMentioned]):
|
||||
return _hash(source)
|
||||
|
||||
@classmethod
|
||||
def bytes_of_mentioned(cls, mentioned: HashMentionable):
|
||||
assert isinstance(mentioned, HashMentionable)
|
||||
def bytes_of_mentioned(cls, mentioned: Mentionable):
|
||||
assert isinstance(mentioned, Mentionable)
|
||||
topology_hash: bytes = mentioned.__topology_hash__()
|
||||
assert isinstance(topology_hash, bytes)
|
||||
assert len(topology_hash) == cls.HASH_LENGTH
|
||||
return topology_hash + bytes(mentioned)
|
||||
|
||||
@classmethod
|
||||
def of(cls, mentioned: HashMentioned) -> 'HashPoint[HashMentioned]':
|
||||
assert isinstance(mentioned, HashMentionable)
|
||||
def of(cls, mentioned: Mentioned) -> 'HashPoint[Mentioned]':
|
||||
assert isinstance(mentioned, Mentionable)
|
||||
return cls(
|
||||
cls.hash(cls.bytes_of_mentioned(mentioned)), LocalOrigin(mentioned)
|
||||
)
|
||||
|
||||
def resolve(self) -> HashMentioned:
|
||||
def resolve(self) -> Mentioned:
|
||||
resolved = self.origin.resolve()
|
||||
assert isinstance(resolved, HashMentionable)
|
||||
assert isinstance(resolved, Mentionable)
|
||||
assert self.point == self.hash(self.bytes_of_mentioned(resolved))
|
||||
return resolved
|
||||
|
||||
|
@ -1,9 +1,5 @@
|
||||
from typing import TypeVar
|
||||
|
||||
__all__ = ('HashResolver',)
|
||||
|
||||
RHashMentioned = TypeVar('RHashMentioned')
|
||||
|
||||
|
||||
class HashResolver:
|
||||
def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']:
|
||||
|
@ -7,15 +7,15 @@ from rainbowadn.hashing.rainbow_factory import RainbowFactory
|
||||
|
||||
__all__ = ('LocalMetaOrigin',)
|
||||
|
||||
OriginType = TypeVar('OriginType')
|
||||
Mentioned = TypeVar('Mentioned')
|
||||
|
||||
|
||||
class LocalMetaOrigin(MetaOrigin[OriginType], Generic[OriginType]):
|
||||
def __init__(self, origin: Origin[OriginType]):
|
||||
class LocalMetaOrigin(MetaOrigin[Mentioned], Generic[Mentioned]):
|
||||
def __init__(self, origin: Origin[Mentioned]):
|
||||
assert isinstance(origin, Origin)
|
||||
self._origin = origin
|
||||
|
||||
def origin(self, factory: RainbowFactory[OriginType], point: bytes) -> Origin[OriginType]:
|
||||
def origin(self, factory: RainbowFactory[Mentioned], point: bytes) -> Origin[Mentioned]:
|
||||
assert isinstance(factory, RainbowFactory)
|
||||
assert isinstance(point, bytes)
|
||||
assert len(point) == HashPoint.HASH_LENGTH
|
||||
|
@ -1,18 +1,18 @@
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from rainbowadn.hashing.hashmentionable import HashMentionable
|
||||
from rainbowadn.hashing.mentionable import Mentionable
|
||||
from rainbowadn.hashing.origin import Origin
|
||||
|
||||
__all__ = ('LocalOrigin',)
|
||||
|
||||
OriginType = TypeVar('OriginType')
|
||||
Mentioned = TypeVar('Mentioned')
|
||||
|
||||
|
||||
class LocalOrigin(Origin[OriginType], Generic[OriginType]):
|
||||
def __init__(self, value: OriginType):
|
||||
assert isinstance(value, HashMentionable)
|
||||
class LocalOrigin(Origin[Mentioned], Generic[Mentioned]):
|
||||
def __init__(self, value: Mentioned):
|
||||
assert isinstance(value, Mentionable)
|
||||
super().__init__(value.__factory__())
|
||||
self.value: OriginType = value
|
||||
self.value: Mentioned = value
|
||||
|
||||
def resolve(self) -> OriginType:
|
||||
def resolve(self) -> Mentioned:
|
||||
return self.value
|
||||
|
@ -2,16 +2,16 @@ from typing import TypeVar
|
||||
|
||||
from rainbowadn.hashing.rainbow_factory import RainbowFactory
|
||||
|
||||
__all__ = ('HashMentionable',)
|
||||
__all__ = ('Mentionable',)
|
||||
|
||||
HashMentioned = TypeVar('HashMentioned')
|
||||
Mentioned = TypeVar('Mentioned')
|
||||
|
||||
|
||||
class HashMentionable:
|
||||
class Mentionable:
|
||||
def __bytes__(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def __factory__(self: HashMentioned) -> RainbowFactory[HashMentioned]:
|
||||
def __factory__(self: Mentioned) -> RainbowFactory[Mentioned]:
|
||||
raise NotImplementedError
|
||||
|
||||
def __topology_hash__(self) -> bytes:
|
@ -6,14 +6,14 @@ from rainbowadn.hashing.rainbow_factory import RainbowFactory
|
||||
|
||||
__all__ = ('MetaOrigin',)
|
||||
|
||||
OriginType = TypeVar('OriginType')
|
||||
Mentioned = TypeVar('Mentioned')
|
||||
|
||||
|
||||
class MetaOrigin(Generic[OriginType]):
|
||||
def origin(self, factory: RainbowFactory[OriginType], point: bytes) -> Origin[OriginType]:
|
||||
class MetaOrigin(Generic[Mentioned]):
|
||||
def origin(self, factory: RainbowFactory[Mentioned], point: bytes) -> Origin[Mentioned]:
|
||||
raise NotImplementedError
|
||||
|
||||
def hash_point(self, factory: RainbowFactory[OriginType], point: bytes) -> HashPoint[OriginType]:
|
||||
def hash_point(self, factory: RainbowFactory[Mentioned], point: bytes) -> HashPoint[Mentioned]:
|
||||
assert isinstance(factory, RainbowFactory)
|
||||
assert isinstance(point, bytes)
|
||||
assert len(point) == HashPoint.HASH_LENGTH
|
||||
|
@ -4,12 +4,12 @@ from rainbowadn.hashing.rainbow_factory import RainbowFactory
|
||||
|
||||
__all__ = ('Origin',)
|
||||
|
||||
OriginType = TypeVar('OriginType')
|
||||
Mentioned = TypeVar('Mentioned')
|
||||
|
||||
|
||||
class Origin(Generic[OriginType]):
|
||||
def __init__(self, factory: RainbowFactory[OriginType]):
|
||||
class Origin(Generic[Mentioned]):
|
||||
def __init__(self, factory: RainbowFactory[Mentioned]):
|
||||
self.factory = factory
|
||||
|
||||
def resolve(self) -> OriginType:
|
||||
def resolve(self) -> Mentioned:
|
||||
raise NotImplementedError
|
||||
|
@ -4,11 +4,11 @@ from rainbowadn.hashing.hashresolver import HashResolver
|
||||
|
||||
__all__ = ('RainbowFactory',)
|
||||
|
||||
FHashMentioned = TypeVar('FHashMentioned')
|
||||
Mentioned = TypeVar('Mentioned')
|
||||
|
||||
|
||||
class RainbowFactory(Generic[FHashMentioned]):
|
||||
class RainbowFactory(Generic[Mentioned]):
|
||||
"""вперёд, уроды, вас ждут заводы"""
|
||||
|
||||
def from_bytes(self, source: bytes, resolver: HashResolver) -> FHashMentioned:
|
||||
def from_bytes(self, source: bytes, resolver: HashResolver) -> Mentioned:
|
||||
raise NotImplementedError
|
||||
|
@ -1,13 +1,13 @@
|
||||
import abc
|
||||
from typing import Iterable
|
||||
|
||||
from rainbowadn.hashing.hashmentionable import HashMentionable
|
||||
from rainbowadn.hashing.mentionable import Mentionable
|
||||
from rainbowadn.hashing.hashpoint import HashPoint
|
||||
|
||||
__all__ = ('RecursiveMentionable',)
|
||||
|
||||
|
||||
class RecursiveMentionable(HashMentionable, abc.ABC):
|
||||
class RecursiveMentionable(Mentionable, abc.ABC):
|
||||
def points(self) -> Iterable[HashPoint]:
|
||||
raise NotImplementedError
|
||||
|
||||
|
@ -9,20 +9,20 @@ from rainbowadn.hashing.resolverorigin import ResolverOrigin
|
||||
|
||||
__all__ = ('ResolverMetaOrigin',)
|
||||
|
||||
OriginType = TypeVar('OriginType')
|
||||
Mentioned = TypeVar('Mentioned')
|
||||
|
||||
|
||||
class ResolverMetaOrigin(MetaOrigin[OriginType], Generic[OriginType]):
|
||||
class ResolverMetaOrigin(MetaOrigin[Mentioned], Generic[Mentioned]):
|
||||
def __init__(self, resolver: HashResolver):
|
||||
assert isinstance(resolver, HashResolver)
|
||||
self.resolver = resolver
|
||||
|
||||
def origin(self, factory: RainbowFactory[OriginType], point: bytes) -> Origin[OriginType]:
|
||||
def origin(self, factory: RainbowFactory[Mentioned], point: bytes) -> Origin[Mentioned]:
|
||||
assert isinstance(factory, RainbowFactory)
|
||||
assert isinstance(point, bytes)
|
||||
assert len(point) == HashPoint.HASH_LENGTH
|
||||
return ResolverOrigin(factory, point, self.resolver)
|
||||
|
||||
def migrate(self, hash_point: HashPoint[OriginType]) -> HashPoint[OriginType]:
|
||||
def migrate(self, hash_point: HashPoint[Mentioned]) -> HashPoint[Mentioned]:
|
||||
assert isinstance(hash_point, HashPoint)
|
||||
return self.hash_point(hash_point.factory, hash_point.point)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from rainbowadn.hashing.hashmentionable import HashMentionable
|
||||
from rainbowadn.hashing.mentionable import Mentionable
|
||||
from rainbowadn.hashing.hashpoint import HashPoint
|
||||
from rainbowadn.hashing.hashresolver import HashResolver
|
||||
from rainbowadn.hashing.origin import Origin
|
||||
@ -8,13 +8,13 @@ from rainbowadn.hashing.rainbow_factory import RainbowFactory
|
||||
|
||||
__all__ = ('ResolverOrigin',)
|
||||
|
||||
OriginType = TypeVar('OriginType')
|
||||
Mentioned = TypeVar('Mentioned')
|
||||
|
||||
|
||||
class ResolverOrigin(Origin[OriginType], Generic[OriginType]):
|
||||
class ResolverOrigin(Origin[Mentioned], Generic[Mentioned]):
|
||||
def __init__(
|
||||
self,
|
||||
factory: RainbowFactory[OriginType],
|
||||
factory: RainbowFactory[Mentioned],
|
||||
point: bytes,
|
||||
resolver: HashResolver
|
||||
):
|
||||
@ -26,15 +26,15 @@ class ResolverOrigin(Origin[OriginType], Generic[OriginType]):
|
||||
self.resolver = resolver
|
||||
super().__init__(factory)
|
||||
|
||||
def resolve(self) -> OriginType:
|
||||
def resolve(self) -> Mentioned:
|
||||
resolved, resolver = self.resolver.resolve(self.point)
|
||||
assert isinstance(resolved, bytes)
|
||||
assert isinstance(resolver, HashResolver)
|
||||
mentioned: OriginType = self.factory.from_bytes(resolved[HashPoint.HASH_LENGTH:], resolver)
|
||||
assert isinstance(mentioned, HashMentionable)
|
||||
mentioned: Mentioned = self.factory.from_bytes(resolved[HashPoint.HASH_LENGTH:], resolver)
|
||||
assert isinstance(mentioned, Mentionable)
|
||||
assert mentioned.__topology_hash__() == resolved[:HashPoint.HASH_LENGTH]
|
||||
assert self.point == HashPoint.hash(HashPoint.bytes_of_mentioned(mentioned))
|
||||
return mentioned
|
||||
|
||||
def hash_point(self) -> HashPoint[OriginType]:
|
||||
def hash_point(self) -> HashPoint[Mentioned]:
|
||||
return HashPoint(self.point, self)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import abc
|
||||
from typing import Generic, Type, TypeVar
|
||||
|
||||
from rainbowadn.hashing.hashmentionable import HashMentionable
|
||||
from rainbowadn.hashing.mentionable import Mentionable
|
||||
from rainbowadn.hashing.hashresolver import HashResolver
|
||||
from rainbowadn.hashing.rainbow_factory import RainbowFactory
|
||||
|
||||
@ -10,7 +10,7 @@ __all__ = ('StaticMentionable', 'StaticFactory',)
|
||||
StaticMentioned = TypeVar('StaticMentioned')
|
||||
|
||||
|
||||
class StaticMentionable(HashMentionable, abc.ABC):
|
||||
class StaticMentionable(Mentionable, abc.ABC):
|
||||
@classmethod
|
||||
def from_bytes(cls: Type[StaticMentioned], source: bytes, resolver: HashResolver) -> StaticMentioned:
|
||||
raise NotImplementedError
|
||||
|
@ -1,7 +1,7 @@
|
||||
from collections import OrderedDict
|
||||
from typing import MutableMapping
|
||||
|
||||
from rainbowadn.hashing.hashmentionable import HashMentionable
|
||||
from rainbowadn.hashing.mentionable import Mentionable
|
||||
from rainbowadn.hashing.hashpoint import HashPoint
|
||||
from rainbowadn.hashing.hashresolver import HashResolver
|
||||
from rainbowadn.hashing.recursivementionable import RecursiveMentionable
|
||||
@ -20,8 +20,8 @@ class DictResolver(HashResolver):
|
||||
if hash_point.point in self.table:
|
||||
pass
|
||||
else:
|
||||
value: HashMentionable = hash_point.resolve()
|
||||
assert isinstance(value, HashMentionable)
|
||||
value: Mentionable = hash_point.resolve()
|
||||
assert isinstance(value, Mentionable)
|
||||
self.table[hash_point.point] = HashPoint.bytes_of_mentioned(value)
|
||||
if isinstance(value, RecursiveMentionable):
|
||||
for hash_point in value.points():
|
||||
|
@ -2,7 +2,7 @@ from typing import Iterable
|
||||
|
||||
from rainbowadn.data.atomic.integer import Integer
|
||||
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate
|
||||
from rainbowadn.hashing.hashmentionable import HashMentionable
|
||||
from rainbowadn.hashing.mentionable import Mentionable
|
||||
from rainbowadn.hashing.hashpoint import HashPoint
|
||||
from rainbowadn.hashing.hashresolver import HashResolver
|
||||
from rainbowadn.hashing.localmetaorigin import LocalMetaOrigin
|
||||
@ -94,8 +94,8 @@ class WrisbtRoot(RecursiveMentionable):
|
||||
if exclude.contains(key) or self.contains(key):
|
||||
return self
|
||||
tree = self
|
||||
value: HashMentionable = target.resolve()
|
||||
assert isinstance(value, HashMentionable)
|
||||
value: Mentionable = target.resolve()
|
||||
assert isinstance(value, Mentionable)
|
||||
if isinstance(value, RecursiveMentionable):
|
||||
for hash_point in value.points():
|
||||
tree = tree.index(hash_point, exclude)
|
||||
|
Loading…
Reference in New Issue
Block a user