<s> """<STR_LIT>""" <EOL> try : <EOL> from xml . etree . cElementTree import iterparse <EOL> except ImportError : <EOL> from xml . etree . ElementTree import iterparse <EOL> from ... . compat import ifilter <EOL> from ... . compat import BytesIO as StringIO <EOL> from . . cell import Cell , coordinate_from_string <EOL> from . . worksheet import Worksheet <EOL> def _get_xml_iter ( xml_source ) : <EOL> if not hasattr ( xml_source , '<STR_LIT:name>' ) : <EOL> return StringIO ( xml_source ) <EOL> else : <EOL> xml_source . seek ( <NUM_LIT:0> ) <EOL> return xml_source <EOL> def read_dimension ( xml_source ) : <EOL> source = _get_xml_iter ( xml_source ) <EOL> it = iterparse ( source ) <EOL> for event , element in it : <EOL> if element . tag == '<STR_LIT>' : <EOL> ref = element . get ( '<STR_LIT>' ) <EOL> min_range , max_range = ref . split ( '<STR_LIT::>' ) <EOL> min_col , min_row = coordinate_from_string ( min_range ) <EOL> max_col , max_row = coordinate_from_string ( max_range ) <EOL> return min_col , min_row , max_col , max_row <EOL> else : <EOL> element . clear ( ) <EOL> return None <EOL> def filter_cells ( x ) : <EOL> ( event , element ) = x <EOL> return element . tag == '<STR_LIT>' <EOL> def fast_parse ( ws , xml_source , string_table , style_table ) : <EOL> source = _get_xml_iter ( xml_source ) <EOL> it = iterparse ( source ) <EOL> for event , element in ifilter ( filter_cells , it ) : <EOL> value = element . findtext ( '<STR_LIT>' ) <EOL> if value is not None : <EOL> coordinate = element . get ( '<STR_LIT:r>' ) <EOL> data_type = element . get ( '<STR_LIT:t>' , '<STR_LIT:n>' ) <EOL> style_id = element . get ( '<STR_LIT:s>' ) <EOL> if data_type == Cell . TYPE_STRING : <EOL> value = string_table . get ( int ( value ) ) <EOL> ws . cell ( coordinate ) . value = value <EOL> if style_id is not None : <EOL> ws . _styles [ coordinate ] = style_table . get ( int ( style_id ) ) <EOL> element . clear ( ) <EOL> from . . reader . iter_worksheet import IterableWorksheet <EOL> def read_worksheet ( xml_source , parent , preset_title , string_table , <EOL> style_table , workbook_name = None , sheet_codename = None ) : <EOL> """<STR_LIT>""" <EOL> if workbook_name and sheet_codename : <EOL> ws = IterableWorksheet ( parent , preset_title , workbook_name , <EOL> sheet_codename , xml_source ) <EOL> else : <EOL> ws = Worksheet ( parent , preset_title ) <EOL> fast_parse ( ws , xml_source , string_table , style_table ) <EOL> return ws </s>
