@contextmanager
def safe_args(args, options, max_args=None, argfile=None, delimiter=u'\n', quoter=None, delete=True):
 max_args = (max_args or options.max_subprocess_args)
 if (len(args) > max_args):
  def create_argfile(f):
   f.write(delimiter.join(args))
   f.close()
   return [(quoter(f.name) if quoter else u'@{}'.format(f.name))]
  if argfile:
   try:
    with safe_open(argfile, u'w') as fp:
     (yield create_argfile(fp))
   finally:
    if (delete and os.path.exists(argfile)):
     os.unlink(argfile)
  else:
   with temporary_file(cleanup=delete) as fp:
    (yield create_argfile(fp))
 else:
  (yield args)

@ contextmanager def safe_args ( args , options , max_args = None , argfile = None , delimiter = u'\n' , quoter = None , delete = True ) : max_args = ( max_args or options . max_subprocess_args ) if ( len ( args ) > max_args ) : def create_argfile ( f ) : f . write ( delimiter . join ( args ) ) f . close ( ) return [ ( quoter ( f . name ) if quoter else u'@{}' . format ( f . name ) ) ] if argfile : try : with safe_open ( argfile , u'w' ) as fp : ( yield create_argfile ( fp ) ) finally : if ( delete and os . path . exists ( argfile ) ) : os . unlink ( argfile ) else : with temporary_file ( cleanup = delete ) as fp : ( yield create_argfile ( fp ) ) else : ( yield args )
yields args if there are less than a limit otherwise writes args to an argfile and yields an argument list with one argument formed from the path of the argfile .