  
          self.assertEqual(Form(data).is_valid(), True)
  
  
  class TestXMLParser(TestCase):
      def setUp(self):
          self._input = StringIO(
              '<?xml version="1.0" encoding="utf-8"?>'
              '<root>'
              '<field_a>121.0</field_a>'
              '<field_b>dasd</field_b>'
              '<field_c></field_c>'
              '<field_d>2011-12-25 12:45:00</field_d>'
              '</root>'
          )
          self._data = {
              'field_a': 121,
              'field_b': 'dasd',
              'field_c': None,
              'field_d': datetime.datetime(2011, 12, 25, 12, 45, 00)
          }
          self._complex_data_input = StringIO(
              '<?xml version="1.0" encoding="utf-8"?>'
              '<root>'
              '<creation_date>2011-12-25 12:45:00</creation_date>'
              '<sub_data_list>'
              '<list-item><sub_id>1</sub_id><sub_name>first</sub_name></list-item>'
              '<list-item><sub_id>2</sub_id><sub_name>second</sub_name></list-item>'
              '</sub_data_list>'
              '<name>name</name>'
              '</root>'
          )
          self._complex_data = {
              "creation_date": datetime.datetime(2011, 12, 25, 12, 45, 00),
              "name": "name",
              "sub_data_list": [
                  {
                      "sub_id": 1,
                      "sub_name": "first"
                  },
                  {
                      "sub_id": 2,
                      "sub_name": "second"
                  }
              ]
          }
  
      @unittest.skipUnless(etree, 'defusedxml not installed')
      def test_parse(self):
          parser = XMLParser()
          data = parser.parse(self._input)
          self.assertEqual(data, self._data)
  
      @unittest.skipUnless(etree, 'defusedxml not installed')
      def test_complex_data_parse(self):
          parser = XMLParser()
          data = parser.parse(self._complex_data_input)
          self.assertEqual(data, self._complex_data)
  
  
  class TestFileUploadParser(TestCase):
      def setUp(self):
          class MockRequest(object):
              pass
          from io import BytesIO
 
</s> remove class XMLParser(BaseParser):
    """
    XML parser.
    """

    media_type = 'application/xml'

    def parse(self, stream, media_type=None, parser_context=None):
        """
        Parses the incoming bytestream as XML and returns the resulting data.
        """
        assert etree, 'XMLParser requires defusedxml to be installed'

        parser_context = parser_context or {}
        encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
        parser = etree.DefusedXMLParser(encoding=encoding)
        try:
            tree = etree.parse(stream, parser=parser, forbid_dtd=True)
        except (etree.ParseError, ValueError) as exc:
            raise ParseError('XML parse error - %s' % six.text_type(exc))
        data = self._xml_convert(tree.getroot())

        return data

    def _xml_convert(self, element):
        """
        convert the xml `element` into the corresponding python object
        """

        children = list(element)

        if len(children) == 0:
            return self._type_convert(element.text)
        else:
            # if the fist child tag is list-item means all children are list-item
            if children[0].tag == "list-item":
                data = []
                for child in children:
                    data.append(self._xml_convert(child))
            else:
                data = {}
                for child in children:
                    data[child.tag] = self._xml_convert(child)

            return data

    def _type_convert(self, value):
        """
        Converts the value returned by the XMl parse into the equivalent
        Python type
        """
        if value is None:
            return value

        try:
            return datetime.datetime.strptime(value, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            pass

        try:
            return int(value)
        except ValueError:
            pass

        try:
            return decimal.Decimal(value)
        except decimal.InvalidOperation:
            pass

        return value


 </s> add  </s> remove import datetime
import decimal
 </s> add  </s> remove class XMLRenderer(BaseRenderer):
    """
    Renderer which serializes to XML.
    """

    media_type = 'application/xml'
    format = 'xml'
    charset = 'utf-8'

    def render(self, data, accepted_media_type=None, renderer_context=None):
        """
        Renders `data` into serialized XML.
        """
        if data is None:
            return ''

        stream = StringIO()

        xml = SimplerXMLGenerator(stream, self.charset)
        xml.startDocument()
        xml.startElement("root", {})

        self._to_xml(xml, data)

        xml.endElement("root")
        xml.endDocument()
        return stream.getvalue()

    def _to_xml(self, xml, data):
        if isinstance(data, (list, tuple)):
            for item in data:
                xml.startElement("list-item", {})
                self._to_xml(xml, item)
                xml.endElement("list-item")

        elif isinstance(data, dict):
            for key, value in six.iteritems(data):
                xml.startElement(key, {})
                self._to_xml(xml, value)
                xml.endElement(key)

        elif data is None:
            # Don't output any value
            pass

        else:
            xml.characters(smart_text(data))


 </s> add  </s> remove from rest_framework.parsers import XMLParser
import datetime
 </s> add  </s> remove # XML is optional
try:
    import defusedxml.ElementTree as etree
except ImportError:
    etree = None


 </s> add 
  
          self.assertEqual(Form(data).is_valid(), True)
  
  
























































  class TestFileUploadParser(TestCase):
      def setUp(self):
          class MockRequest(object):
              pass
          from io import BytesIO
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Remove XML support from core 
tests/test_parsers.py