# Path: gtool/core/types/core.py
# class CoreType(object):
#     """
#     CoreType is the base object for all attribute types (except user created classes)
#     """
# 
#     def __init__(self, *args, **kwargs):
#         self.__valuetype__ = kwargs.pop('valuetype', None)
#         if self.__valuetype__ == None:
#             raise NotImplementedError('You need to specify a valuetype in keyword args')
# 
#         # assume singleton if not overridden
#         # self.__singleton = kwargs.pop('singleton', True)
# 
#         initvalue = None
#         if len(args) > 0:
#             initvalue = args[0]
#         self.__value__ = initvalue #None
# 
#     # TODO valid alternative repr requirements (if any)
#     def __repr__(self):
#         #return '%s' % self.__value__
#         #return '{0}: {1}'.format(striptoclassname(type(self)), self.__value__)
#         return  '%s' % self.__convert__(self.__value__)
# 
#     def raw(self):
#         return self.__convert__(self.__value__)
# 
#     def __str__(self):
#         return '%s' % self.__value__
# 
#     def __validate__(self, validatedict):
#         """
#         Abstract Validation method, must be implemented by sub-classes.
#         Must raise a ValueError if the value does not match the criteria
#         Look at gtool.type.common for examples
#         """
#         raise NotImplementedError('Please implement a __validate__ method for your class %s' % self.__class__)
# 
#     @classmethod
#     def __convert__(cls, item):
#         try:
#             return cls.__converter__()(item)
#         except ValueError:
#             raise ValueError('cannot convert %s to type %s' %(item, cls.__converter__()))


from gtool.core.types.core import CoreType

class Choice(CoreType):

    def __validate__(self, valuedict):
        _choices = valuedict.get('choices', None)
        choices = _choices[1:-1].split(',') if _choices is not None else None
        if self.__value__ not in choices:
            raise ValueError('Was expecting either one of %s but got a %s' % (choices, self.__value__))
        return True

    @classmethod
    def __converter__(cls):
        return str

    def __init__(self, *args, **kwargs):

# Path: gtool/core/types/core.py
# class CoreType(object):
#     """
#     CoreType is the base object for all attribute types (except user created classes)
#     """
# 
#     def __init__(self, *args, **kwargs):
#         self.__valuetype__ = kwargs.pop('valuetype', None)
#         if self.__valuetype__ == None:
#             raise NotImplementedError('You need to specify a valuetype in keyword args')
# 
#         # assume singleton if not overridden
#         # self.__singleton = kwargs.pop('singleton', True)
# 
#         initvalue = None
#         if len(args) > 0:
#             initvalue = args[0]
#         self.__value__ = initvalue #None
# 
#     # TODO valid alternative repr requirements (if any)
#     def __repr__(self):
#         #return '%s' % self.__value__
#         #return '{0}: {1}'.format(striptoclassname(type(self)), self.__value__)
#         return  '%s' % self.__convert__(self.__value__)
# 
#     def raw(self):
#         return self.__convert__(self.__value__)
# 
#     def __str__(self):
#         return '%s' % self.__value__
# 
#     def __validate__(self, validatedict):
#         """
#         Abstract Validation method, must be implemented by sub-classes.
#         Must raise a ValueError if the value does not match the criteria
#         Look at gtool.type.common for examples
#         """
#         raise NotImplementedError('Please implement a __validate__ method for your class %s' % self.__class__)
# 
#     @classmethod
#     def __convert__(cls, item):
#         try:
#             return cls.__converter__()(item)
#         except ValueError:
#             raise ValueError('cannot convert %s to type %s' %(item, cls.__converter__()))


# Path: test/test17/plugins/choice.py
from gtool.core.types.core import CoreType


class Choice(CoreType):

    def __validate__(self, valuedict):
        _choices = valuedict.get('choices', None)
        choices = _choices[1:-1].split(',') if _choices is not None else None
        if self.__value__ not in choices:
            raise ValueError('Was expecting either one of %s but got a %s' % (choices, self.__value__))
        return True

    @classmethod
    def __converter__(cls):
        return str

    def __init__(self, *args, **kwargs):

        self.__validators__ = ['choices']