def __init_validators(self): for k, obj in self.fields.items(): func = getattr(self, 'validate_%s' % obj.field_name, None) if func and callable(func): obj.validators.insert(0, func) func = getattr(self, 'form_validate', None) if func and callable(func): self.validators.append(func)
def get(self, key, default=Empty, creator=Empty, expire=None): """ :para default: if default is callable then invoke it, save it and return it """ try: return self.storage.get(key) except KeyError as e: if creator is not Empty: if callable(creator): v = creator() else: v = creator self.set(key, v, expire) return v else: if default is not Empty: if callable(default): v = default() return v return default else: raise
def set(self, key, value=None, expire=None): if callable(value): value = value() return self.storage.set(key, value, expire or self.expiry_time)
def __setitem__(self, key, value): if callable(value): value = value() return self.set(key, value)
def get_choices(self, value=None): if callable(self.choices): return self.choices() else: return self.choices
def get_commands(self, global_options): if callable(self.commands): commands = self.commands(global_options) else: commands = self.commands return commands