Get, parse and prepare input file.
978977
def prepare_input(argv=None):
    
    p = ArgumentParser(description='InsiliChem Ommprotocol: '
                       'easy to deploy MD protocols for OpenMM')
    p.add_argument('input', metavar='INPUT FILE', type=extant_file,
                   help='YAML input file')
    p.add_argument('--version', action='version', version='%(prog)s v{}'.format(__version__))
    p.add_argument('-c', '--check', action='store_true',
                   help='Validate input file only')
    args = p.parse_args(argv if argv else sys.argv[1:])

    jinja_env = jinja2.Environment(trim_blocks=True, lstrip_blocks=True)
    # Load config file
    with open(args.input) as f:
        rendered = jinja_env.from_string(f.read()).render()
        cfg = yaml.load(rendered, Loader=YamlLoader)
    # Paths and dirs
    from .md import SYSTEM_OPTIONS
    cfg['_path'] = os.path.abspath(args.input)
    cfg['system_options'] = prepare_system_options(cfg, defaults=SYSTEM_OPTIONS)
    cfg['outputpath'] = sanitize_path_for_file(cfg.get('outputpath', '.'), args.input)

    if not args.check:
        with ignored_exceptions(OSError):
            os.makedirs(cfg['outputpath'])

    handler = prepare_handler(cfg)

    return handler, cfg, args
1144536
def get_input(problem):
    "
    input_data = load_input()
    pbsplit = problem.split(":")
    problem_input = input_data['input'][pbsplit[0]]
    if isinstance(problem_input, dict) and "filename" in problem_input and "value" in problem_input:
        if len(pbsplit) > 1 and pbsplit[1] == 'filename':
            return problem_input["filename"]
        else:
            return open(problem_input["value"], 'rb').read()
    else:
        return problem_input
307247
def parse(input_: Union[str, FileStream], default_base: Optional[str]=None) -> Optional[Schema]:
    

    # Step 1: Tokenize the input stream
    error_listener = ParseErrorListener()
    if not isinstance(input_, FileStream):
        input_ = InputStream(input_)
    lexer = ShExDocLexer(input_)
    lexer.addErrorListener(error_listener)
    tokens = CommonTokenStream(lexer)
    tokens.fill()
    if error_listener.n_errors:         # Lexer prints errors directly
        return None

    # Step 2: Generate the parse tree
    parser = ShExDocParser(tokens)
    parser.addErrorListener(error_listener)
    parse_tree = parser.shExDoc()
    if error_listener.n_errors:
        print('\n'.join(error_listener.errors), file=sys.stderr)
        return None

    # Step 3: Transform the results the results
    parser = ShexDocParser(default_base=default_base)
    parser.visit(parse_tree)

    return parser.context.schema
265416
function preprocessInputText(inputText, currentDirectory) {
  var processDirectory = process.cwd(),
      importedFilePaths = [];

  // If the file name is an absolute path, returns it normailzed. If it is
  // a relative path starting with "./" or "../", appends it to the path
  // of the parent file, which the specified file is being expanded to.
  // Otherwise the relative path is  appended to the current directory.
  function completeFilePath(fileName, currentDirectory) {
    var directory;
    if (!path.isAbsolute(fileName)) {
      fileName = fileName.replace(/\\/g, '/');
      if (fileName.indexOf('./') === 0 ||
          fileName.indexOf('../') === 0) {
        directory = currentDirectory;
      } else {
        directory = processDirectory;
      }
      fileName = path.join(directory, fileName);
    }
    return path.resolve(path.normalize(fileName));
  }

  function expandFileImports(inputText, currentDirectory) {
    return inputText.replace(/#import: *(.*)/g, function (all, fileName) {
      fileName = completeFilePath(fileName, currentDirectory);
      if (importedFilePaths.indexOf(fileName) >= 0) {
        return '';
      }
      importedFilePaths.push(fileName);
      return expandFileImports(
          fs.readFileSync(fileName, {encoding: 'utf8'}),
          path.dirname(fileName));
    });
  }

  return expandFileImports(inputText, currentDirectory || processDirectory);
}
1029384
protected function prepareInput()
    {
        $arguments = [
            '--optimize' => (bool) $this->file->get(self::SETTING_OPTIMIZE),
            '--no-dev'   => true,
        ];

        $input = new ArrayInput($arguments);
        $input->setInteractive(false);

        return $input;
    }
