示例#1
0
    def setUp(self):
        #~ dude = XCheck('dude')
        nick = BoolCheck('nick', required=False)
        fname = TextCheck('first', min_length = 1)
        fname.addattribute(nick)



        lname = TextCheck('last', min_length = 1)
        code = IntCheck('code', min_occurs = 1, max_occurs = 5)
        code.addattribute(TextCheck('word', required=False) )
        name = XCheck('name', children=[fname, lname, code])

        emailtype = SelectionCheck('type', values = ['home','work', 'personal'])
        email = EmailCheck('email', max_occurs=2)
        email.addattribute(emailtype)
        street = TextCheck('street')
        city = TextCheck('city')

        address = XCheck('address', children = [street, city, email], max_occurs = 4)
        self.address = address
        dude = XCheck('dude', children=[name, address])
        idch = IntCheck('id', required=True)
        dude.addattribute(idch)

        elem = ET.fromstring("""<dude id="1">
        <name>
            <first nick="true">Josh</first>
            <last>English</last>
            <code>12</code>
            <code word="answer">42</code>
        </name>
        <address>
            <street>100 Main St</street>
            <city>Podunk</city>
            <email type="home">[email protected]</email>
            <email type="work">[email protected]</email>
        </address>
        <address>
            <street>318 West Nowhere Ln</street>
            <city>East Podunk</city>
            <email type="personal">[email protected]</email>
        </address>
        </dude>""")
        self.w = Wrap(dude, elem)
示例#2
0
def local_test():
    "sample usage and simple test"
    nick = BoolCheck('nick', required=False)
    first_name = TextCheck('first', min_length = 1)
    first_name.addattribute(nick)

    last_name = TextCheck('last', min_length = 1)
    code = IntCheck('code', min_occurs=1, max_occurs=5)
    code.addattribute(TextCheck('word', required=False) )
    name = XCheck('name', children=[first_name, last_name, code])

    emailtype = SelectionCheck('type', values = ['home', 'work', 'personal'])
    email = EmailCheck('email', max_occurs=2)
    email.addattribute(emailtype)
    street = TextCheck('street')
    city = TextCheck('city')

    address = XCheck('address', children = [street, city, email],
         max_occurs = 4)

    dude = XCheck('dude', children=[name, address],
        help="A simple contact list item")

    dude_node = ET.fromstring("""<dude id="1">
            <name>
                <first nick="true">Josh</first>
                <last>English</last>
                <code>12</code>
                <code word="answer">42</code>
            </name>
            <address>
                <street>100 Main St</street>
                <city>Podunk</city>
                <email type="home">[email protected]</email>
                <email type="work">[email protected]</email>
            </address>
            <address>
                <street>318 West Nowhere Ln</street>
                <city>East Podunk</city>
                <email type="personal">[email protected]</email>
            </address>
    </dude>""")
    from pprint import pprint
    object_dict = node_to_dict(dude_node, dude)
    pprint( object_dict )
示例#3
0
    def setUp(self):
        nick = BoolCheck('nick', required=False)
        fname = TextCheck('first', min_length = 1)
        fname.addattribute(nick)

        lname = TextCheck('last', min_length = 1)
        code = IntCheck('code', min_occurs = 1, max_occurs = 5)
        code.addattribute(TextCheck('word', required=False) )
        ch = XCheck('name', children=[fname, lname, code])
        idch = IntCheck('id', required=True)
        ch.addattribute(idch)
        elem = ET.fromstring("""<name id="1">
        <first nick="true">Josh</first>
        <last>English</last>
        <code>12</code>
        <code word="answer">42</code>
        </name>""")
        self.w = Wrap(ch, elem)