8import xml.etree.ElementTree
as ET
13 """Try to decode byte strings to unicode.
14 This can only be a guess, but this might be better than failing.
15 It is safe to use this on numbers
or strings that are already unicode.
17 if isinstance(string, compat.unicode):
18 unicode_string = string
19 elif isinstance(string, compat.bytes):
22 encoding = sys.stdin.encoding
24 encoding = locale.getpreferredencoding()
25 unicode_string = string.decode(encoding,
"ignore")
27 unicode_string = compat.unicode(string)
28 return unicode_string.replace(
'\x00',
'').strip()
31 """Given a bytestring or a file-like object that will produce them,
32 parse and return an ElementTree.
34 if isinstance(bytes_or_file, compat.basestring):
37 s = bytes_or_file.read()
42 f = compat.StringIO(s)
43 tree = ET.ElementTree(file=f)
def _unicode(string, encoding=None)
def bytes_to_elementtree(bytes_or_file)