From db1c8ab9aa5845bf09092e683e6016b3ccb7f5c0 Mon Sep 17 00:00:00 2001 From: timotheyca Date: Tue, 7 Jun 2022 20:58:26 +0300 Subject: [PATCH] naming refactoring --- rainbowadn/encryption/encrypted.py | 9 ++++---- rainbowadn/hashing/hashpoint.py | 21 +++++++++---------- rainbowadn/hashing/hashresolver.py | 4 ---- rainbowadn/hashing/localmetaorigin.py | 8 +++---- rainbowadn/hashing/localorigin.py | 14 ++++++------- .../{hashmentionable.py => mentionable.py} | 8 +++---- rainbowadn/hashing/metaorigin.py | 8 +++---- rainbowadn/hashing/origin.py | 8 +++---- rainbowadn/hashing/rainbow_factory.py | 6 +++--- rainbowadn/hashing/recursivementionable.py | 4 ++-- rainbowadn/hashing/resolvermetaorigin.py | 8 +++---- rainbowadn/hashing/resolverorigin.py | 16 +++++++------- rainbowadn/hashing/static.py | 4 ++-- rainbowadn/testing/dictresolver.py | 6 +++--- rainbowadn/wrisbt/wrisbtroot.py | 6 +++--- 15 files changed, 63 insertions(+), 67 deletions(-) rename rainbowadn/hashing/{hashmentionable.py => mentionable.py} (60%) diff --git a/rainbowadn/encryption/encrypted.py b/rainbowadn/encryption/encrypted.py index da0142c..d8d22bb 100644 --- a/rainbowadn/encryption/encrypted.py +++ b/rainbowadn/encryption/encrypted.py @@ -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) ) diff --git a/rainbowadn/hashing/hashpoint.py b/rainbowadn/hashing/hashpoint.py index 56d034f..48f694a 100644 --- a/rainbowadn/hashing/hashpoint.py +++ b/rainbowadn/hashing/hashpoint.py @@ -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 diff --git a/rainbowadn/hashing/hashresolver.py b/rainbowadn/hashing/hashresolver.py index 8a77dfd..011edd9 100644 --- a/rainbowadn/hashing/hashresolver.py +++ b/rainbowadn/hashing/hashresolver.py @@ -1,9 +1,5 @@ -from typing import TypeVar - __all__ = ('HashResolver',) -RHashMentioned = TypeVar('RHashMentioned') - class HashResolver: def resolve(self, point: bytes) -> tuple[bytes, 'HashResolver']: diff --git a/rainbowadn/hashing/localmetaorigin.py b/rainbowadn/hashing/localmetaorigin.py index adc0fd4..b43c523 100644 --- a/rainbowadn/hashing/localmetaorigin.py +++ b/rainbowadn/hashing/localmetaorigin.py @@ -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 diff --git a/rainbowadn/hashing/localorigin.py b/rainbowadn/hashing/localorigin.py index 1fb9495..d1ff834 100644 --- a/rainbowadn/hashing/localorigin.py +++ b/rainbowadn/hashing/localorigin.py @@ -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 diff --git a/rainbowadn/hashing/hashmentionable.py b/rainbowadn/hashing/mentionable.py similarity index 60% rename from rainbowadn/hashing/hashmentionable.py rename to rainbowadn/hashing/mentionable.py index 4861432..986d51e 100644 --- a/rainbowadn/hashing/hashmentionable.py +++ b/rainbowadn/hashing/mentionable.py @@ -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: diff --git a/rainbowadn/hashing/metaorigin.py b/rainbowadn/hashing/metaorigin.py index 0c93805..cdb0d4a 100644 --- a/rainbowadn/hashing/metaorigin.py +++ b/rainbowadn/hashing/metaorigin.py @@ -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 diff --git a/rainbowadn/hashing/origin.py b/rainbowadn/hashing/origin.py index fe013ec..d96ee87 100644 --- a/rainbowadn/hashing/origin.py +++ b/rainbowadn/hashing/origin.py @@ -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 diff --git a/rainbowadn/hashing/rainbow_factory.py b/rainbowadn/hashing/rainbow_factory.py index 05db69e..d6441fb 100644 --- a/rainbowadn/hashing/rainbow_factory.py +++ b/rainbowadn/hashing/rainbow_factory.py @@ -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 diff --git a/rainbowadn/hashing/recursivementionable.py b/rainbowadn/hashing/recursivementionable.py index 1c4e82b..1278975 100644 --- a/rainbowadn/hashing/recursivementionable.py +++ b/rainbowadn/hashing/recursivementionable.py @@ -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 diff --git a/rainbowadn/hashing/resolvermetaorigin.py b/rainbowadn/hashing/resolvermetaorigin.py index d864153..391431c 100644 --- a/rainbowadn/hashing/resolvermetaorigin.py +++ b/rainbowadn/hashing/resolvermetaorigin.py @@ -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) diff --git a/rainbowadn/hashing/resolverorigin.py b/rainbowadn/hashing/resolverorigin.py index 8645c98..c74eb37 100644 --- a/rainbowadn/hashing/resolverorigin.py +++ b/rainbowadn/hashing/resolverorigin.py @@ -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) diff --git a/rainbowadn/hashing/static.py b/rainbowadn/hashing/static.py index 4cd989a..b5678e3 100644 --- a/rainbowadn/hashing/static.py +++ b/rainbowadn/hashing/static.py @@ -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 diff --git a/rainbowadn/testing/dictresolver.py b/rainbowadn/testing/dictresolver.py index 79cbacc..2f8d354 100644 --- a/rainbowadn/testing/dictresolver.py +++ b/rainbowadn/testing/dictresolver.py @@ -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(): diff --git a/rainbowadn/wrisbt/wrisbtroot.py b/rainbowadn/wrisbt/wrisbtroot.py index 1f0ebf3..2640bcb 100644 --- a/rainbowadn/wrisbt/wrisbtroot.py +++ b/rainbowadn/wrisbt/wrisbtroot.py @@ -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)