def torrent_to_file(target_file, data):
 try:
  with open(target_file, 'wb') as fp:
   fp.write(data)
 except IOError as e:
  logger.error("Could not write torrent file '%s': %s. Skipping.", target_file, e.message)
  return
 if headphones.CONFIG.FILE_PERMISSIONS_ENABLED:
  try:
   os.chmod(target_file, int(headphones.CONFIG.FILE_PERMISSIONS, 8))
  except OSError as e:
   logger.warn("Could not change permissions for file '%s': %s. Continuing.", target_file.decode(headphones.SYS_ENCODING, 'replace'), e.message)
 else:
  logger.debug('Not changing file permissions, since it is disabled: %s', target_file.decode(headphones.SYS_ENCODING, 'replace'))
 return True

def torrent_to_file ( target_file , data ) : try : with open ( target_file , 'wb' ) as fp : fp . write ( data ) except IOError as e : logger . error ( "Could not write torrent file '%s': %s. Skipping." , target_file , e . message ) return if headphones . CONFIG . FILE_PERMISSIONS_ENABLED : try : os . chmod ( target_file , int ( headphones . CONFIG . FILE_PERMISSIONS , 8 ) ) except OSError as e : logger . warn ( "Could not change permissions for file '%s': %s. Continuing." , target_file . decode ( headphones . SYS_ENCODING , 'replace' ) , e . message ) else : logger . debug ( 'Not changing file permissions, since it is disabled: %s' , target_file . decode ( headphones . SYS_ENCODING , 'replace' ) ) return True
write torrent data to file .