模板 filename 规范检查 保证 include 语法引用的是相对路径
174023
function (uri, fromUri, source) {
        if (!/^\./.test(uri) || EXTNAME_RE.test(uri)) {

            var line;

            // 如果只出现一次这个字符串，很容易确认模板错误行
            if (source.split(uri).length === 2) {
                source.split(/\n/).forEach(function (code, index) {
                    if (code.indexOf(uri) !== -1) {
                        line = index + 1;
                        source = code.trim();
                    }
                });
            }

            var error = {
                name: 'Syntax Error',
                line: line,
                source: source,
                message: 'Template must be a relative path, and can not have a suffix.'
            };

            if (fromUri) {
                error.filename = fromUri;
            }

            throw error;
        }
    }
392275
def filename_to_module(filename):
    
    find = re.compile(r"^[^.|-]*")
    name = re.search(find, filename).group(0)
    return name
197505
def SaveName_Conv(Mod=None, Cls=None, Type=None, Name=None, Deg=None,
                      Exp=None, Diag=None, shot=None, version=None, usr=None,
                      include=None):
        
        Modstr = ID._dModes[Mod] if Mod is not None else None
        include = ID._defInclude if include is None else include
        if Cls is not None and Type is not None and 'Type' in include:
            Clsstr = Cls+Type
        else:
            Clsstr = Cls
        Dict = {'Mod':Modstr, 'Cls':Clsstr, 'Name':Name}
        for ii in include:
            if not ii in ['Mod','Cls','Type','Name']:
                Dict[ii] = None
            if ii=='Deg' and Deg is not None:
                Dict[ii] = ID._dPref[ii]+'{0:02.0f}'.format(Deg)
            elif ii=='shot' and shot is not None:
                Dict[ii] = ID._dPref[ii]+'{0:05.0f}'.format(shot)
            elif not (ii in ['Mod','Cls','Type','Name'] or eval(ii+' is None')):
                Dict[ii] = ID._dPref[ii]+eval(ii)
        if 'Data' in Cls:
            Order = ['Mod','Cls','Exp','Deg','Diag','shot',
                     'Name','version','usr']
        else:
            Order = ['Mod','Cls','Exp','Deg','Diag','Name',
                     'shot','version','usr']

        SVN = ""
        for ii in range(0,len(Order)):
            if Order[ii] in include and Dict[Order[ii]] is not None:
                SVN += '_' + Dict[Order[ii]]
        SVN = SVN.replace('__','_')
        if SVN[0]=='_':
            SVN = SVN[1:]
        return SVN
252861
def p_include_once_fname(p):
    
    p[0] = []

    if ENABLED:
        p[0] = include_once(p[3], p.lineno(3), local_first=False)
    else:
        p[0] = []

    if not p[0]:
        p.lexer.next_token = '_ENDFILE_'
885309
def _file_filter(cls, filename, include_patterns, exclude_patterns):
    """"""
    logger.debug('filename: {}'.format(filename))
    for exclude_pattern in exclude_patterns:
      if exclude_pattern.match(filename):
        return False
    if include_patterns:
      found = False
      for include_pattern in include_patterns:
        if include_pattern.match(filename):
          found = True
          break
      if not found:
        return False
    return True
1212373
function getAndWriteIncludedFile(file, includeDir) {
    return new Promise((resolve, reject) => {
        const fileName = file[0];
        const fileURL = file[1];

        const options = {
            url: fileURL,
            headers: {
                'User-Agent': 'request',
            },
        };

        request.get(options, (err, response, body) => {
            if (!err && response.statusCode === 200) {
                fs.writeFile(path.join(includeDir, fileName), body, (writeErr) => {
                    if (writeErr) {
                        resolve({
                            fileName,
                            successful: false,
                        });
                    } else {
                        resolve({
                            fileName,
                            successful: true,
                        });
                    }
                    return;
                });
            } else {
                resolve({
                    fileName,
                    successful: false,
                });
                return;
            }
        });
    });
}
873305
def save(self, filename):
        """"""
        filename = pathlib.Path(filename)
        out = []
        keys = sorted(list(self.keys()))
        for key in keys:
            out.append("[{}]".format(key))
            section = self[key]
            ikeys = list(section.keys())
            ikeys.sort()
            for ikey in ikeys:
                var, val = keyval_typ2str(ikey, section[ikey])
                out.append("{} = {}".format(var, val))
            out.append("")

        with filename.open("w") as f:
            for i in range(len(out)):
                # win-like line endings
                out[i] = out[i]+"\n"
            f.writelines(out)
