naming refactoring

This commit is contained in:
AF 2022-06-07 20:58:26 +03:00
parent 547b233c97
commit db1c8ab9aa
15 changed files with 63 additions and 67 deletions

View File

@ -3,7 +3,7 @@ from typing import Generic, Iterable, TypeVar
from nacl.bindings import crypto_hash_sha256 from nacl.bindings import crypto_hash_sha256
from nacl.secret import SecretBox 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.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.origin import Origin from rainbowadn.hashing.origin import Origin
@ -29,7 +29,7 @@ class Encrypted(RecursiveMentionable, Generic[EncryptedType]):
assert isinstance(key, bytes) assert isinstance(key, bytes)
assert isinstance(resolution, tuple) assert isinstance(resolution, tuple)
assert isinstance(mapping, dict) assert isinstance(mapping, dict)
assert isinstance(decrypted, HashMentionable) assert isinstance(decrypted, Mentionable)
self.factory: RainbowFactory[EncryptedType] = decrypted.__factory__() self.factory: RainbowFactory[EncryptedType] = decrypted.__factory__()
self.key = key self.key = key
@ -196,7 +196,8 @@ class ShortcutResolver(HashResolver):
def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']: def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']:
assert isinstance(point, bytes) assert isinstance(point, bytes)
resolved: Encrypted = self.mapping[point].resolve()
return ( return (
HashPoint.bytes_of_mentioned(self.mapping[point].resolve()), HashPoint.bytes_of_mentioned(resolved),
ShortcutResolver(self.mapping[point].resolve()) ShortcutResolver(resolved)
) )

View File

@ -1,15 +1,14 @@
import hashlib import hashlib
from typing import Generic, TypeVar 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.localorigin import LocalOrigin
from rainbowadn.hashing.origin import Origin from rainbowadn.hashing.origin import Origin
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('HashPoint',) __all__ = ('HashPoint',)
HashMentioned = TypeVar('HashMentioned') Mentioned = TypeVar('Mentioned')
ReHashMentioned = TypeVar('ReHashMentioned')
def _hash(source: bytes) -> bytes: def _hash(source: bytes) -> bytes:
@ -17,11 +16,11 @@ def _hash(source: bytes) -> bytes:
return hashlib.sha256(source).digest() return hashlib.sha256(source).digest()
class HashPoint(Generic[HashMentioned]): class HashPoint(Generic[Mentioned]):
def __init__( def __init__(
self, self,
point: bytes, point: bytes,
origin: Origin[HashMentioned] origin: Origin[Mentioned]
): ):
assert isinstance(point, bytes) assert isinstance(point, bytes)
assert isinstance(origin, Origin) assert isinstance(origin, Origin)
@ -43,23 +42,23 @@ class HashPoint(Generic[HashMentioned]):
return _hash(source) return _hash(source)
@classmethod @classmethod
def bytes_of_mentioned(cls, mentioned: HashMentionable): def bytes_of_mentioned(cls, mentioned: Mentionable):
assert isinstance(mentioned, HashMentionable) assert isinstance(mentioned, Mentionable)
topology_hash: bytes = mentioned.__topology_hash__() topology_hash: bytes = mentioned.__topology_hash__()
assert isinstance(topology_hash, bytes) assert isinstance(topology_hash, bytes)
assert len(topology_hash) == cls.HASH_LENGTH assert len(topology_hash) == cls.HASH_LENGTH
return topology_hash + bytes(mentioned) return topology_hash + bytes(mentioned)
@classmethod @classmethod
def of(cls, mentioned: HashMentioned) -> 'HashPoint[HashMentioned]': def of(cls, mentioned: Mentioned) -> 'HashPoint[Mentioned]':
assert isinstance(mentioned, HashMentionable) assert isinstance(mentioned, Mentionable)
return cls( return cls(
cls.hash(cls.bytes_of_mentioned(mentioned)), LocalOrigin(mentioned) cls.hash(cls.bytes_of_mentioned(mentioned)), LocalOrigin(mentioned)
) )
def resolve(self) -> HashMentioned: def resolve(self) -> Mentioned:
resolved = self.origin.resolve() resolved = self.origin.resolve()
assert isinstance(resolved, HashMentionable) assert isinstance(resolved, Mentionable)
assert self.point == self.hash(self.bytes_of_mentioned(resolved)) assert self.point == self.hash(self.bytes_of_mentioned(resolved))
return resolved return resolved

View File

@ -1,9 +1,5 @@
from typing import TypeVar
__all__ = ('HashResolver',) __all__ = ('HashResolver',)
RHashMentioned = TypeVar('RHashMentioned')
class HashResolver: class HashResolver:
def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']: def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']:

View File

@ -7,15 +7,15 @@ from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('LocalMetaOrigin',) __all__ = ('LocalMetaOrigin',)
OriginType = TypeVar('OriginType') Mentioned = TypeVar('Mentioned')
class LocalMetaOrigin(MetaOrigin[OriginType], Generic[OriginType]): class LocalMetaOrigin(MetaOrigin[Mentioned], Generic[Mentioned]):
def __init__(self, origin: Origin[OriginType]): def __init__(self, origin: Origin[Mentioned]):
assert isinstance(origin, Origin) assert isinstance(origin, Origin)
self._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(factory, RainbowFactory)
assert isinstance(point, bytes) assert isinstance(point, bytes)
assert len(point) == HashPoint.HASH_LENGTH assert len(point) == HashPoint.HASH_LENGTH

