<s> """<STR_LIT>""" <EOL> from google . appengine . ext . bulkload import bulkloader_errors <EOL> from google . appengine . ext . bulkload import connector_interface <EOL> class SimpleTextConnector ( connector_interface . ConnectorInterface ) : <EOL> """<STR_LIT>""" <EOL> VALID_MODES = ( '<STR_LIT:text>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ classmethod <EOL> def create_from_options ( cls , options , name ) : <EOL> """<STR_LIT>""" <EOL> template = options . get ( '<STR_LIT>' ) <EOL> if not template : <EOL> raise bulkloader_errors . InvalidConfiguration ( <EOL> '<STR_LIT>' % name ) <EOL> prolog = options . get ( '<STR_LIT>' ) <EOL> epilog = options . get ( '<STR_LIT>' ) <EOL> mode = options . get ( '<STR_LIT>' , '<STR_LIT:text>' ) <EOL> return cls ( template , prolog , epilog , mode , name ) <EOL> def __init__ ( self , template , prolog = None , epilog = None , mode = '<STR_LIT:text>' , name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if mode not in self . VALID_MODES : <EOL> raise bulkloader_errors . InvalidConfiguration ( <EOL> '<STR_LIT>' % <EOL> ( '<STR_LIT>' . join ( self . VALID_MODES ) , name ) ) <EOL> self . template = template <EOL> self . prolog = prolog <EOL> self . epilog = epilog <EOL> self . mode = mode <EOL> self . export_file_pointer = None <EOL> def initialize_export ( self , filename , bulkload_state ) : <EOL> """<STR_LIT>""" <EOL> self . bulkload_state = bulkload_state <EOL> mode = '<STR_LIT:w>' <EOL> if self . mode == '<STR_LIT>' : <EOL> mode = '<STR_LIT:wb>' <EOL> self . export_file_pointer = open ( filename , mode ) <EOL> if self . prolog : <EOL> self . export_file_pointer . write ( self . prolog ) <EOL> if self . mode == '<STR_LIT:text>' : <EOL> self . export_file_pointer . write ( '<STR_LIT:\n>' ) <EOL> def write_dict ( self , dictionary ) : <EOL> """<STR_LIT>""" <EOL> self . export_file_pointer . write ( self . template % dictionary ) <EOL> if self . mode == '<STR_LIT:text>' : <EOL> self . export_file_pointer . write ( '<STR_LIT:\n>' ) <EOL> def finalize_export ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . epilog : <EOL> self . export_file_pointer . write ( self . epilog ) <EOL> if self . mode == '<STR_LIT:text>' : <EOL> self . export_file_pointer . write ( '<STR_LIT:\n>' ) <EOL> self . export_file_pointer . close ( ) </s>
