# Path: webtools/formdata/widgets.py
# class Widget(object):
#     """
#     Base class for all formdata widgets.
#     """
# 
#     def __init__(self, attrs={}):
#         self.attrs = attrs
# 
#     def set_field(self, field):
#         self.field = field
# 
#     def render(self, name, prefixed_name, value):
#         raise NotImplementedError()
# 
#     def attrs_to_str(self, attrs):
#         return " ".join(['{key}="{val}"'.format(key=x, val=y)
#             for x,y in attrs.items()])
# 
#     def __call__(self, name, prefixed_name, value):
#         return self.render(name, prefixed_name, value)
# 
# Path: webtools/formdata/exceptions.py
# class ValidateError(Exception):
#     pass


from .widgets import Widget
from .exceptions import ValidateError
from . import data_types

class Field(object):
    def __init__(self, datatype, widget=None, required=True, default=None):
        assert isinstance(datatype, data_types.Type), "datatype must be a instance of Type"
        self.datatype = datatype
        self.default = default
        self.required = required
        self.widget = widget

        if self.widget:
            if isinstance(self.widget, type):
                self.widget = self.widget()
            assert isinstance(self.widget, Widget), "widget must be a instance of Widget"


# Path: webtools/formdata/widgets.py
# class Widget(object):
#     """
#     Base class for all formdata widgets.
#     """
# 
#     def __init__(self, attrs={}):
#         self.attrs = attrs
# 
#     def set_field(self, field):
#         self.field = field
# 
#     def render(self, name, prefixed_name, value):
#         raise NotImplementedError()
# 
#     def attrs_to_str(self, attrs):
#         return " ".join(['{key}="{val}"'.format(key=x, val=y)
#             for x,y in attrs.items()])
# 
#     def __call__(self, name, prefixed_name, value):
#         return self.render(name, prefixed_name, value)
# 
# Path: webtools/formdata/exceptions.py
# class ValidateError(Exception):
#     pass


# Path: webtools/formdata/field.py
from .widgets import Widget
from .exceptions import ValidateError
from . import data_types


class Field(object):
    def __init__(self, datatype, widget=None, required=True, default=None):
        assert isinstance(datatype, data_types.Type), "datatype must be a instance of Type"
        self.datatype = datatype
        self.default = default
        self.required = required
        self.widget = widget

        if self.widget:
            if isinstance(self.widget, type):
                self.widget = self.widget()
            assert isinstance(self.widget, Widget), "widget must be a instance of Widget"


    def clean(self, name, formdata):