<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from django . utils import six <EOL> from django . utils . xmlutils import SimplerXMLGenerator <EOL> from django . utils . six . moves import StringIO <EOL> from django . utils . encoding import smart_text <EOL> from rest_framework . renderers import BaseRenderer <EOL> class XMLRenderer ( BaseRenderer ) : <EOL> """<STR_LIT>""" <EOL> media_type = '<STR_LIT>' <EOL> format = '<STR_LIT>' <EOL> charset = '<STR_LIT:utf-8>' <EOL> item_tag_name = '<STR_LIT>' <EOL> root_tag_name = '<STR_LIT:root>' <EOL> def render ( self , data , accepted_media_type = None , renderer_context = None ) : <EOL> """<STR_LIT>""" <EOL> if data is None : <EOL> return '<STR_LIT>' <EOL> stream = StringIO ( ) <EOL> xml = SimplerXMLGenerator ( stream , self . charset ) <EOL> xml . startDocument ( ) <EOL> xml . startElement ( self . root_tag_name , { } ) <EOL> self . _to_xml ( xml , data ) <EOL> xml . endElement ( self . root_tag_name ) <EOL> xml . endDocument ( ) <EOL> return stream . getvalue ( ) <EOL> def _to_xml ( self , xml , data ) : <EOL> if isinstance ( data , ( list , tuple ) ) : <EOL> for item in data : <EOL> xml . startElement ( self . item_tag_name , { } ) <EOL> self . _to_xml ( xml , item ) <EOL> xml . endElement ( self . item_tag_name ) <EOL> elif isinstance ( data , dict ) : <EOL> for key , value in six . iteritems ( data ) : <EOL> xml . startElement ( key , { } ) <EOL> self . _to_xml ( xml , value ) <EOL> xml . endElement ( key ) <EOL> elif data is None : <EOL> pass <EOL> else : <EOL> xml . characters ( smart_text ( data ) ) </s>