1052045
def from_file(cls, path, encoding, dialect, fields, converters, field_index):
        """"""

        return cls(open(path, 'r', encoding=encoding), dialect, fields, converters, field_index)
1277789
def parse_file(self, filename=None, buffer=None, fileobj=None):
        """"""
        if filename:
            self.file = GzipFile(filename, 'rb')
        elif buffer:
            if hasattr(buffer, 'name'):
                self.filename = buffer.name
            self.file = buffer
        elif fileobj:
            if hasattr(fileobj, 'name'):
                self.filename = fileobj.name
            self.file = GzipFile(fileobj=fileobj)
        if self.file:
            try:
                type = TAG_Byte(buffer=self.file)
                if type.value == self.id:
                    name = TAG_String(buffer=self.file).value
                    self._parse_buffer(self.file)
                    self.name = name
                    self.file.close()
                else:
                    raise MalformedFileError(
                        "First record is not a Compound Tag")
            except StructError as e:
                raise MalformedFileError(
                    "Partial File Parse: file possibly truncated.")
        else:
            raise ValueError(
                "NBTFile.parse_file(): Need to specify either a "
                "filename or a file object"
            )
154992
def parse_files(self, req, name, field):
        """"""
        return get_value(req.files, name, field)
694981
def _text_or_file(input_):
    '''
    
    '''
    if _isfile(input_):
        with salt.utils.files.fopen(input_) as fp_:
            out = salt.utils.stringutils.to_str(fp_.read())
    else:
        out = salt.utils.stringutils.to_str(input_)

    return out
560437
def parse_input_file(text, variables=None):
    
    text = find_includes(text)
    lines = text.splitlines()
    tasks, linenumbers = find_tasks(lines)
    preamble = [line for line in lines[:linenumbers[0]]]
    logging.debug("Preamble:\n{}".format("\n".join(preamble)))
    if variables is not None:
        preamble += "\n" + "\n".join(variables)
    environment = create_environment(preamble)
    code_sections = []
    for n in range(len(linenumbers) - 1):
        code_sections.append((linenumbers[n], linenumbers[n+1]))
    for n, task in zip(code_sections, tasks):
        task["code"] = lines[n[0]: n[1]]
        task["environment"] = environment
    clean_tasks = []
    for task in tasks:
        clean_tasks.append(Task(**task))
    return clean_tasks
329408
def load(self, f, line=None):
        """"""
        if line is None:
            # in case the file contains only a fragment of an input file,
            # this is useful.
            line = f.readlin()
        words = line[1:].split()
        self.__name = words[0].upper()
        self.section_parameters = " ".join(words[1:])
        try:
            self.load_children(f)
        except EOFError:
            raise FileFormatError("Unexpected end of file, section '%s' not ended." % self.__name)
1144238
def read_examples(input_file):
    """"""
    examples = []
    unique_id = 0
    with open(input_file, "r", encoding='utf-8') as reader:
        while True:
            line = reader.readline()
            if not line:
                break
            line = line.strip()
            text_a = None
            text_b = None
            m = re.match(r"^(.*) \|\|\| (.*)$", line)
            if m is None:
                text_a = line
            else:
                text_a = m.group(1)
                text_b = m.group(2)
            examples.append(
                InputExample(unique_id=unique_id, text_a=text_a, text_b=text_b))
            unique_id += 1
    return examples
