Created
February 29, 2012 17:17
-
-
Save marazmiki/1942605 to your computer and use it in GitHub Desktop.
Базовый класс для всякого рода "пулов" python-объектов
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PoolBase(object): | |
def __init__(self): | |
self.item_stack = [] | |
def register(self, item): | |
if not self.check_type(item): | |
raise TypeError, 'The {item} can\'t be registered in {class_name}'.format( | |
class_name = self.__class__, | |
item = item.__class__) | |
self.item_stack.append(item) | |
def check_type(self, item): | |
return True | |
def get_choices(self): | |
return tuple(enumerate([self.unicode_item(item) for item in self.item_stack])) | |
def unicode_item(self, item): | |
return unicode(item) | |
def get_default(self): | |
return 0 | |
def get_item_by_index(self, index): | |
return self.item_stack[index] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment