:param kwargs: Pass lists to distribute as lists, lists that should be passed intact as tuples.
  :return: results, in the format [(arguments, results)].  Also saved to json at resultName, in the same format.
768454
def runMultiprocessNoiseExperiment(resultName, repeat, numWorkers,
                                   appendResults, **kwargs):
  
  experiments = [{}]
  for key, values in kwargs.items():
    if type(values) is list:
      newExperiments = []
      for experiment in experiments:
        for val in values:
          newExperiment = copy(experiment)
          newExperiment[key] = val
          newExperiments.append(newExperiment)
      experiments = newExperiments
    else:
      [a.__setitem__(key, values) for a in experiments]

  newExperiments = []
  for experiment in experiments:
    for _ in xrange(repeat):
      newExperiments.append(copy(experiment))
  experiments = newExperiments

  if numWorkers > 1:
    pool = Pool(processes=numWorkers)
    rs = pool.map_async(experimentWrapper, experiments, chunksize=1)
    while not rs.ready():
      remaining = rs._number_left
      pctDone = 100.0 - (100.0*remaining) / len(experiments)
      print "    =>", remaining, "experiments remaining, percent complete=",pctDone
      time.sleep(5)
    pool.close()  # No more work
    pool.join()
    result = rs.get()
  else:
    result = []
    for arg in experiments:
      result.append(doExperiment(**arg))

  # Save results for later use
  results = [(arg,res) for arg, res in zip(experiments, result)]

  if appendResults:
    try:
      with open(os.path.join(SCRIPT_DIR, resultName), "r") as f:
        existingResults = json.load(f)
        results = existingResults + results
    except IOError:
      pass

  with open(os.path.join(SCRIPT_DIR, resultName),"wb") as f:
    print "Writing results to {}".format(resultName)
    json.dump(results,f)

  return results
499674
def results(self):
        
        self.__init()
        for k,v in self._results.items():
            param = self._get_json(v['paramUrl'])
            if param['dataType'] == "GPFeatureRecordSetLayer":
                self._results[k] = GPFeatureRecordSetLayer.fromJSON(json.dumps(param))
            elif param['dataType'].lower().find('gpmultivalue') > -1:
                self._results[k] = GPMultiValue.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPString":
                self._results[k] = GPString.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPLong":
                self._results[k] = GPLong.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPDouble":
                self._results[k] = GPDouble.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPDate":
                self._results[k] = GPDate.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPBoolean":
                self._results[k] = GPBoolean.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPDataFile":
                self._results[k] = GPDataFile.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPLinearUnit":
                self._results[k] = GPLinearUnit.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPMultiValue":
                self._results[k] = GPMultiValue.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPRasterData":
                self._results[k] = GPRasterData.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPRasterDataLayer":
                self._results[k] = GPRasterDataLayer.fromJSON(json.dumps(param))
            elif param['dataType'] == "GPRecordSet":
                self._results[k] = GPRecordSet.fromJSON(json.dumps(param))
        return self._results
56411
def get_kwargs(**kwargs):
        
        d = dict()
        for k, v in kwargs.iteritems():
            if v is not NOTSET:
                d[k] = v
        return d
671276
def to_paginated_list(self, result, _ns, _operation, **kwargs):
        
        items, context = self.parse_result(result)
        headers = dict()
        paginated_list = PaginatedList(
            items=items,
            _page=self,
            _ns=_ns,
            _operation=_operation,
            _context=context,
        )
        return paginated_list, headers
136906
def prepare_args(self, args, kwargs):
        
        args, kwargs = super().prepare_args(args, kwargs)
        form_kwargs = self.get_form_kwargs()
        self.form = self.Form(**form_kwargs)
        return args, kwargs
1043184
def _get_task_kwargs(self):
        
        res = {}
        for (param_name, param_obj) in self._get_task_cls().get_params():
            attr = getattr(self.known_args, param_name)
            if attr:
                res.update(((param_name, param_obj.parse(attr)),))

        return res
