| 107 | ################################################################################ |
| 108 | |
| 109 | class Primer(object): |
| 110 | |
| 111 | slots('data') |
| 112 | |
| 113 | @classmethod |
| 114 | def new(cls, key): |
| 115 | base = key.base |
| 116 | return cls(''.join(_CHAOS.choice(base) for _ in range(key.prefix_len))) |
| 117 | |
| 118 | def __init__(self, data): |
| 119 | self.__test_data(data) |
| 120 | self.__data = data |
| 121 | |
| 122 | @staticmethod |
| 123 | def __test_data(data): |
| 124 | if not isinstance(data, str): |
| 125 | raise TypeError('Data must be a str object!') |
| 126 | if not data: |
| 127 | raise ValueError('Data must contain at least one char!') |
| 128 | |
| 129 | def test_key(self, key): |
| 130 | if len(self.__data) != key.prefix_len: |
| 131 | raise ValueError('Key size must be one more than the primer size!') |
| 132 | if not set(self.__data).issubset(key.base): |
| 133 | raise ValueError('Key data must be a superset of primer data!') |
| 134 | |
| 135 | @property |
| 136 | def data(self): |
| 137 | return self.__data |
| 138 | |
| 139 | ################################################################################ |
| 140 | |