Generates the variables to replace in files
181417
def generate_vars(project_name, project_dir):
    

    out = vary_name(project_name)
    out['random_key'] = make_random_key()
    out['settings_file'] = make_file_path(
        project_dir,
        project_name,
        path.join('src', project_name),
        'settings.py',
    )

    return out
495381
function replaceInFile (filename, regex, replacement) {
    log.bright.cyan ('Exporting exchanges →', filename.yellow)
    let contents = fs.readFileSync (filename, 'utf8')
    const newContents = contents.replace (regex, replacement)
    fs.truncateSync (filename)
    fs.writeFileSync (filename, newContents)
}
498783
def substitute_vars(template, replacements):
    
    result = template
    for (key, value) in replacements:
        result = result.replace('${' + key + '}' , value)
    if '${' in result:
        logging.warning("A variable was not replaced in '%s'.", result)
    return result
951042
def gen_textfiles_from_filenames(
        filenames: Iterable[str]) -> Generator[TextIO, None, None]:
    
    for filename in filenames:
        with open(filename) as f:
            yield f
514171
function replaceVars(value, vars) {
        if (typeof value != "string") {
          value = value(vars);
        } else if (vars) {
          value = value.replace(/%(\w+)/g, function (str, name) {
            return vars[name] || str;
          });
        }

        return value;
      }
1209623
def replace_in_files(search, replace, depth=0, paths=None, confirm=True):
    

    # have the user select some files
    if paths==None:
        paths = _s.dialogs.MultipleFiles('DIS AND DAT|*.*')
    if paths == []: return

    for path in paths:
        lines = read_lines(path)

        if depth: N=min(len(lines),depth)
        else:     N=len(lines)

        for n in range(0,N):
            if lines[n].find(search) >= 0:
                lines[n] = lines[n].replace(search,replace)
                print(path.split(_os.path.pathsep)[-1]+ ': "'+lines[n]+'"')

        # only write if we're not confirming
        if not confirm:
            _os.rename(path, path+".backup")
            write_to_file(path, join(lines, ''))

    if confirm:
        if input("yes? ")=="yes":
            replace_in_files(search,replace,depth,paths,False)

    return
1152721
function replaceEnvironmentVariables (fileContent) {
  const environmentVariable = new RegExp(/\${([^}]+)}/g)
  // eslint-disable-next-line
  fileContent = fileContent.replace(environmentVariable, (a, b) => process.env[b] || '')
  return fileContent
}
1255172
protected String replaceVariables(String commentForGenerated, JvmDeclaredType jvmType) {
		String result = commentForGenerated;
		if (result.contains(GENERATED_COMMENT_VAR_SOURCE_FILE)) {
			Resource resource = jvmType.eResource();
			if (resource != null) {
				URI uri = resource.getURI();
				if (uri != null) {
					String sourceFile = uri.lastSegment();
					if (sourceFile == null)
						sourceFile = uri.toString();
					result = result.replace(GENERATED_COMMENT_VAR_SOURCE_FILE, sourceFile);
				}
			}
		}
		return result;
	}
422554
def transform_source(text):
    '''
    '''

    loop_keyword = 'repeat'

    nb = text.count(loop_keyword)
    if nb == 0:
        return text

    var_names = get_unique_variable_names(text, nb)

    toks = tokenize.generate_tokens(StringIO(text).readline)
    result = []
    replacing_keyword = False
    for toktype, tokvalue, _, _, _ in toks:
        if toktype == tokenize.NAME and tokvalue == loop_keyword:
            result.extend([
                (tokenize.NAME, 'for'),
                (tokenize.NAME, var_names.pop()),
                (tokenize.NAME, 'in'),
                (tokenize.NAME, 'range'),
                (tokenize.OP, '(')
            ])
            replacing_keyword = True
        elif replacing_keyword and tokvalue == ':':
            result.extend([
                (tokenize.OP, ')'),
                (tokenize.OP, ':')
            ])
            replacing_keyword = False
        else:
            result.append((toktype, tokvalue))
    return tokenize.untokenize(result)
316116
def _replace_global_vars(xs, global_vars):
    
    if isinstance(xs, (list, tuple)):
        return [_replace_global_vars(x) for x in xs]
    elif isinstance(xs, dict):
        final = {}
        for k, v in xs.items():
            if isinstance(v, six.string_types) and v in global_vars:
                v = global_vars[v]
            final[k] = v
        return final
    else:
        return xs
1157370
function generate(tmpl, src, variables) {
        variables = variables || {};
        variables.FILES = {};
        for (var i = 0; i < src.length; i++) {
            var content = JSON.stringify(grunt.file.read(src[i]));
            variables.FILES[src[i]] = content;
        }
        var template = grunt.file.read(tmpl);
        return substitute(template, variables);
    }