26811
def process_inputs(self):
        
        ret = []
        files = self.args.files
        if files is None:
            return ret

        for fname in files:

            # arguments are host specs
            if self.args.hosts:
                sub = self.process_host(fname, fname, 0)
                if sub is not None:
                    ret.append(sub)
                continue

            # arguments are file names
            fh = open(fname, 'r')
            with fh:
                data = fh.read()
                sub = self.process_tls(data, fname)
                ret.append(sub)

        return ret
409138
def train_input_fn(params):
  """"""
  file_pattern = os.path.join(getattr(params, "data_dir", ""), "*encoded-train*")
  return _read_and_batch_from_files(
      file_pattern, params.batch_size, params.max_length, params.num_cpu_cores,
      shuffle=True, repeat=params.repeat_dataset)
539336
def call(cmd, input_file=None, input_text=None, encoding=None):
    """"""

    process = get_process(cmd)

    if input_file is not None:
        with open(input_file, 'rb') as f:
            process.stdin.write(f.read())
    if input_text is not None:
        process.stdin.write(input_text)

    return get_process_output(process, encoding)
916508
protected void parse() {
        // have we already parsed the input?
        if (_parsed)
            return;
        _parsed = true;

        try {
            // initialize
            _parts = new MultiMap<>();

            // if its not a multipart request, don't parse it
            if (_contentType == null || !_contentType.startsWith("multipart/form-data"))
                return;

            // sort out the location to which to write the files
            if (_config.getLocation() == null)
                _tmpDir = _contextTmpDir;
            else if ("".equals(_config.getLocation()))
                _tmpDir = _contextTmpDir;
            else {
                File f = new File(_config.getLocation());
                if (f.isAbsolute())
                    _tmpDir = f;
                else
                    _tmpDir = new File(_contextTmpDir, _config.getLocation());
            }

            if (!_tmpDir.exists())
                _tmpDir.mkdirs();

            String contentTypeBoundary = "";
            int bstart = _contentType.indexOf("boundary=");
            if (bstart >= 0) {
                int bend = _contentType.indexOf(";", bstart);
                bend = (bend < 0 ? _contentType.length() : bend);
                contentTypeBoundary = QuotedStringTokenizer.unquote(value(_contentType.substring(bstart, bend)).trim());
            }

            Handler handler = new Handler();
            MultiPartParser parser = new MultiPartParser(handler, contentTypeBoundary);

            byte[] data = new byte[_bufferSize];
            int len;
            long total = 0;

            while (true) {

                len = _in.read(data);

                if (len > 0) {
                    // keep running total of size of bytes read from input and throw an exception if exceeds MultipartConfigElement._maxRequestSize
                    total += len;
                    if (_config.getMaxRequestSize() > 0 && total > _config.getMaxRequestSize()) {
                        _err = new IllegalStateException("Request exceeds maxRequestSize (" + _config.getMaxRequestSize() + ")");
                        return;
                    }

                    ByteBuffer buffer = BufferUtils.toBuffer(data);
                    buffer.limit(len);
                    if (parser.parse(buffer, false))
                        break;

                    if (buffer.hasRemaining())
                        throw new IllegalStateException("Buffer did not fully consume");

                } else if (len == -1) {
                    parser.parse(BufferUtils.EMPTY_BUFFER, true);
                    break;
                }

            }

            // check for exceptions
            if (_err != null) {
                return;
            }

            // check we read to the end of the message
            if (parser.getState() != MultiPartParser.State.END) {
                if (parser.getState() == MultiPartParser.State.PREAMBLE)
                    _err = new IOException("Missing initial multi part boundary");
                else
                    _err = new IOException("Incomplete Multipart");
            }

            if (LOG.isDebugEnabled()) {
                LOG.debug("Parsing Complete {} err={}", parser, _err);
            }

        } catch (Throwable e) {
            _err = e;
        }
    }
637743
def _parse(self, source, name, filename):
        """"""
        return Parser(self, source, name, _encode_filename(filename)).parse()