View File

@ -1,18 +1,18 @@
from typing import Generic, TypeVar from typing import Generic, TypeVar
from rainbowadn.hashing.hashmentionable import HashMentionable from rainbowadn.hashing.mentionable import Mentionable
from rainbowadn.hashing.origin import Origin from rainbowadn.hashing.origin import Origin
__all__ = ('LocalOrigin',) __all__ = ('LocalOrigin',)
OriginType = TypeVar('OriginType') Mentioned = TypeVar('Mentioned')
class LocalOrigin(Origin[OriginType], Generic[OriginType]): class LocalOrigin(Origin[Mentioned], Generic[Mentioned]):
def __init__(self, value: OriginType): def __init__(self, value: Mentioned):
assert isinstance(value, HashMentionable) assert isinstance(value, Mentionable)
super().__init__(value.__factory__()) super().__init__(value.__factory__())
self.value: OriginType = value self.value: Mentioned = value
def resolve(self) -> OriginType: def resolve(self) -> Mentioned:
return self.value return self.value

View File

@ -2,16 +2,16 @@ from typing import TypeVar
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('HashMentionable',) __all__ = ('Mentionable',)
HashMentioned = TypeVar('HashMentioned') Mentioned = TypeVar('Mentioned')
class HashMentionable: class Mentionable:
def __bytes__(self): def __bytes__(self):
raise NotImplementedError raise NotImplementedError
def __factory__(self: HashMentioned) -> RainbowFactory[HashMentioned]: def __factory__(self: Mentioned) -> RainbowFactory[Mentioned]:
raise NotImplementedError raise NotImplementedError
def __topology_hash__(self) -> bytes: def __topology_hash__(self) -> bytes:

View File

@ -6,14 +6,14 @@ from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('MetaOrigin',) __all__ = ('MetaOrigin',)
OriginType = TypeVar('OriginType') Mentioned = TypeVar('Mentioned')
class MetaOrigin(Generic[OriginType]): class MetaOrigin(Generic[Mentioned]):
def origin(self, factory: RainbowFactory[OriginType], point: bytes) -> Origin[OriginType]: def origin(self, factory: RainbowFactory[Mentioned], point: bytes) -> Origin[Mentioned]:
raise NotImplementedError 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(factory, RainbowFactory)
assert isinstance(point, bytes) assert isinstance(point, bytes)
assert len(point) == HashPoint.HASH_LENGTH assert len(point) == HashPoint.HASH_LENGTH

View File

@ -4,12 +4,12 @@ from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('Origin',) __all__ = ('Origin',)
OriginType = TypeVar('OriginType') Mentioned = TypeVar('Mentioned')
class Origin(Generic[OriginType]): class Origin(Generic[Mentioned]):
def __init__(self, factory: RainbowFactory[OriginType]): def __init__(self, factory: RainbowFactory[Mentioned]):
self.factory = factory self.factory = factory
def resolve(self) -> OriginType: def resolve(self) -> Mentioned:
raise NotImplementedError raise NotImplementedError

View File

@ -4,11 +4,11 @@ from rainbowadn.hashing.hashresolver import HashResolver
__all__ = ('RainbowFactory',) __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 raise NotImplementedError

View File

@ -1,13 +1,13 @@
import abc import abc
from typing import Iterable from typing import Iterable
from rainbowadn.hashing.hashmentionable import HashMentionable from rainbowadn.hashing.mentionable import Mentionable
from rainbowadn.hashing.hashpoint import HashPoint from rainbowadn.hashing.hashpoint import HashPoint
__all__ = ('RecursiveMentionable',) __all__ = ('RecursiveMentionable',)
class RecursiveMentionable(HashMentionable, abc.ABC): class RecursiveMentionable(Mentionable, abc.ABC):
def points(self) -> Iterable[HashPoint]: def points(self) -> Iterable[HashPoint]:
raise NotImplementedError raise NotImplementedError

View File

@ -9,20 +9,20 @@ from rainbowadn.hashing.resolverorigin import ResolverOrigin
__all__ = ('ResolverMetaOrigin',) __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): def __init__(self, resolver: HashResolver):
assert isinstance(resolver, HashResolver) assert isinstance(resolver, HashResolver)
self.resolver = resolver 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(factory, RainbowFactory)
assert isinstance(point, bytes) assert isinstance(point, bytes)
assert len(point) == HashPoint.HASH_LENGTH assert len(point) == HashPoint.HASH_LENGTH
return ResolverOrigin(factory, point, self.resolver) 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) assert isinstance(hash_point, HashPoint)
return self.hash_point(hash_point.factory, hash_point.point) return self.hash_point(hash_point.factory, hash_point.point)

View File

