Create a DocFile for a file that will be opened for reading.
167396
public static DocFile createFileForInput(Configuration configuration, String file) {
        return DocFileFactory.getFactory(configuration).createFileForInput(file);
    }
783685
def _read_file(name, encoding='utf-8') -> str:
    
    with open(name, encoding=encoding) as f:
        return f.read()
657962
def read_file(self, file_name, section=None):
        """"""
        file_name, section = self.parse_file_name_and_section(file_name, section)
        if not os.path.isfile(file_name):
            raise SettingsFileNotFoundError(file_name)
        parser = self.make_parser()
        with open(file_name) as fp:
            parser.read_file(fp)

        settings = OrderedDict()

        if parser.has_section(section):
            section_dict = parser[section]
            self.section_found_while_reading = True
        else:
            section_dict = parser.defaults().copy()

        extends = section_dict.get('extends')

        if extends:
            extends = self.decode_value(extends)
            extends, extends_section = self.parse_file_name_and_section(
                extends, extender=file_name, extender_section=section)
            settings.update(self.read_file(extends, extends_section))

        settings.update(section_dict)

        if not self.section_found_while_reading:
            raise SettingsFileSectionNotFoundError(section)

        return settings
140512
def load(self, file, name=None):
        """"""
        if name is None:
            name = self.format_from_extension(op.splitext(file)[1])
        file_format = self.file_type(name)
        if file_format == 'text':
            return _read_text(file)
        elif file_format == 'json':
            return _read_json(file)
        else:
            load_function = self._formats[name].get('load', None)
            if load_function is None:
                raise IOError("The format must declare a file type or "
                              "load/save functions.")
            return load_function(file)
603370
def read_file(file, filename='<input>'):
    """"""
    reader = Reader(filename)
    for line in file:
        yield from reader.feed_line(line)
    reader.finish()
1307772
def open_file(self) :
        """"""
        if self.isdir() : raise Exception("FSQuery tried to open a directory as a file : %s" % self.abs)
        return open(self.abs)
1007403
def makefile(self, sock, mode='r', bufsize=DEFAULT_BUFFER_SIZE):
        """"""
        cls = StreamReader if 'r' in mode else StreamWriter
        return cls(sock, mode, bufsize)
1006679
def read_file(filename):
    """"""
    path = os.path.abspath(os.path.dirname(__file__))
    filepath = os.path.join(path, filename)
    try:
        return open(filepath).read()
    except IOError:
        return ''
307691
def _open(self, path, skip_to_end = True, offset = None):
      """"""
      fh = os.fdopen(os.open(path, os.O_RDONLY | os.O_NONBLOCK))

      # If the file is being opened for the first time, jump to the end.
      # Otherwise, it is being reopened after a rotation, and we want
      # content from the beginning.
      if offset is None:
         if skip_to_end:
            fh.seek(0, 2)

            self._offset = fh.tell()
         else:
            self._offset = 0
      else:
         fh.seek(offset)
         self._offset = fh.tell()
      
      self._fh = fh
      self._lastsize = fh.tell()
      self._inode = os.stat(self._path).st_ino
321124
def readme(fname):
    """"""
    md = open(os.path.join(os.path.dirname(__file__), fname)).read()
    output = md
    try:
        import pypandoc
        output = pypandoc.convert(md, 'rst', format='md')
    except ImportError:
        pass
    return output
30388
def open(self, filehandle):
        """"""
        with self.lock:
            if filehandle in self.files:
                self.files[filehandle] += 1
            elif filehandle.closed:
                filehandle.open()
                self.files[filehandle] = 1
                self.past.append(filehandle)
902714
def docs(self, fileids=None) -> Generator[str, str, None]:
        
        if not fileids:
            fileids = self.fileids()
        # Create a generator, loading one document into memory at a time.
        for path, encoding in self.abspaths(fileids, include_encoding=True):
            with codecs.open(path, 'r', encoding=encoding) as reader:
                if self.skip_keywords:
                    tmp_data = []
                    for line in reader:
                        skip = False
                        for keyword in self.skip_keywords:
                            if keyword in line:
                                skip = True
                        if not skip:
                            tmp_data.append(line)
                    yield ''.join(tmp_data)
                else:
                    yield reader.read()
551434
def from_file(cls, file):
        """"""
        opf_xml = etree.parse(file)
        # Check if ``file`` is file-like.
        if hasattr(file, 'read'):
            name = os.path.basename(file.name)
            root = os.path.abspath(os.path.dirname(file.name))
        else:  # ...a filepath
            name = os.path.basename(file)
            root = os.path.abspath(os.path.dirname(file))
        parser = OPFParser(opf_xml)

        # Roll through the item entries
        manifest = opf_xml.xpath('/opf:package/opf:manifest/opf:item',
                                 namespaces=EPUB_OPF_NAMESPACES)
        pkg_items = []
        for item in manifest:
            absolute_filepath = os.path.join(root, item.get('href'))
            properties = item.get('properties', '').split()
            is_navigation = 'nav' in properties
            media_type = item.get('media-type')
            pkg_items.append(Item.from_file(absolute_filepath,
                                            media_type=media_type,
                                            is_navigation=is_navigation,
                                            properties=properties))
        # Ignore spine ordering, because it is not important
        #   for our use cases.
        return cls(name, pkg_items, parser.metadata)
294240
def create_file(self, fileName, contents=""):
        
        with open(fileName, "w") as written_file:
            written_file.write(contents)
728647
function(file, cb) {
    zip.entry(fs.createReadStream(file.path), { name: file.name }, cb);
  }
746365
def _open(file_, mode='r'):
  """"""
  if isinstance(file_, string_types):
    _, ext = path.splitext(file_)
    if ext in {'.bz2', '.gz'}:
      s = tarfile.open(file_)
      return s.extractfile(s.next())
    else:
      return open(file_, mode)
  return file_
1009494
def opened(filename, mode):
    ""
    if isinstance(filename, str):
        file = open(filename, mode)
        try: 
            yield file
        finally: 
            if not file.closed:
                file.close()
    else:
        yield filename