# Path: wokkel/data_form.py
# NS_X_DATA = 'jabber:x:data'
# class Error(Exception):
# class FieldNameRequiredError(Error):
# class TooManyValuesError(Error):
# class Option(object):
# class Field(object):
# class Form(object):
#     def __init__(self, value, label=None):
#     def __repr__(self):
#     def toElement(self):
#     def fromElement(element):
#     def __init__(self, fieldType='text-single', var=None, value=None,
#                        values=None, options=None, label=None, desc=None,
#                        required=False):
#     def __repr__(self):
#     def __value_set(self, value):
#     def __value_get(self):
#     def typeCheck(self):
#     def toElement(self, asForm=False):
#     def _parse_desc(field, element):
#     def _parse_option(field, element):
#     def _parse_required(field, element):
#     def _parse_value(field, element):
#     def fromElement(element):
#     def fromDict(fieldDict):
#     def __init__(self, formType, title=None, instructions=None,
#                        formNamespace=None, fields=None):
#     def __repr__(self):
#     def addField(self, field):
#     def removeField(self, field):
#     def makeFields(self, values, fieldDefs=None, filterUnknown=True):
#     def toElement(self):
#     def _parse_title(form, element):
#     def _parse_instructions(form, element):
#     def _parse_field(form, element):
#     def fromElement(element):
#     def __iter__(self):
#     def __len__(self):
#     def __getitem__(self, key):
#     def get(self, key, default=None):
#     def __contains__(self, key):
#     def iterkeys(self):
#     def itervalues(self):
#     def iteritems(self):
#         def keys(self):
#         def values(self):
#         def items(self):
#     def getValues(self):
#     def typeCheck(self, fieldDefs=None, filterUnknown=False):
# def findForm(element, formNamespace):


from zope.interface import verify
from zope.interface.common.mapping import IIterableMapping
from twisted.python.compat import unicode, _PY3
from twisted.trial import unittest
from twisted.words.xish import domish
from twisted.words.protocols.jabber import jid
from wokkel import data_form
                  data_form.Field('text-multi',
                                  var='description',
                                  label='Helpful description of your bot'),
                  data_form.Field('boolean',
                                  var='public',
                                  label='Public bot?',
                                  required=True)
                 ]
        form = data_form.Form('form', fields=fields)
        element = form.toElement()

        elements = list(element.elements())
        self.assertEqual(4, len(elements))
        for field in elements:
            self.assertEqual('field', field.name)
            self.assertEqual(NS_X_DATA, field.uri)

        # Check order
        self.assertEqual('fixed', elements[0]['type'])
        self.assertEqual('botname', elements[1]['var'])
        self.assertEqual('description', elements[2]['var'])
        self.assertEqual('public', elements[3]['var'])


    def test_fromElement(self):
        """
        C{fromElement} creates a L{data_form.Form} from a DOM representation.
        """
        element = domish.Element((NS_X_DATA, 'x'))
        element['type'] = 'result'

# Path: wokkel/data_form.py
# NS_X_DATA = 'jabber:x:data'
# class Error(Exception):
# class FieldNameRequiredError(Error):
# class TooManyValuesError(Error):
# class Option(object):
# class Field(object):
# class Form(object):
#     def __init__(self, value, label=None):
#     def __repr__(self):
#     def toElement(self):
#     def fromElement(element):
#     def __init__(self, fieldType='text-single', var=None, value=None,
#                        values=None, options=None, label=None, desc=None,
#                        required=False):
#     def __repr__(self):
#     def __value_set(self, value):
#     def __value_get(self):
#     def typeCheck(self):
#     def toElement(self, asForm=False):
#     def _parse_desc(field, element):
#     def _parse_option(field, element):
#     def _parse_required(field, element):
#     def _parse_value(field, element):
#     def fromElement(element):
#     def fromDict(fieldDict):
#     def __init__(self, formType, title=None, instructions=None,
#                        formNamespace=None, fields=None):
#     def __repr__(self):
#     def addField(self, field):
#     def removeField(self, field):
#     def makeFields(self, values, fieldDefs=None, filterUnknown=True):
#     def toElement(self):
#     def _parse_title(form, element):
#     def _parse_instructions(form, element):
#     def _parse_field(form, element):
#     def fromElement(element):
#     def __iter__(self):
#     def __len__(self):
#     def __getitem__(self, key):
#     def get(self, key, default=None):
#     def __contains__(self, key):
#     def iterkeys(self):
#     def itervalues(self):
#     def iteritems(self):
#         def keys(self):
#         def values(self):
#         def items(self):
#     def getValues(self):
#     def typeCheck(self, fieldDefs=None, filterUnknown=False):
# def findForm(element, formNamespace):


# Path: wokkel/test/test_data_form.py
from zope.interface import verify
from zope.interface.common.mapping import IIterableMapping
from twisted.python.compat import unicode, _PY3
from twisted.trial import unittest
from twisted.words.xish import domish
from twisted.words.protocols.jabber import jid
from wokkel import data_form

                  data_form.Field('text-multi',
                                  var='description',
                                  label='Helpful description of your bot'),
                  data_form.Field('boolean',
                                  var='public',
                                  label='Public bot?',
                                  required=True)
                 ]
        form = data_form.Form('form', fields=fields)
        element = form.toElement()

        elements = list(element.elements())
        self.assertEqual(4, len(elements))
        for field in elements:
            self.assertEqual('field', field.name)
            self.assertEqual(NS_X_DATA, field.uri)

        # Check order
        self.assertEqual('fixed', elements[0]['type'])
        self.assertEqual('botname', elements[1]['var'])
        self.assertEqual('description', elements[2]['var'])
        self.assertEqual('public', elements[3]['var'])


    def test_fromElement(self):
        """
        C{fromElement} creates a L{data_form.Form} from a DOM representation.
        """
        element = domish.Element((NS_X_DATA, 'x'))
        element['type'] = 'result'

        form = data_form.Form.fromElement(element)