<s> from __future__ import absolute_import <EOL> """<STR_LIT>""" <EOL> from openpyxl . compat import unicode <EOL> from openpyxl . utils . indexed_list import IndexedList <EOL> from openpyxl . xml . functions import fromstring , safe_iterator <EOL> from openpyxl . xml . constants import SHEET_MAIN_NS , XML_NS <EOL> def read_string_table ( xml_source ) : <EOL> """<STR_LIT>""" <EOL> root = fromstring ( text = xml_source ) <EOL> nodes = safe_iterator ( root , '<STR_LIT>' % SHEET_MAIN_NS ) <EOL> strings = ( get_string ( node ) for node in nodes ) <EOL> return IndexedList ( strings ) <EOL> def get_string ( string_index_node ) : <EOL> """<STR_LIT>""" <EOL> rich_nodes = string_index_node . findall ( '<STR_LIT>' % SHEET_MAIN_NS ) <EOL> if rich_nodes : <EOL> reconstructed_text = [ ] <EOL> for rich_node in rich_nodes : <EOL> partial_text = get_text ( rich_node ) <EOL> reconstructed_text . append ( partial_text ) <EOL> return unicode ( '<STR_LIT>' . join ( reconstructed_text ) ) <EOL> return get_text ( string_index_node ) <EOL> def get_text ( rich_node ) : <EOL> """<STR_LIT>""" <EOL> text_node = rich_node . find ( '<STR_LIT>' % SHEET_MAIN_NS ) <EOL> text = text_node . text or unicode ( '<STR_LIT>' ) <EOL> if text_node . get ( '<STR_LIT>' % XML_NS ) != '<STR_LIT>' : <EOL> text = text . strip ( ) <EOL> text = text . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return unicode ( text ) </s>