777543
function replace(content, filename) {
    var dirname = nps.dirname(filename)

    return content.replace(
      new RegExp(
        '(^\\s*)' + prefix + '\\s*(.+?)\\s*' + suffix + '(\\s*\\n?)$',
        'gm'
      ),
      // /@\s*(.+?)\s*@/g,
      function(m, preappend, path, newlineOrNull) {
        var currLink = path.trim()
        var fullpath = ''

        // link::[why-need-require]../refs/why-need-require.md
        if (disableValue !== 'link' && currLink.startsWith('link::')) {
          var title = ''
          path = ''

          if (/^link::\[(.+?)\](.+)/.test(currLink)) {
            title = RegExp.$1
            path = RegExp.$2
            title = title && title.trim() ? title.trim() : path
          } else if (/^link::(.+)/.test(currLink)) {
            title = RegExp.$1
            path = RegExp.$1
          }

          fullpath = checkPath(path, dirname, selfFilename, true, alias)

          if (fullpath) {
            var link = findLink(filesMap, fullpath)
            if (link !== false) {
              return preappend + '[' + title + '](' + link + ')' + newlineOrNull
            }
          }
        }

        if (disableValue !== 'file-content') {
          fullpath = checkPath(currLink, dirname, filename, false, alias)
          if (fullpath) {
            var fileContent = fs.readFileSync(fullpath).toString()
            if (deep) {
              fileContent = replace(fileContent, fullpath)
            }

            return fileContent + newlineOrNull
          }
        }

        return m
      }
    )
  }
1022102
function copyReplace( src, dest, replacements ){

        if ( replacements ){
            var source = grunt.file.read( src );
            for ( var s in replacements ){
                var r = replacements[s];
                var re = new RegExp( s, "g" );
                source = source.replace( re, r );
            }
            grunt.file.write( dest, source );
        }
        else{
            grunt.file.copy( src, dest );
        }

	}
868943
def replace(self, infile):
        '''
        '''
        gf = infile[31:]
        same_size_index = []
        while len(same_size_index) <= 1:
            index = random.randint(0,len(gf)-1)
            index_len = len(gf[index])
            same_size_index = [i for (i,g) in enumerate(gf) if len(g) == index_len]
        else:
            same_size_index = random.choice(same_size_index[:])
        gf[index], gf[same_size_index] = gf[same_size_index], gf[index]
        return infile[:31] + gf
910774
function getReplacements() {
    // Get old style variable names.
    $module_data = $this->component_data;

    return array(
      '%module'       => $module_data['root_name'],
      '%Module'       => ucfirst($module_data['readable_name']),
      '%description'  => str_replace("'", "\'", $module_data['short_description']),
      '%name'         => !empty($module_data['readable_name']) ? str_replace("'", "\'", $module_data['readable_name']) : $module_data['root_name'],
      '%help'         => !empty($module_data['module_help_text']) ? str_replace('"', '\"', $module_data['module_help_text']) : 'TODO: Create admin help text.',
      '%readable'     => str_replace("'", "\'", $module_data['readable_name']),
    );
  }
764018
public static String replaceVariables( final VariableResolver pResolver, final String pExpression, final String pOpen, final String pClose ) {
        final char[] open = pOpen.toCharArray();
        final char[] close = pClose.toCharArray();

        final StringBuilder out = new StringBuilder();
        StringBuilder sb = new StringBuilder();
        char[] last = null;
        int wo = 0;
        int wc = 0;
        int level = 0;
        for (char c : pExpression.toCharArray()) {
            if (c == open[wo]) {
                if (wc > 0) {
                    sb.append(close, 0, wc);
                }
                wc = 0;
                wo++;
                if (open.length == wo) {
                    // found open
                    if (last == open) {
                        out.append(open);
                    }
                    level++;
                    out.append(sb);
                    sb = new StringBuilder();
                    wo = 0;
                    last = open;
                }
            } else if (c == close[wc]) {
                if (wo > 0) {
                    sb.append(open, 0, wo);
                }
                wo = 0;
                wc++;
                if (close.length == wc) {
                    // found close
                    if (last == open) {
                        final String variable = pResolver.get(sb.toString());
                        if (variable != null) {
                            out.append(variable);
                        } else {
                            out.append(open);
                            out.append(sb);
                            out.append(close);
                        }
                    } else {
                        out.append(sb);
                        out.append(close);
                    }
                    sb = new StringBuilder();
                    level--;
                    wc = 0;
                    last = close;
                }
            } else {

                if (wo > 0) {
                    sb.append(open, 0, wo);
                }

                if (wc > 0) {
                    sb.append(close, 0, wc);
                }

                sb.append(c);

                wo = wc = 0;
            }
        }

        if (wo > 0) {
            sb.append(open, 0, wo);
        }

        if (wc > 0) {
            sb.append(close, 0, wc);
        }

        if (level > 0) {
            out.append(open);
        }
        out.append(sb);

        return out.toString();
    }
895663
function envReplace(str, vars) {
  return str.replace(/\$?\$\{([A-Za-z0-9_]+)(:-(.*?))?\}/g, function (varStr, varName, _, defValue) {
    // Handle escaping:
    if (varStr.indexOf('$$') === 0) {
      return varStr;
    }
    // Handle simple variable replacement:
    if (vars.hasOwnProperty(varName)) {
      log.debug(`${varName} replaced in configuration file`);
      return vars[varName];
    }
    // Handle default values:
    if (defValue) {
      log.debug(`${varName} replaced with default value in configuration file`);
      return defValue;
    }
    log.warn(`Unknown variable: ${varName}. Returning null.`);
    return null;
  });
}