def get_xml_encoding(source):
 with get_xml_iterator(source) as iterator:
  (start, tag, data, pos) = six.next(iterator)
  if ((not start) or (tag != u'xml')):
   raise IOError(u'Invalid XML file')
 return (data.get(u'encoding') or u'utf-8')

def get_xml_encoding ( source ) : with get_xml_iterator ( source ) as iterator : ( start , tag , data , pos ) = six . next ( iterator ) if ( ( not start ) or ( tag != u'xml' ) ) : raise IOError ( u'Invalid XML file' ) return ( data . get ( u'encoding' ) or u'utf-8' )
determine the encoding of an xml file by reading its header .