Ejemplo n.º 1
0
    def test_encoding(self):
        u_test = (b'<?xml version="1.0" encoding="latin1"?>'
                  b'<team><boolean>True</boolean>'
                  b'<name>Bar\xe7a</name>'
                  b'<nil />'
                  b'<number>1234</number></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xe7a'.decode('latin1'))

        u_test = (b'<?xml version="1.0" encoding="UTF-8"?>'
                  b'<team><boolean>True</boolean>'
                  b'<name>Bar\xc3\xa7a</name>'
                  b'<nil />'
                  b'<number>1234</number></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xc3\xa7a'.decode('utf-8'))

        resp = xml.dict_to_xml({
            'team': {
                'name': b'Bar\xc3\xa7a'.decode('utf-8'),
                'boolean': True,
                'number': 1234,
                'nil': None
            }
        })
        self.assertEqual(resp, u_test)
Ejemplo n.º 2
0
    def test_encoding(self):
        u_test = (b'<?xml version="1.0" encoding="UTF-8"?>'
                  b'<team><name>Bar\xc3\xa7a</name></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xc3\xa7a'.decode('utf-8'))

        u_test = (b'<?xml version="1.0" encoding="latin1"?>'
                  b'<team><name>Bar\xe7a</name></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xe7a'.decode('latin1'))
Ejemplo n.º 3
0
    def test_encoding(self):
        u_test = (b'<?xml version="1.0" encoding="UTF-8"?>'
                  b'<team><name>Bar\xc3\xa7a</name></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xc3\xa7a'.decode('utf-8'))

        u_test = (b'<?xml version="1.0" encoding="latin1"?>'
                  b'<team><name>Bar\xe7a</name></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xe7a'.decode('latin1'))
Ejemplo n.º 4
0
    def test_basic_usage(self):
        resp1 = xml.parse_xml(self.xml_header + self.xml_duck, 200, None)
        duck1 = resp1['duck']
        self.check_duck(duck1)

        # From generated xml: generate a dict; then, parse it again
        # It must be exactly the same than the very first dict
        resp2 = xml.parse_xml(xml.dict_to_xml(resp1), 200, None)
        duck2 = resp2['duck']
        self.check_duck(duck2)

        # Now, let's test an array...
        xml_doc = self.xml_header
        xml_doc += b'<ducks>'
        xml_doc += self.xml_duck
        xml_doc += self.xml_duck
        xml_doc += b'</ducks>'
        resp3 = xml.parse_xml(xml_doc, 200, None)
        ducks = resp3['ducks']['duck']
        for duck in ducks:
            self.check_duck(duck)
Ejemplo n.º 5
0
    def test_basic_usage(self):
        resp1 = xml.parse_xml(self.xml_header + self.xml_duck, 200, None)
        duck1 = resp1['duck']
        self.check_duck(duck1)

        # From generated xml: generate a dict; then, parse it again
        # It must be exactly the same than the very first dict
        resp2 = xml.parse_xml(xml.dict_to_xml(resp1), 200, None)
        duck2 = resp2['duck']
        self.check_duck(duck2)

        # Now, let's test an array...
        xml_doc = self.xml_header
        xml_doc += b'<ducks>'
        xml_doc += self.xml_duck
        xml_doc += self.xml_duck
        xml_doc += b'</ducks>'
        resp3 = xml.parse_xml(xml_doc, 200, None)
        ducks = resp3['ducks']['duck']
        for duck in ducks:
            self.check_duck(duck)
Ejemplo n.º 6
0
    def test_encoding(self):
        u_test = (b'<?xml version="1.0" encoding="latin1"?>'
                  b'<team><boolean>True</boolean>'
                  b'<name>Bar\xe7a</name>'
                  b'<nil />'
                  b'<number>1234</number></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xe7a'.decode('latin1'))

        u_test_part1 = (b'<?xml version="1.0" encoding="UTF-8"?>'
                        b'<team><boolean>True</boolean>'
                        b'<name>Bar\xc3\xa7a</name>')
        u_test_part2 = b'<number>1234</number></team>'

        # some versions of libxml2 produce <nil /> for empty tags, others
        # produce <nil></nil> - we don't care when serializing and we'll just
        # check for both
        u_test = u_test_part1 + b'<nil />' + u_test_part2
        u_test_alt = u_test_part1 + b'<nil></nil>' + u_test_part2

        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xc3\xa7a'.decode('utf-8'))

        resp = xml.dict_to_xml({
            'team': {
                'boolean': True,
                'name': b'Bar\xc3\xa7a'.decode('utf-8'),
                'nil': None,
                'number': 1234
            }
        })

        # accept both <nil /> and <nil></nil>; can't use assertIn, as it only
        # got added in Python 2.7
        try:
            self.assertEqual(resp, u_test)
        except AssertionError:
            self.assertEqual(resp, u_test_alt)
Ejemplo n.º 7
0
    def test_encoding(self):
        u_test = (b'<?xml version="1.0" encoding="latin1"?>'
                  b'<team><boolean>True</boolean>'
                  b'<name>Bar\xe7a</name>'
                  b'<nil />'
                  b'<number>1234</number></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xe7a'.decode('latin1'))

        u_test_part1 = (b'<?xml version="1.0" encoding="UTF-8"?>'
                        b'<team><boolean>True</boolean>'
                        b'<name>Bar\xc3\xa7a</name>')
        u_test_part2 = b'<number>1234</number></team>'

        # some versions of libxml2 produce <nil /> for empty tags, others
        # produce <nil></nil> - we don't care when serializing and we'll just
        # check for both
        u_test = u_test_part1 + b'<nil />' + u_test_part2
        u_test_alt = u_test_part1 + b'<nil></nil>' + u_test_part2

        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xc3\xa7a'.decode('utf-8'))

        resp = xml.dict_to_xml({'team': {
            'name': b'Bar\xc3\xa7a'.decode('utf-8'),
            'boolean': True,
            'number': 1234,
            'nil': None
        }})

        # accept both <nil /> and <nil></nil>; can't use assertIn, as it only
        # got added in Python 2.7
        try:
            self.assertEqual(resp, u_test)
        except AssertionError:
            self.assertEqual(resp, u_test_alt)
Ejemplo n.º 8
0
    def test_encoding(self):
        u_test = (b'<?xml version="1.0" encoding="latin1"?>'
                  b'<team><boolean>True</boolean>'
                  b'<name>Bar\xe7a</name>'
                  b'<nil />'
                  b'<number>1234</number></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xe7a'.decode('latin1'))

        u_test = (b'<?xml version="1.0" encoding="UTF-8"?>'
                  b'<team><boolean>True</boolean>'
                  b'<name>Bar\xc3\xa7a</name>'
                  b'<nil />'
                  b'<number>1234</number></team>')
        resp = xml.parse_xml(u_test, 200, None)
        self.assertEqual(resp['team']['name'], b'Bar\xc3\xa7a'.decode('utf-8'))

        resp = xml.dict_to_xml({'team': {
            'name': b'Bar\xc3\xa7a'.decode('utf-8'),
            'boolean': True,
            'number': 1234,
            'nil': None
        }})
        self.assertEqual(resp, u_test)