cengal.data_generation.id_generator.versions.v_0.id_generator
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 cengal.system import PLATFORM_NAME 19if 'PyPy' != PLATFORM_NAME: 20 import uuid 21from enum import Enum 22 23""" 24Module Docstring 25Docstrings: http://www.python.org/dev/peps/pep-0257/ 26""" 27 28__author__ = "ButenkoMS <gtalk@butenkoms.space>" 29__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>" 30__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ] 31__license__ = "Apache License, Version 2.0" 32__version__ = "4.4.1" 33__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>" 34__email__ = "gtalk@butenkoms.space" 35# __status__ = "Prototype" 36__status__ = "Development" 37# __status__ = "Production" 38 39 40class TypeOfGenerator(Enum): 41 INTEGER = 0 42 GUID_STRING = 1 43 44 # _VALUES_TO_NAMES = { 45 # 0: "INTEGER", 46 # 1: "GUID_STRING", 47 # } 48 # 49 # _NAMES_TO_VALUES = { 50 # "INTEGER": 0, 51 # "GUID_STRING": 1, 52 # } 53 54 55class IDGenerator: 56 57 def __init__(self, type=TypeOfGenerator.INTEGER): 58 self.counter = 0 59 self.type = type 60 61 def get_new_ID(self): 62 currentCounter = None 63 if TypeOfGenerator.INTEGER == self.type: 64 currentCounter = self.counter 65 self.counter += 1 66 elif TypeOfGenerator.GUID_STRING == self.type: 67 seq = self.counter 68 self.counter += 1 69 currentCounter = uuid.uuid1(clock_seq=seq).hex 70 return currentCounter 71 72 def remove_ID(self, ID): 73 pass 74 75 def clear(self): 76 self.counter = 0 77 78 def __call__(self): 79 return self.get_new_ID()
class
TypeOfGenerator(enum.Enum):
41class TypeOfGenerator(Enum): 42 INTEGER = 0 43 GUID_STRING = 1 44 45 # _VALUES_TO_NAMES = { 46 # 0: "INTEGER", 47 # 1: "GUID_STRING", 48 # } 49 # 50 # _NAMES_TO_VALUES = { 51 # "INTEGER": 0, 52 # "GUID_STRING": 1, 53 # }
An enumeration.
INTEGER =
<TypeOfGenerator.INTEGER: 0>
GUID_STRING =
<TypeOfGenerator.GUID_STRING: 1>
Inherited Members
- enum.Enum
- name
- value
class
IDGenerator:
56class IDGenerator: 57 58 def __init__(self, type=TypeOfGenerator.INTEGER): 59 self.counter = 0 60 self.type = type 61 62 def get_new_ID(self): 63 currentCounter = None 64 if TypeOfGenerator.INTEGER == self.type: 65 currentCounter = self.counter 66 self.counter += 1 67 elif TypeOfGenerator.GUID_STRING == self.type: 68 seq = self.counter 69 self.counter += 1 70 currentCounter = uuid.uuid1(clock_seq=seq).hex 71 return currentCounter 72 73 def remove_ID(self, ID): 74 pass 75 76 def clear(self): 77 self.counter = 0 78 79 def __call__(self): 80 return self.get_new_ID()
IDGenerator(type=<TypeOfGenerator.INTEGER: 0>)
def
get_new_ID(self):
62 def get_new_ID(self): 63 currentCounter = None 64 if TypeOfGenerator.INTEGER == self.type: 65 currentCounter = self.counter 66 self.counter += 1 67 elif TypeOfGenerator.GUID_STRING == self.type: 68 seq = self.counter 69 self.counter += 1 70 currentCounter = uuid.uuid1(clock_seq=seq).hex 71 return currentCounter