875026
def include(self):
        
        if len(self.pending) == 0 or not self.pending[0].startswith('include '):
            return
        name = self.pending.pop(0)[8:].strip()[1:-1]
        for b in [os.path.dirname(self.name)] + self.inc_dirs:
            pname = os.path.abspath(os.path.expanduser(os.path.join(b, name)))
            if os.path.isfile(pname):
                name = pname
                break
        else:
            raise Exception('Can not find include file "{}".'.format(name))
        self.pending = list(FortranReader(name, self.docmark, self.predocmark, 
                                          self.docmark_alt, self.predocmark_alt,
                                          self.fixed, self.length_limit,
                                          inc_dirs=self.inc_dirs)) + self.pending
782365
def p_include(p):
    
    if ENABLED:
        p[0] = include_file(p[2], p.lineno(2), local_first=True)
    else:
        p[0] = []
        p.lexer.next_token = '_ENDFILE_'
5429
def p_include_fname(p):
    
    if ENABLED:
        p[0] = include_file(p[2], p.lineno(2), local_first=False)
    else:
        p[0] = []
        p.lexer.next_token = '_ENDFILE_'
300745
def expand_include(filename):
        
        open_files = set()

        def _expand_include_rec(filename):
            if filename in open_files:
                raise RuntimeError('Recursive include statement detected for '
                                   'file: ' + filename)
            else:
                open_files.add(filename)

            with open(filename) as open_file:
                for line in open_file:
                    line_stripped = line.strip().replace("//", "#")
                    if line_stripped.startswith('@include '):
                        inc_to_clean = line_stripped.split(None, 1)[1]
                        inc_filename = inc_to_clean.replace('"'," ").strip()
                        for included_line in _expand_include_rec(inc_filename):
                            yield included_line
                    else:
                        yield line

            open_files.remove(filename)

        try:
            lines = []
            for line in _expand_include_rec(filename):
                lines.append(line)
            return ''.join(lines)
        except RuntimeError:
            return None
536128
function includeRawDataFile(includedFiles, files, entryFilename, data) {
  let orderedFiles = includedFiles;

  if(entryFilename === RAW_DATA_FILE && data) {
    files[RAW_DATA_FILE] = data;
    orderedFiles = [...orderedFiles, RAW_DATA_FILE];
  } else if(orderedFiles.length > 0) {
    orderedFiles = [...orderedFiles.slice(1), orderedFiles[0]];
  }

  return {
    compiledFiles: files,
    orderedFiles,
  };
}
716155
def insert(self, filename):
        
        errors = []
        if os.path.isfile(filename):
            log.info('loading IOC from: {}'.format(filename))
            if not self.parse(filename):
                log.warning('Failed to prase [{}]'.format(filename))
                errors.append(filename)
        elif os.path.isdir(filename):
            log.info('loading IOCs from: {}'.format(filename))
            for fn in glob.glob(filename + os.path.sep + '*.ioc'):
                if not os.path.isfile(fn):
                    continue
                else:
                    if not self.parse(fn):
                        log.warning('Failed to parse [{}]'.format(filename))
                        errors.append(fn)
        else:
            pass
        log.info('Parsed [%s] IOCs' % str(len(self)))
        return errors
1243383
def save fname, options={}
      File.open(fname,"wb"){ |f| f << export(options) }
    end
286093
def save(self, filename):
        
        clibrebound.reb_output_binary(byref(self), c_char_p(filename.encode("ascii")))
900415
function resolveInclude(name, filename) {
  var path = join(dirname(filename), name);
  var ext = extname(name);
  if (!ext) path += '.ejs';
  return path;
}
1187944
def saveFile(self, filename):
        
        ret = libxml2mod.xmlSaveFile(filename, self._o)
        return ret