Skip to content

Instantly share code, notes, and snippets.

@marazmiki
Created February 29, 2012 17:17
Show Gist options
  • Save marazmiki/1942605 to your computer and use it in GitHub Desktop.
Save marazmiki/1942605 to your computer and use it in GitHub Desktop.
Базовый класс для всякого рода "пулов" python-объектов
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