@ -1,6 +1,6 @@
from typing import Generic, TypeVar 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.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.origin import Origin from rainbowadn.hashing.origin import Origin
@ -8,13 +8,13 @@ from rainbowadn.hashing.rainbow_factory import RainbowFactory
__all__ = ('ResolverOrigin',) __all__ = ('ResolverOrigin',)
OriginType = TypeVar('OriginType') Mentioned = TypeVar('Mentioned')
class ResolverOrigin(Origin[OriginType], Generic[OriginType]): class ResolverOrigin(Origin[Mentioned], Generic[Mentioned]):
def __init__( def __init__(
self, self,
factory: RainbowFactory[OriginType], factory: RainbowFactory[Mentioned],
point: bytes, point: bytes,
resolver: HashResolver resolver: HashResolver
): ):
@ -26,15 +26,15 @@ class ResolverOrigin(Origin[OriginType], Generic[OriginType]):
self.resolver = resolver self.resolver = resolver
super().__init__(factory) super().__init__(factory)
def resolve(self) -> OriginType: def resolve(self) -> Mentioned:
resolved, resolver = self.resolver.resolve(self.point) resolved, resolver = self.resolver.resolve(self.point)
assert isinstance(resolved, bytes) assert isinstance(resolved, bytes)
assert isinstance(resolver, HashResolver) assert isinstance(resolver, HashResolver)
mentioned: OriginType = self.factory.from_bytes(resolved[HashPoint.HASH_LENGTH:], resolver) mentioned: Mentioned = self.factory.from_bytes(resolved[HashPoint.HASH_LENGTH:], resolver)
assert isinstance(mentioned, HashMentionable) assert isinstance(mentioned, Mentionable)
assert mentioned.__topology_hash__() == resolved[:HashPoint.HASH_LENGTH] assert mentioned.__topology_hash__() == resolved[:HashPoint.HASH_LENGTH]
assert self.point == HashPoint.hash(HashPoint.bytes_of_mentioned(mentioned)) assert self.point == HashPoint.hash(HashPoint.bytes_of_mentioned(mentioned))
return mentioned return mentioned
def hash_point(self) -> HashPoint[OriginType]: def hash_point(self) -> HashPoint[Mentioned]:
return HashPoint(self.point, self) return HashPoint(self.point, self)

View File

@ -1,7 +1,7 @@
import abc import abc
from typing import Generic, Type, TypeVar 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.hashresolver import HashResolver
from rainbowadn.hashing.rainbow_factory import RainbowFactory from rainbowadn.hashing.rainbow_factory import RainbowFactory
@ -10,7 +10,7 @@ __all__ = ('StaticMentionable', 'StaticFactory',)
StaticMentioned = TypeVar('StaticMentioned') StaticMentioned = TypeVar('StaticMentioned')
class StaticMentionable(HashMentionable, abc.ABC): class StaticMentionable(Mentionable, abc.ABC):
@classmethod @classmethod
def from_bytes(cls: Type[StaticMentioned], source: bytes, resolver: HashResolver) -> StaticMentioned: def from_bytes(cls: Type[StaticMentioned], source: bytes, resolver: HashResolver) -> StaticMentioned:
raise NotImplementedError raise NotImplementedError

View File

@ -1,7 +1,7 @@
from collections import OrderedDict from collections import OrderedDict
from typing import MutableMapping 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.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.recursivementionable import RecursiveMentionable from rainbowadn.hashing.recursivementionable import RecursiveMentionable
@ -20,8 +20,8 @@ class DictResolver(HashResolver):
if hash_point.point in self.table: if hash_point.point in self.table:
pass pass
else: else:
value: HashMentionable = hash_point.resolve() value: Mentionable = hash_point.resolve()
assert isinstance(value, HashMentionable) assert isinstance(value, Mentionable)
self.table[hash_point.point] = HashPoint.bytes_of_mentioned(value) self.table[hash_point.point] = HashPoint.bytes_of_mentioned(value)
if isinstance(value, RecursiveMentionable): if isinstance(value, RecursiveMentionable):
for hash_point in value.points(): for hash_point in value.points():

View File

@ -2,7 +2,7 @@ from typing import Iterable
from rainbowadn.data.atomic.integer import Integer from rainbowadn.data.atomic.integer import Integer
from rainbowadn.hashing.hash_point_format import hash_point_format, tabulate 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.hashpoint import HashPoint
from rainbowadn.hashing.hashresolver import HashResolver from rainbowadn.hashing.hashresolver import HashResolver
from rainbowadn.hashing.localmetaorigin import LocalMetaOrigin from rainbowadn.hashing.localmetaorigin import LocalMetaOrigin
@ -94,8 +94,8 @@ class WrisbtRoot(RecursiveMentionable):
if exclude.contains(key) or self.contains(key): if exclude.contains(key) or self.contains(key):
return self return self
tree = self tree = self
value: HashMentionable = target.resolve() value: Mentionable = target.resolve()
assert isinstance(value, HashMentionable) assert isinstance(value, Mentionable)
if isinstance(value, RecursiveMentionable): if isinstance(value, RecursiveMentionable):
for hash_point in value.points(): for hash_point in value.points():
tree = tree.index(hash_point, exclude) tree = tree.index(hash_point, exclude)