def convert_newlines(fname, in_place=True, tmp_dir=None, tmp_prefix=None):
 (fd, temp_name) = tempfile.mkstemp(prefix=tmp_prefix, dir=tmp_dir)
 fp = os.fdopen(fd, 'wt')
 i = None
 for (i, line) in enumerate(open(fname, 'U')):
  fp.write(('%s\n' % line.rstrip('\r\n')))
 fp.close()
 if (i is None):
  i = 0
 else:
  i += 1
 if in_place:
  shutil.move(temp_name, fname)
  return (i, None)
 else:
  return (i, temp_name)

def convert_newlines ( fname , in_place = True , tmp_dir = None , tmp_prefix = None ) : ( fd , temp_name ) = tempfile . mkstemp ( prefix = tmp_prefix , dir = tmp_dir ) fp = os . fdopen ( fd , 'wt' ) i = None for ( i , line ) in enumerate ( open ( fname , 'U' ) ) : fp . write ( ( '%s\n' % line . rstrip ( '\r\n' ) ) ) fp . close ( ) if ( i is None ) : i = 0 else : i += 1 if in_place : shutil . move ( temp_name , fname ) return ( i , None ) else : return ( i , temp_name )
converts in place a file from universal line endings to posix line endings .