# Path: webtools/formdata/exceptions.py
# class ValidateError(Exception):
#     pass
# 
# Path: webtools/formdata/field.py
# 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):
#         raw_value = formdata.get_argument(name)
#         if raw_value:
#             return self.datatype.to_python(raw_value, self)
#         else:
#             if not self.required:
#                 return self.default
#             raise ValidateError("this field is required")
# 
# class BoundField(object):
#     def __init__(self, name, prefixed_name, field, form):
#         self.name = name
#         self.prefixed_name = prefixed_name
#         self.field = field
#         self.form = form
# 
#     def __str__(self):
#         if not self.field.widget:
#             return ""
# 
#         value = self.form._initial.get(self.name, None)
#         value = self.field.datatype.from_python(value)
# 
#         return self.field.widget(self.name, self.prefixed_name, value)


from .exceptions import ValidateError
from .field import Field, BoundField
import copy



def get_declared_fields(bases, attrs, with_base_fields=True):
    fields = [(field_name, attrs.pop(field_name)) for field_name, obj in list(attrs.items()) if isinstance(obj, Field)]

    if with_base_fields:
        for base in bases[::-1]:
            if hasattr(base, "base_fields"):
                fields = list(base.base_fields.items()) + fields

    return dict(fields)


class FormDataMeta(type):

# Path: webtools/formdata/exceptions.py
# class ValidateError(Exception):
#     pass
# 
# Path: webtools/formdata/field.py
# 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):
#         raw_value = formdata.get_argument(name)
#         if raw_value:
#             return self.datatype.to_python(raw_value, self)
#         else:
#             if not self.required:
#                 return self.default
#             raise ValidateError("this field is required")
# 
# class BoundField(object):
#     def __init__(self, name, prefixed_name, field, form):
#         self.name = name
#         self.prefixed_name = prefixed_name
#         self.field = field
#         self.form = form
# 
#     def __str__(self):
#         if not self.field.widget:
#             return ""
# 
#         value = self.form._initial.get(self.name, None)
#         value = self.field.datatype.from_python(value)
# 
#         return self.field.widget(self.name, self.prefixed_name, value)


# Path: webtools/formdata/base.py
from .exceptions import ValidateError
from .field import Field, BoundField
import copy




def get_declared_fields(bases, attrs, with_base_fields=True):
    fields = [(field_name, attrs.pop(field_name)) for field_name, obj in list(attrs.items()) if isinstance(obj, Field)]

    if with_base_fields:
        for base in bases[::-1]:
            if hasattr(base, "base_fields"):
                fields = list(base.base_fields.items()) + fields

    return dict(fields)


class FormDataMeta(type):

    def __new__(cls, name, bases, attrs):