def _sort_records_map(records):
 ctx = context.get()
 l = len(records)
 key_records = ([None] * l)
 logging.debug('Parsing')
 for i in range(l):
  proto = file_service_pb.KeyValue()
  proto.ParseFromString(records[i])
  key_records[i] = (proto.key(), records[i])
 logging.debug('Sorting')
 key_records.sort(cmp=_compare_keys)
 logging.debug('Writing')
 blob_file_name = (((ctx.mapreduce_spec.name + '-') + ctx.mapreduce_id) + '-output')
 output_path = files.blobstore.create(_blobinfo_uploaded_filename=blob_file_name)
 with output_writers.RecordsPool(output_path, ctx=ctx) as pool:
  for key_record in key_records:
   pool.append(key_record[1])
 logging.debug('Finalizing')
 files.finalize(output_path)
 output_path = files.blobstore.get_file_name(files.blobstore.get_blob_key(output_path))
 entity = _OutputFile(key_name=output_path, parent=_OutputFile.get_root_key(ctx.mapreduce_id))
 entity.put()

def _sort_records_map ( records ) : ctx = context . get ( ) l = len ( records ) key_records = ( [ None ] * l ) logging . debug ( 'Parsing' ) for i in range ( l ) : proto = file_service_pb . KeyValue ( ) proto . ParseFromString ( records [ i ] ) key_records [ i ] = ( proto . key ( ) , records [ i ] ) logging . debug ( 'Sorting' ) key_records . sort ( cmp = _compare_keys ) logging . debug ( 'Writing' ) blob_file_name = ( ( ( ctx . mapreduce_spec . name + '-' ) + ctx . mapreduce_id ) + '-output' ) output_path = files . blobstore . create ( _blobinfo_uploaded_filename = blob_file_name ) with output_writers . RecordsPool ( output_path , ctx = ctx ) as pool : for key_record in key_records : pool . append ( key_record [ 1 ] ) logging . debug ( 'Finalizing' ) files . finalize ( output_path ) output_path = files . blobstore . get_file_name ( files . blobstore . get_blob_key ( output_path ) ) entity = _OutputFile ( key_name = output_path , parent = _OutputFile . get_root_key ( ctx . mapreduce_id ) ) entity . put ( )
map function sorting records .