392820
def results(self, *args, **kwargs):
        
        def worker():
            kwargs['page'] = 1
            while True:
                response = self.client(*args, **kwargs)
                if isinstance(response, list):
                    yield response
                    break
                elif _is_page(response):
                    yield response['results']
                    if response['next']:
                        kwargs['page'] += 1
                    else:
                        break
                else:
                    raise NoResultsError(response)

        return itertools.chain.from_iterable(worker())
51597
def _list_args_kwargs(self):
        

        params = []
        params.extend(self._positional_args)
        params.extend(['{k}={v}'.format(k=k, v=v) for k, v in
                       self._key_value_args.items()])

        return params
728966
def _convert_args(args):
    '''
    
    '''
    converted = []
    for arg in args:
        if isinstance(arg, dict):
            for key in list(arg.keys()):
                if key == '__kwarg__':
                    continue
                converted.append('{0}={1}'.format(key, arg[key]))
        else:
            converted.append(arg)
    return converted
305050
def get_join_parameters(join_kwargs):
    

    by = join_kwargs.get('by', None)
    suffixes = join_kwargs.get('suffixes', ('_x', '_y'))
    if isinstance(by, tuple):
        left_on, right_on = by
    elif isinstance(by, list):
        by = [x if isinstance(x, tuple) else (x, x) for x in by]
        left_on, right_on = (list(x) for x in zip(*by))
    else:
        left_on, right_on = by, by
    return left_on, right_on, suffixes
1156826
def get_args_tuple(args, kwargs, arg_names, kwargs_defaults):
    """"""
    args_list = list(args)
    args_len = len(args)
    all_args_len = len(arg_names)
    try:
        while args_len < all_args_len:
            arg_name = arg_names[args_len]
            if arg_name in kwargs_defaults:
                args_list.append(kwargs.get(arg_name, kwargs_defaults[arg_name]))
            else:
                args_list.append(kwargs[arg_name])
            args_len += 1
    except KeyError as e:
        raise TypeError("Missing argument %r" % (e.args[0],))
    return tuple(args_list)
50814
def createArgs(**kwargs):
  
  if len(kwargs) == 0: return [{}]
  kargs = deepcopy(kwargs)
  k1 = kargs.keys()[0]
  values = kargs.pop(k1)
  args = []

  # Get all other combinations
  otherArgs = createArgs(**kargs)

  # Create combinations for values associated with k1
  for v in values:
    newArgs = deepcopy(otherArgs)
    arg = {k1: v}
    for newArg in newArgs:
      newArg.update(arg)
      args.append(newArg)

  return args
1007567
def kwargs(self):
    
    return {k: v for k, v in self._kwargs.items() if k not in self._INTERNAL_FIELDS}
753575
def extract_kwargs(names:Collection[str], kwargs:KWArgs):
    ""
    new_kwargs = {}
    for arg_name in names:
        if arg_name in kwargs:
            arg_val = kwargs.pop(arg_name)
            new_kwargs[arg_name] = arg_val
    return new_kwargs, kwargs
1211602
def expandParameters(*args):
    
    count = 1
    for arg in args:
        count = max(len(arg[0]), count)
    results = []
    for arg in args:
        results.append(expandValues(arg[0], count, args[1]))
    return tuple(results)
84827
def convert_kwargs_to_cmd_line_args(kwargs):
    """"""
    args = []
    for k in sorted(kwargs.keys()):
        v = kwargs[k]
        args.append('-{}'.format(k))
        if v is not None:
            args.append('{}'.format(v))
    return args
486066
def to_json(value, **kwargs):
        
        def _recurse_list(val):
            if val and isinstance(val[0], list):
                return [_recurse_list(v) for v in val]
            return [str(v) if np.isnan(v) or np.isinf(v) else v for v in val]
        return _recurse_list(value.tolist())