cengal.code_flow_control.smart_values.versions.v_1.smart_values
1#!/usr/bin/env python 2# coding=utf-8 3 4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space> 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17 18from typing import Any 19 20""" 21Module Docstring 22Docstrings: http://www.python.org/dev/peps/pep-0257/ 23""" 24 25__author__ = "ButenkoMS <gtalk@butenkoms.space>" 26__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>" 27__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ] 28__license__ = "Apache License, Version 2.0" 29__version__ = "4.4.1" 30__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>" 31__email__ = "gtalk@butenkoms.space" 32# __status__ = "Prototype" 33__status__ = "Development" 34# __status__ = "Production" 35 36 37class ValueExistence: 38 __slots__ = ('existence', 'result') 39 40 def __init__(self, existence: bool, result: Any): 41 self.existence: bool = existence 42 self.result = result 43 44 def __bool__(self): 45 return self.existence 46 47 def __nonzero__(self): 48 return self.__bool__() 49 50 def __str__(self): 51 return 'ValueExistence({}, {})'.format(self.existence, self.result) 52 53 def __getstate__(self): 54 return self.existence, self.result 55 56 def __setstate__(self, state): 57 existence, value = state 58 self.value = value 59 self.existence = existence 60 61 def __eq__(self, __value: object) -> bool: 62 if isinstance(__value, ValueExistence): 63 return (self.existence == __value.existence) and (self.value == __value.value) 64 else: 65 if self.existence: 66 return self.value == __value 67 else: 68 return False 69 70 def __ne__(self, __value: object) -> bool: 71 return not self.__eq__(__value) 72 73 74class ValueCache(ValueExistence): 75 __slots__ = tuple() 76 77 def __init__(self): 78 super(ValueCache, self).__init__(False, None) 79 80 def __call__(self, *args, **kwargs): 81 self.existence = False 82 83 def get(self): 84 return self.result 85 86 def set(self, new_result): 87 self.existence = True 88 self.result = new_result 89 90 def __getstate__(self): 91 return self.existence, self.result 92 93 def __setstate__(self, state): 94 existence, value = state 95 self.value = value 96 self.existence = existence 97 98 def __eq__(self, __value: object) -> bool: 99 if isinstance(__value, ValueExistence): 100 return (self.existence == __value.existence) and (self.value == __value.value) 101 else: 102 if self.existence: 103 return self.value == __value 104 else: 105 return False 106 107 def __ne__(self, __value: object) -> bool: 108 return not self.__eq__(__value) 109 110 111class ValueType: 112 __slots__ = ('type_id', 'result') 113 114 def __init__(self, type_id, result): 115 self.type_id = type_id 116 self.result = result 117 118 def __eq__(self, other): 119 # "__ne__() delegates to __eq__() and inverts the result" 120 if isinstance(other, ValueType): 121 return self.type_id == other.type_id 122 else: 123 return self.type_id == other 124 125 def __getstate__(self): 126 return self.type_id, self.result 127 128 def __setstate__(self, state): 129 self.type_id, self.result = state
class
ValueExistence:
38class ValueExistence: 39 __slots__ = ('existence', 'result') 40 41 def __init__(self, existence: bool, result: Any): 42 self.existence: bool = existence 43 self.result = result 44 45 def __bool__(self): 46 return self.existence 47 48 def __nonzero__(self): 49 return self.__bool__() 50 51 def __str__(self): 52 return 'ValueExistence({}, {})'.format(self.existence, self.result) 53 54 def __getstate__(self): 55 return self.existence, self.result 56 57 def __setstate__(self, state): 58 existence, value = state 59 self.value = value 60 self.existence = existence 61 62 def __eq__(self, __value: object) -> bool: 63 if isinstance(__value, ValueExistence): 64 return (self.existence == __value.existence) and (self.value == __value.value) 65 else: 66 if self.existence: 67 return self.value == __value 68 else: 69 return False 70 71 def __ne__(self, __value: object) -> bool: 72 return not self.__eq__(__value)
75class ValueCache(ValueExistence): 76 __slots__ = tuple() 77 78 def __init__(self): 79 super(ValueCache, self).__init__(False, None) 80 81 def __call__(self, *args, **kwargs): 82 self.existence = False 83 84 def get(self): 85 return self.result 86 87 def set(self, new_result): 88 self.existence = True 89 self.result = new_result 90 91 def __getstate__(self): 92 return self.existence, self.result 93 94 def __setstate__(self, state): 95 existence, value = state 96 self.value = value 97 self.existence = existence 98 99 def __eq__(self, __value: object) -> bool: 100 if isinstance(__value, ValueExistence): 101 return (self.existence == __value.existence) and (self.value == __value.value) 102 else: 103 if self.existence: 104 return self.value == __value 105 else: 106 return False 107 108 def __ne__(self, __value: object) -> bool: 109 return not self.__eq__(__value)
Inherited Members
class
ValueType:
112class ValueType: 113 __slots__ = ('type_id', 'result') 114 115 def __init__(self, type_id, result): 116 self.type_id = type_id 117 self.result = result 118 119 def __eq__(self, other): 120 # "__ne__() delegates to __eq__() and inverts the result" 121 if isinstance(other, ValueType): 122 return self.type_id == other.type_id 123 else: 124 return self.type_id == other 125 126 def __getstate__(self): 127 return self.type_id, self.result 128 129 def __setstate__(self, state): 130 self.type_id, self.result = state