# Path: starterpyth/cliforms.py
# class BaseForm(object):
# 
#     def __init__(self, initial=None, extra_env=None):
#         super(BaseForm, self).__init__()
#         self.extra_env = {} if extra_env is None else extra_env
#         self.initial = {} if initial is None else initial
# 
#     def read(self, interactive=True):
#         fields = []
#         for key, field in self.__class__.__dict__.items():
#             if isinstance(field, Input):
#                 fields.append((key, field))
#         fields.sort(key=lambda f_: f_[1].order)
#         values = {}
#         extra_env = {}
#         extra_env.update(self.extra_env)
#         for key, field in fields:
#             kwargs = {}
#             show = field.show
#             init_value = self.initial.get(key, field.initial)
#             extra_env.update(values)
#             if hasattr(init_value, '__call__') and not isinstance(init_value, type):
#                 init_value = init_value(**extra_env)
#             if show is not None:
#                 if hasattr(show, '__call__'):
#                     show = show(**extra_env)
#                 if not show:
#                     values[key] = init_value
#                     continue
#             kwargs['initial'] = init_value
#             if interactive:
#                 values[key] = field.read(**kwargs)
#             else:
#                 values[key] = kwargs.get('initial', field.initial)
#         return values
# 
# class CharInput(Input):
# 
#     def __init__(self, label='', initial=None, max_length=None, min_length=None, show=None):
#         super(CharInput, self).__init__(label=label, initial=initial, show=show)
#         self.max_length = max_length
#         self.min_length = min_length
# 
#     def widget(self, initial=None):
#         if initial:
#             return _('%(label)s [%(init)s]: ') % {'label': self.label, 'init': self.to_str(initial)}
#         else:
#             return _('%(label)s: ') % {'label': self.label}
# 
#     def to_str(self, value):
#         return str(value)
# 
#     def to_python(self, value):
#         if self.min_length is not None and self.min_length > len(value):
#             raise InvalidValue(_('Value must be at least %(l)d character long') % {'l': self.min_length})
#         if self.max_length is not None and self.max_length < len(value):
#             raise InvalidValue(_('Value must be at most %(l)d character long') % {'l': self.max_length})
#         return value
# 
# class BooleanInput(CharInput):
#     true_values = [_('yes'), _('y')]
#     false_values = [_('no'), _('n')]
# 
#     def to_python(self, value):
#         value = value.lower()
#         if value in self.true_values:
#             return True
#         elif value in self.false_values:
#             return False
#         raise InvalidValue(_('Value must be one of %(l)s') % {'l': ', '.join(self.true_values + self.false_values)})
# 
#     def to_str(self, value):
#         if value:
#             return self.true_values[0]
#         return self.false_values[0]
# 
#     def widget(self, initial=None):
#         if initial is None:
#             choices = _('%s/%s') % (self.true_values[0], self.false_values[0])
#         elif initial:
#             choices = _('%s/%s') % (self.true_values[0].upper(), self.false_values[0])
#         else:
#             choices = _('%s/%s') % (self.true_values[0], self.false_values[0].upper())
#         return _('%(label)s [%(choices)s]: ') % {'label': self.label, 'choices': choices}


from starterpyth.cliforms import BaseForm, CharInput, BooleanInput
    import doctest
#coding=utf-8

__author__ = 'flanker'


class TestForm(BaseForm):
    c_323 = CharInput(label='label1', min_length=12)

# Path: starterpyth/cliforms.py
# class BaseForm(object):
# 
#     def __init__(self, initial=None, extra_env=None):
#         super(BaseForm, self).__init__()
#         self.extra_env = {} if extra_env is None else extra_env
#         self.initial = {} if initial is None else initial
# 
#     def read(self, interactive=True):
#         fields = []
#         for key, field in self.__class__.__dict__.items():
#             if isinstance(field, Input):
#                 fields.append((key, field))
#         fields.sort(key=lambda f_: f_[1].order)
#         values = {}
#         extra_env = {}
#         extra_env.update(self.extra_env)
#         for key, field in fields:
#             kwargs = {}
#             show = field.show
#             init_value = self.initial.get(key, field.initial)
#             extra_env.update(values)
#             if hasattr(init_value, '__call__') and not isinstance(init_value, type):
#                 init_value = init_value(**extra_env)
#             if show is not None:
#                 if hasattr(show, '__call__'):
#                     show = show(**extra_env)
#                 if not show:
#                     values[key] = init_value
#                     continue
#             kwargs['initial'] = init_value
#             if interactive:
#                 values[key] = field.read(**kwargs)
#             else:
#                 values[key] = kwargs.get('initial', field.initial)
#         return values
# 
# class CharInput(Input):
# 
#     def __init__(self, label='', initial=None, max_length=None, min_length=None, show=None):
#         super(CharInput, self).__init__(label=label, initial=initial, show=show)
#         self.max_length = max_length
#         self.min_length = min_length
# 
#     def widget(self, initial=None):
#         if initial:
#             return _('%(label)s [%(init)s]: ') % {'label': self.label, 'init': self.to_str(initial)}
#         else:
#             return _('%(label)s: ') % {'label': self.label}
# 
#     def to_str(self, value):
#         return str(value)
# 
#     def to_python(self, value):
#         if self.min_length is not None and self.min_length > len(value):
#             raise InvalidValue(_('Value must be at least %(l)d character long') % {'l': self.min_length})
#         if self.max_length is not None and self.max_length < len(value):
#             raise InvalidValue(_('Value must be at most %(l)d character long') % {'l': self.max_length})
#         return value
# 
# class BooleanInput(CharInput):
#     true_values = [_('yes'), _('y')]
#     false_values = [_('no'), _('n')]
# 
#     def to_python(self, value):
#         value = value.lower()
#         if value in self.true_values:
#             return True
#         elif value in self.false_values:
#             return False
#         raise InvalidValue(_('Value must be one of %(l)s') % {'l': ', '.join(self.true_values + self.false_values)})
# 
#     def to_str(self, value):
#         if value:
#             return self.true_values[0]
#         return self.false_values[0]
# 
#     def widget(self, initial=None):
#         if initial is None:
#             choices = _('%s/%s') % (self.true_values[0], self.false_values[0])
#         elif initial:
#             choices = _('%s/%s') % (self.true_values[0].upper(), self.false_values[0])
#         else:
#             choices = _('%s/%s') % (self.true_values[0], self.false_values[0].upper())
#         return _('%(label)s [%(choices)s]: ') % {'label': self.label, 'choices': choices}


# Path: starterpyth/tests/test_cliforms.py
from starterpyth.cliforms import BaseForm, CharInput, BooleanInput
    import doctest

#coding=utf-8

__author__ = 'flanker'


class TestForm(BaseForm):
    c_323 = CharInput(label='label1', min_length=12)

    c_2 = CharInput(label='label2', initial='42')