#NEWLINE# def xml_remove_namespaces( xml_bytes ) : #NEWLINE# #INDENT# '\n    Given a stream of xml bytes, strip all namespaces from tag and attribute\n    names.\n    ' #NEWLINE# try : #NEWLINE# #INDENT# root = parse_xml_from_string ( xml_bytes , remove_namespaces = False ) #NEWLINE# #UNINDENT# except ( SyntaxError , ExpatError ) : #NEWLINE# #INDENT# raise MalformedDocxException ( 'This document cannot be converted.' ) #NEWLINE# #UNINDENT# for child in el_iter ( root ) : #NEWLINE# #INDENT# child . tag = child . tag . split ( '}' ) [ ( - 1 ) ] #NEWLINE# child . attrib = dict ( ( ( k . split ( '}' ) [ ( - 1 ) ] , v ) for ( k , v ) in child . attrib . items ( ) ) ) #NEWLINE# #UNINDENT# return cElementTree . tostring ( root , encoding = 'utf-8' )