<s> """<STR_LIT>""" <EOL> import sys <EOL> import pretty <EOL> from curses . ascii import isprint <EOL> try : <EOL> from collections import OrderedDict <EOL> except : <EOL> OrderedDict = dict <EOL> from arraydisposition import * <EOL> array_types = [ ] <EOL> try : <EOL> import Numeric <EOL> array_types . append ( type ( Numeric . array ( [ ] ) ) ) <EOL> except : <EOL> pass <EOL> try : <EOL> import array <EOL> array_types . append ( array . array ) <EOL> except : <EOL> pass <EOL> import simplearray <EOL> array_types . append ( simplearray . SimpleArray ) <EOL> import pretty <EOL> XML_PREPEND_CHAR = '<STR_LIT:_>' <EOL> XML_DUMP_PREPEND_KEYS_AS_TAGS = <NUM_LIT> <EOL> XML_DUMP_SIMPLE_TAGS_AS_ATTRIBUTES = <NUM_LIT> <EOL> XML_DUMP_STRINGS_AS_STRINGS = <NUM_LIT> <EOL> XML_DUMP_STRINGS_BEST_GUESS = <NUM_LIT> <EOL> XML_DUMP_PRETTY = <NUM_LIT> <EOL> XML_DUMP_POD_LIST_AS_XML_LIST = <NUM_LIT> <EOL> XML_DUMP_PREFER_EMPTY_STRINGS = <NUM_LIT> <EOL> XML_DUMP_UNNATURAL_ORDER = <NUM_LIT> <EOL> XML_TAGS_ACCEPTS_DIGITS = <NUM_LIT> <EOL> XML_STRICT_HDR = <NUM_LIT> <EOL> class XMLDumper ( object ) : <EOL> """<STR_LIT>""" <EOL> SILENT_ON_ERROR = <NUM_LIT:1> <EOL> CERR_ON_ERROR = <NUM_LIT:2> <EOL> THROW_ON_ERROR = <NUM_LIT:3> <EOL> def __init__ ( self , os , options = <NUM_LIT:0> , <EOL> array_disposition = ARRAYDISPOSITION_AS_LIST , <EOL> indent_increment = <NUM_LIT:4> , <EOL> prepend_char = XML_PREPEND_CHAR , <EOL> mode = <NUM_LIT:2> ) : <EOL> """<STR_LIT>""" <EOL> if array_disposition == ARRAYDISPOSITION_AS_NUMERIC : <EOL> import Numeric <EOL> if array_disposition == ARRAYDISPOSITION_AS_NUMERIC_WRAPPER : <EOL> import simplearray <EOL> if array_disposition == ARRAYDISPOSITION_AS_PYTHON_ARRAY : <EOL> import array <EOL> self . os_ = os <EOL> self . options_ = options <EOL> self . arrDisp_ = array_disposition <EOL> self . indentIncrement_ = indent_increment <EOL> self . prependChar_ = prepend_char <EOL> self . mode_ = mode <EOL> self . specialCharToEscapeSeq_ = { } <EOL> self . NULLKey_ = None <EOL> self . EMPTYAttrs_ = { } <EOL> self . LISTAttrs_ = { } <EOL> self . DICTTag_ = "<STR_LIT>" <EOL> self . specialCharToEscapeSeq_ [ '<STR_LIT:&>' ] = "<STR_LIT>" <EOL> self . specialCharToEscapeSeq_ [ '<STR_LIT:<>' ] = "<STR_LIT>" <EOL> self . specialCharToEscapeSeq_ [ '<STR_LIT:>>' ] = "<STR_LIT>" <EOL> self . specialCharToEscapeSeq_ [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> self . specialCharToEscapeSeq_ [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> self . LISTAttrs_ [ "<STR_LIT>" ] = "<STR_LIT:list>" <EOL> def XMLDumpValue ( self , value , indent = <NUM_LIT:0> ) : <EOL> "<STR_LIT>" <EOL> self . XMLDumpKeyValue ( self . NULLKey_ , value , indent ) <EOL> def XMLDumpKeyValue ( self , key , value , indent = <NUM_LIT:0> ) : <EOL> "<STR_LIT>" <EOL> self . _XMLHeader ( ) <EOL> if type ( value ) == list : <EOL> a = value <EOL> p = a <EOL> top = { } <EOL> top [ "<STR_LIT>" ] = p <EOL> self . _XMLDumpKeyValue ( key , top , indent ) <EOL> else : <EOL> self . _XMLDumpKeyValue ( key , value , indent ) <EOL> def dump ( self , key , value , indent = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . _XMLDumpKeyValue ( key , value , indent ) <EOL> def dumpValue ( self , value , indent = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . _XMLDumpKeyValue ( self . NULLKey_ , value , indent ) <EOL> def mode ( self , mode ) : <EOL> """<STR_LIT>""" <EOL> self . mode_ = mode <EOL> def _XMLHeader ( self ) : <EOL> if self . options_ & XML_STRICT_HDR : <EOL> self . os_ . write ( "<STR_LIT>" + "<STR_LIT:\n>" ) <EOL> def _XMLDumpKeyValue ( self , key , value , indent = <NUM_LIT:0> , attrs_ptr = None , <EOL> was_array_typecode = None ) : <EOL> t = type ( value ) <EOL> if t == dict : <EOL> if self . options_ & XML_DUMP_UNNATURAL_ORDER : <EOL> self . _XMLDumpTable ( key , value , indent , attrs_ptr , sortkeys = False ) <EOL> else : <EOL> self . _XMLDumpTable ( key , value , indent , attrs_ptr , sortkeys = True ) <EOL> elif t == OrderedDict : <EOL> if self . options_ & XML_DUMP_UNNATURAL_ORDER : <EOL> self . _XMLDumpTable ( key , value , indent , attrs_ptr , sortkeys = True ) <EOL> else : <EOL> self . _XMLDumpTable ( key , value , indent , attrs_ptr , sortkeys = False ) <EOL> elif t == list or t == tuple : <EOL> self . _XMLDumpList ( key , value , indent , was_array_typecode ) <EOL> elif t in array_types : <EOL> self . _XMLDumpPODList ( key , value , indent , - <NUM_LIT:1> , False ) <EOL> else : <EOL> self . _XMLDumpPrimitive ( key , value , indent , attrs_ptr , was_array_typecode ) <EOL> def _XMLDumpName ( self , tag ) : <EOL> if len ( tag ) == <NUM_LIT:0> : <EOL> self . _handleProblem ( "<STR_LIT>" ) <EOL> t = tag <EOL> if t [ <NUM_LIT:0> ] . isdigit ( ) : <EOL> if self . options_ & XML_TAGS_ACCEPTS_DIGITS : <EOL> self . os_ . write ( '<STR_LIT:_>' ) <EOL> else : <EOL> self . _handleProblem ( "<STR_LIT>" + t [ <NUM_LIT:0> ] ) <EOL> elif not ( t [ <NUM_LIT:0> ] . isalpha ( ) or t [ <NUM_LIT:0> ] == '<STR_LIT:_>' ) : <EOL> self . _handleProblem ( "<STR_LIT>" + t [ <NUM_LIT:0> ] ) <EOL> for ii in xrange ( <NUM_LIT:1> , len ( tag ) ) : <EOL> if not ( t [ ii ] . isalnum ( ) or t [ ii ] == '<STR_LIT:_>' or t [ ii ] == '<STR_LIT::>' ) : <EOL> self . _handleProblem ( "<STR_LIT>" + t [ ii ] ) <EOL> self . os_ . write ( tag ) <EOL> def _XMLContentFilter ( self , content , was_array_typecode = None ) : <EOL> result = "<STR_LIT>" <EOL> typecode = { float : '<STR_LIT:d>' , complex : '<STR_LIT:D>' } <EOL> type_content = type ( content ) <EOL> if was_array_typecode != None : <EOL> t = pretty . NumericString_ ( was_array_typecode , content ) <EOL> elif type_content in [ float , complex ] : <EOL> t = pretty . NumericString_ ( typecode [ type_content ] , content ) <EOL> elif type_content == long : <EOL> t = repr ( content ) <EOL> else : <EOL> t = str ( content ) <EOL> for ii in xrange ( <NUM_LIT:0> , len ( t ) ) : <EOL> c = t [ ii ] <EOL> if not isprint ( c ) : <EOL> result += "<STR_LIT>" + hex ( ord ( c ) ) [ <NUM_LIT:1> : ] + "<STR_LIT:;>" <EOL> else : <EOL> if c in self . specialCharToEscapeSeq_ : <EOL> esc_seq = self . specialCharToEscapeSeq_ [ t [ ii ] ] <EOL> result = result + esc_seq <EOL> else : <EOL> result = result + t [ ii ] <EOL> return result <EOL> def _XMLDumpStartTag ( self , tag , attrs , indent , <EOL> primitive_dump = False , none_dump = False , <EOL> was_array_typecode = None ) : <EOL> if tag is self . NULLKey_ : return <EOL> if self . options_ & XML_DUMP_PRETTY : <EOL> self . os_ . write ( '<STR_LIT:U+0020>' * indent ) <EOL> self . os_ . write ( '<STR_LIT:<>' ) <EOL> self . _XMLDumpName ( tag ) <EOL> len_attrs = len ( attrs ) <EOL> if len_attrs >= <NUM_LIT:1> : self . os_ . write ( "<STR_LIT:U+0020>" ) <EOL> where = <NUM_LIT:0> <EOL> for key , val in sorted ( attrs . iteritems ( ) ) : <EOL> attr_name = str ( key ) <EOL> if ( len ( attr_name ) > <NUM_LIT:0> and attr_name [ <NUM_LIT:0> ] == self . prependChar_ and <EOL> ( ( self . options_ & XML_DUMP_PREPEND_KEYS_AS_TAGS ) == <NUM_LIT:0> ) ) : <EOL> attr_name = attr_name [ <NUM_LIT:1> : ] <EOL> attr_val = str ( val ) <EOL> self . _XMLDumpName ( attr_name ) <EOL> self . os_ . write ( "<STR_LIT>" + self . _XMLContentFilter ( attr_val , was_array_typecode ) + "<STR_LIT>" ) <EOL> where += <NUM_LIT:1> <EOL> if ( where != len_attrs ) : <EOL> self . os_ . write ( "<STR_LIT:U+0020>" ) <EOL> if none_dump : self . os_ . write ( "<STR_LIT:/>" ) <EOL> self . os_ . write ( "<STR_LIT:>>" ) <EOL> if ( ( self . options_ & XML_DUMP_PRETTY ) != <NUM_LIT:0> ) and ( not primitive_dump or none_dump ) : <EOL> self . os_ . write ( "<STR_LIT:\n>" ) <EOL> def _XMLDumpEndTag ( self , tag , indent , primitive_dump = False ) : <EOL> if tag is self . NULLKey_ : <EOL> return <EOL> if ( ( self . options_ & XML_DUMP_PRETTY ) and not primitive_dump ) : <EOL> self . os_ . write ( '<STR_LIT:U+0020>' * indent ) <EOL> self . os_ . write ( "<STR_LIT>" + tag + "<STR_LIT:>>" ) <EOL> if ( self . options_ & XML_DUMP_PRETTY ) : <EOL> self . os_ . write ( "<STR_LIT:\n>" ) <EOL> def _IsComposite ( self , v ) : <EOL> t = type ( v ) <EOL> return t in [ tuple , dict , list , OrderedDict ] or t in array_types <EOL> def _FindAttributes ( self , t ) : <EOL> attrs = { } <EOL> if "<STR_LIT>" in t : <EOL> attrs = t [ "<STR_LIT>" ] <EOL> sorted_keys = sorted ( t . keys ( ) ) <EOL> for key in sorted_keys : <EOL> value = t [ key ] <EOL> if key == "<STR_LIT>" : continue <EOL> if key == "<STR_LIT>" : continue <EOL> if ( len ( key ) > <NUM_LIT:0> and key [ <NUM_LIT:0> ] == self . prependChar_ ) : <EOL> if key in attrs : <EOL> self . _handleProblem ( key + string ( "<STR_LIT>" ) + str ( t ) ) <EOL> key_without_underscore = key [ <NUM_LIT:1> : ] <EOL> if ( self . options_ & XML_DUMP_PREPEND_KEYS_AS_TAGS ) == <NUM_LIT:0> : <EOL> attrs [ key_without_underscore ] = value <EOL> continue <EOL> if ( self . options_ & XML_DUMP_SIMPLE_TAGS_AS_ATTRIBUTES ) : <EOL> simple = not self . _IsComposite ( value ) <EOL> if key in attrs : <EOL> self . _handleProblem ( key + string ( "<STR_LIT>" ) + str ( t ) ) <EOL> if simple : <EOL> attrs [ key ] = value <EOL> continue <EOL> return attrs <EOL> def _XMLDumpList ( self , list_name , l , indent , was_array_typecode = None ) : <EOL> if list_name is self . NULLKey_ : <EOL> tag = "<STR_LIT>" <EOL> else : <EOL> tag = list_name <EOL> if len ( l ) == <NUM_LIT:0> : <EOL> self . _XMLDumpPrimitive ( tag , None , indent , self . LISTAttrs_ ) <EOL> return <EOL> for ii in xrange ( <NUM_LIT:0> , len ( l ) ) : <EOL> key_to_use = self . NULLKey_ <EOL> value_ptr = l [ ii ] <EOL> table_inside_value = type ( value_ptr ) == dict or type ( value_ptr ) == OrderedDict <EOL> indent_inc = self . indentIncrement_ <EOL> attrs = { } <EOL> if ( table_inside_value ) : <EOL> indent_inc = <NUM_LIT:0> <EOL> attrs = self . _FindAttributes ( value_ptr ) <EOL> if ( "<STR_LIT>" in value_ptr ) : <EOL> value_ptr = value_ptr [ "<STR_LIT>" ] <EOL> if ( type ( value_ptr ) == dict or type ( value_ptr ) == OrderedDict ) and len ( value_ptr ) == <NUM_LIT:0> and len ( l ) == <NUM_LIT:1> : <EOL> indent_inc = self . indentIncrement_ <EOL> key_to_use = self . DICTTag_ <EOL> elif type ( value_ptr ) in array_types and self . arrDisp_ != ARRAYDISPOSITION_AS_LIST : <EOL> self . _XMLDumpPODList ( tag , value_ptr , indent , ii , <EOL> ( ii == <NUM_LIT:0> and len ( l ) == <NUM_LIT:1> ) ) <EOL> continue <EOL> if ( ii == <NUM_LIT:0> and len ( l ) == <NUM_LIT:1> ) : <EOL> attrs [ "<STR_LIT>" ] = "<STR_LIT:list>" <EOL> primitive_type = not self . _IsComposite ( value_ptr ) <EOL> self . _XMLDumpStartTag ( tag , attrs , indent , primitive_type , False , <EOL> was_array_typecode ) <EOL> self . _XMLDumpKeyValue ( key_to_use , value_ptr , indent + indent_inc , None , <EOL> was_array_typecode ) <EOL> self . _XMLDumpEndTag ( tag , indent , primitive_type ) <EOL> def _XMLDumpPODList ( self , list_name , l , <EOL> indent , inside_list_number , add_type ) : <EOL> tag = list_name <EOL> if self . arrDisp_ == ARRAYDISPOSITION_AS_LIST : <EOL> was_array_typecode = l . typecode <EOL> if callable ( l . typecode ) : was_array_typecode = l . typecode ( ) <EOL> if not was_array_typecode in [ '<STR_LIT:f>' , '<STR_LIT:F>' , '<STR_LIT:d>' , '<STR_LIT:D>' ] : <EOL> was_array_typecode = None <EOL> l = l . tolist ( ) <EOL> if was_array_typecode == None : <EOL> l = [ int ( x ) for x in l ] <EOL> self . _XMLDumpList ( list_name , l , indent , was_array_typecode ) <EOL> return <EOL> attrs = { } <EOL> lookup_table = { '<STR_LIT:1>' : '<STR_LIT:s>' , '<STR_LIT:b>' : '<STR_LIT:S>' , '<STR_LIT:s>' : '<STR_LIT:i>' , '<STR_LIT:w>' : '<STR_LIT:I>' , '<STR_LIT:i>' : '<STR_LIT:l>' , '<STR_LIT:u>' : '<STR_LIT:L>' , '<STR_LIT:l>' : '<STR_LIT:x>' , '<STR_LIT:f>' : '<STR_LIT:f>' , '<STR_LIT:d>' : '<STR_LIT:d>' , '<STR_LIT:F>' : '<STR_LIT:F>' , '<STR_LIT:D>' : '<STR_LIT:D>' } <EOL> bytetag = lookup_table [ l . typecode ( ) ] <EOL> if ( self . options_ & XML_DUMP_POD_LIST_AS_XML_LIST ) : <EOL> attrs [ "<STR_LIT>" ] = bytetag <EOL> else : <EOL> attrs [ "<STR_LIT>" ] = bytetag <EOL> primitive_type = True <EOL> temp = None <EOL> inner_tag = tag <EOL> if ( self . options_ & XML_DUMP_POD_LIST_AS_XML_LIST ) : <EOL> if ( inside_list_number != - <NUM_LIT:1> ) : <EOL> inner_attrs = { } <EOL> if inside_list_number == <NUM_LIT:0> and add_type : <EOL> inner_attrs [ "<STR_LIT>" ] = "<STR_LIT:list>" <EOL> self . _XMLDumpStartTag ( tag , inner_attrs , indent , False ) <EOL> inner_tag = "<STR_LIT:list>" + str ( inside_list_number ) + "<STR_LIT>" <EOL> indent += self . indentIncrement_ <EOL> if len ( l ) == <NUM_LIT:0> : <EOL> self . _XMLDumpStartTag ( inner_tag , attrs , indent , primitive_type ) <EOL> self . _XMLDumpEndTag ( inner_tag , indent , primitive_type ) <EOL> else : <EOL> for ii in xrange ( <NUM_LIT:0> , len ( l ) ) : <EOL> self . _XMLDumpStartTag ( inner_tag , attrs , indent , primitive_type ) <EOL> temp = pretty . NumericString_ ( bytetag , l [ ii ] ) <EOL> self . os_ . write ( temp ) <EOL> self . _XMLDumpEndTag ( inner_tag , indent , primitive_type ) <EOL> if ( inside_list_number != - <NUM_LIT:1> ) : <EOL> indent -= self . indentIncrement_ <EOL> self . _XMLDumpEndTag ( tag , indent , False ) <EOL> else : <EOL> if ( inside_list_number == <NUM_LIT:0> and add_type ) : attrs [ "<STR_LIT>" ] = "<STR_LIT:list>" <EOL> self . _XMLDumpStartTag ( tag , attrs , indent , primitive_type ) <EOL> for ii in xrange ( <NUM_LIT:0> , len ( l ) ) : <EOL> temp = pretty . NumericString_ ( bytetag , l [ ii ] ) <EOL> self . os_ . write ( temp ) <EOL> if ( ii < len ( l ) - <NUM_LIT:1> ) : self . os_ . write ( "<STR_LIT:U+002C>" ) <EOL> self . _XMLDumpEndTag ( tag , indent , primitive_type ) <EOL> def _XMLDumpTable ( self , dict_name , t , indent , attrs_ptr , sortkeys ) : <EOL> if "<STR_LIT>" in t : <EOL> attrs = self . _FindAttributes ( t ) <EOL> self . _XMLDumpKeyValue ( dict_name , t [ "<STR_LIT>" ] , indent , attrs ) <EOL> return <EOL> if attrs_ptr == None : <EOL> attrs = self . _FindAttributes ( t ) <EOL> else : <EOL> attrs = attrs_ptr <EOL> self . _XMLDumpStartTag ( dict_name , attrs , indent ) <EOL> keys = t . keys ( ) <EOL> if sortkeys : keys . sort ( ) <EOL> for key in keys : <EOL> value = t [ key ] <EOL> k = str ( key ) <EOL> if key in attrs or k == "<STR_LIT>" or ( len ( k ) > <NUM_LIT:0> and k [ <NUM_LIT:0> ] == self . prependChar_ and k [ <NUM_LIT:1> : ] in attrs ) : <EOL> continue <EOL> self . _XMLDumpKeyValue ( key , value , indent + self . indentIncrement_ ) <EOL> self . _XMLDumpEndTag ( dict_name , indent ) <EOL> def _XMLDumpPrimitive ( self , key , value , indent , attrs_ptr , was_array_typecode = None ) : <EOL> if attrs_ptr is None : <EOL> attrs = self . EMPTYAttrs_ <EOL> else : <EOL> attrs = attrs_ptr <EOL> if ( self . _IsComposite ( value ) ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if value is None : <EOL> self . _XMLDumpStartTag ( key , attrs , indent , True , True ) <EOL> return <EOL> self . _XMLDumpStartTag ( key , attrs , indent , True ) <EOL> if ( self . options_ & XML_DUMP_STRINGS_AS_STRINGS ) : <EOL> if ( type ( value ) == str ) : <EOL> self . os_ . write ( self . _XMLContentFilter ( repr ( value ) , was_array_typecode ) ) <EOL> else : <EOL> self . os_ . write ( self . _XMLContentFilter ( value , was_array_typecode ) ) <EOL> elif ( self . options_ & XML_DUMP_STRINGS_BEST_GUESS ) : <EOL> if ( type ( value ) == str ) : <EOL> s = str ( value ) <EOL> if ( len ( s ) == <NUM_LIT:0> or <EOL> ( ( len ( s ) > <NUM_LIT:0> ) and <EOL> ( s [ <NUM_LIT:0> ] . isdigit ( ) or s [ <NUM_LIT:0> ] == '<STR_LIT:(>' or s [ <NUM_LIT:0> ] == '<STR_LIT:->' or s [ <NUM_LIT:0> ] == '<STR_LIT:+>' ) ) ) : <EOL> self . os_ . write ( self . _XMLContentFilter ( repr ( value ) , was_array_typecode ) ) <EOL> else : <EOL> self . os_ . write ( self . _XMLContentFilter ( value , was_array_typecode ) ) <EOL> else : <EOL> self . os_ . write ( self . _XMLContentFilter ( value , was_array_typecode ) ) <EOL> else : <EOL> if ( self . options_ & XML_DUMP_PREFER_EMPTY_STRINGS ) : <EOL> if type ( value ) == str and len ( value ) == <NUM_LIT:0> : <EOL> value = "<STR_LIT>" <EOL> self . os_ . write ( self . _XMLContentFilter ( value , was_array_typecode ) ) <EOL> self . _XMLDumpEndTag ( key , indent , True ) <EOL> def _handleProblem ( self , text ) : <EOL> if ( self . mode_ == XMLDumper . SILENT_ON_ERROR ) : return <EOL> if ( self . mode_ == XMLDumper . THROW_ON_ERROR ) : <EOL> raise Exception , text <EOL> sys . stderr . write ( text + "<STR_LIT:\n>" ) <EOL> def WriteToXMLStream ( v , ofs , top_level_key = None , <EOL> options = XML_DUMP_PRETTY | XML_STRICT_HDR | XML_DUMP_STRINGS_BEST_GUESS , <EOL> arr_disp = ARRAYDISPOSITION_AS_NUMERIC_WRAPPER , <EOL> prepend_char = XML_PREPEND_CHAR ) : <EOL> """<STR_LIT>""" <EOL> indent = <NUM_LIT:2> <EOL> xd = XMLDumper ( ofs , options , arr_disp , indent , prepend_char , <EOL> XMLDumper . THROW_ON_ERROR ) <EOL> if top_level_key == None : <EOL> xd . XMLDumpValue ( v ) <EOL> else : <EOL> xd . XMLDumpKeyValue ( top_level_key , v ) <EOL> def WriteToXMLFile ( v , filename , top_level_key = None , <EOL> options = XML_DUMP_PRETTY | XML_STRICT_HDR | XML_DUMP_STRINGS_BEST_GUESS , <EOL> arr_disp = ARRAYDISPOSITION_AS_NUMERIC_WRAPPER , <EOL> prepend_char = XML_PREPEND_CHAR ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> ofs = open ( filename , '<STR_LIT:w>' ) <EOL> WriteToXMLStream ( v , ofs , top_level_key , options , arr_disp , prepend_char ) <EOL> except Exception , e : <EOL> raise Exception , e <EOL> import cStringIO <EOL> def ConvertToXML ( given_dict ) : <EOL> """<STR_LIT>""" <EOL> stream_thing = cStringIO . StringIO ( ) <EOL> WriteToXMLStream ( given_dict , stream_thing , '<STR_LIT>' ) <EOL> return stream_thing . getvalue ( ) </s>
