Open file intelligently depending on the source and python version.

    Args:
        filepath (:obj:`str`): Path to the file.

    Yields:
        Context manager for file handle.
508739
def smart_open(filepath):
    
    if filepath[-2:] == "gz":
        mode = "rt"
        fopen = gzip.open
    else:
        mode = "r"
        fopen = open
    if sys.version_info[0] < 3:
        fh = fopen(filepath, mode)
    else:
        fh = fopen(filepath, mode, errors="ignore")
    try:
        yield fh
    except IOError:
        fh.close()
    finally:
        fh.close()
27412
public static function openFile(/*string*/ $filePath, /*string*/ $mode) {
    return self::isFile($filePath) ? fopen($filePath, $mode, false) : false;
  }
486820
def _process_file(self, path):
        
        try:
            f = open(path)
            for line in f:
                self._process_line(line)

            os.remove(path)
        except IOError as ex:
            self.log.error("Could not open file `{path}': {error}".format(
                path=path, error=ex.strerror))
1069646
def OpenFile(self, windows_path):
    
    path_spec = self._path_resolver.ResolvePath(windows_path)
    if path_spec is None:
      return None

    return self._file_system.GetFileObjectByPathSpec(path_spec)
541954
def _OpenFileObject(self, path_spec):
    
    if not path_spec.HasParent():
      raise errors.PathSpecError(
          'Unsupported path specification without parent.')

    file_object = resolver.Resolver.OpenFileObject(
        path_spec.parent, resolver_context=self._resolver_context)
    qcow_file = pyqcow.file()
    qcow_file.open_file_object(file_object)
    return qcow_file
695639
def file(self, name, *args, **kwargs):
        
        return open(self(name), *args, **kwargs)
164317
def open_asset_path(self, *args, **kwargs):
        
        f = self.asset_path_le.text()
        d = os.path.dirname(f)
        osinter = get_interface()
        osinter.open_path(d)
967942
def open_file(name, mode=None, driver=None, libver=None, userblock_size=None, **kwargs):
    
    import sys
    import os
    from h5py import h5p
    from h5py._hl import files

    try:
        # If the byte string doesn't match the default
        # encoding, just pass it on as-is.  Note Unicode
        # objects can always be encoded.
        name = name.encode(sys.getfilesystemencoding())
    except (UnicodeError, LookupError):
        pass
    exists = os.path.exists(name)
    try:
        fcpl = h5p.create(h5p.FILE_CREATE)
        fcpl.set_link_creation_order(
            h5p.CRT_ORDER_TRACKED | h5p.CRT_ORDER_INDEXED)
    except AttributeError:
        # older version of h5py
        fp = files.File(name, mode=mode, driver=driver,
                        libver=libver, **kwargs)
    else:
        fapl = files.make_fapl(driver, libver, **kwargs)
        fp = files.File(files.make_fid(name, mode, userblock_size, fapl, fcpl))

    if not exists and fp.mode == 'r+':
        set_attributes(fp,
                       arf_library='python',
                       arf_library_version=__version__,
                       arf_version=spec_version)
    return fp
1229604
def copy_file(self, filepath):
        
        copy_file = False
        try:
            copy_file = self.data[filepath]['copy']
        except KeyError:
            return False
        return copy_file
1251560
def setFilepath( self, filepath ):
        
        self._filepath = nativestring(filepath)
        self.setIcon(QIcon(filepath))
        if ( not self.signalsBlocked() ):
            self.filepathChanged.emit(filepath)
48889
def _open(self, file_path=None):
		
		if file_path is None:
			file_path = self.file_path

		if not os.path.exists(file_path):
			raise ValueError('Could not find file: {}'.format(file_path))

		try:
			f = open(file_path, encoding='utf-8', newline='')
		except OSError as err:
			self.log.error(str(err))
			raise ValueError('Could not open file: {}'.format(file_path))

		return f
524457
def _open_file_obj(f, mode="r"):
    
    if isinstance(f, six.string_types):
        if f.startswith(("http://", "https://")):
            file_obj = _urlopen(f)
            yield file_obj
            file_obj.close()
        else:
            with open(f, mode) as file_obj:
                yield file_obj
    else:
        yield f
1047531
def maybe_gzip_open(path, *args, **kwargs):
    
    path = path_to_str(path)
    if path.endswith('.gz') or path.endswith('.gzip'):
        _open = gzip.open
    else:
        _open = open
    return _open(path, *args, **kwargs)
997472
def file_w_create_directories(filepath):
    
    dirname = os.path.dirname(filepath)

    if dirname and dirname != os.path.curdir and not os.path.isdir(dirname):
        os.makedirs(dirname)

    return open(filepath, 'w')
183428
def open(self, external_dir=None):
        
        if self.kind == 'data':
            with io.BytesIO(self._data.data) as f:
                yield f
        elif self.kind == 'external':
            filepath = self._data.linked_file[b'fullPath'].value
            filepath = filepath.replace('\x00', '').replace('file://', '')
            if not os.path.exists(filepath):
                filepath = self._data.linked_file[b'relPath'].value
                filepath = filepath.replace('\x00', '')
                if external_dir is not None:
                    filepath = os.path.join(external_dir, filepath)
            if not os.path.exists(filepath):
                raise FileNotFoundError(filepath)
            with open(filepath, 'rb') as f:
                yield f
        else:
            raise NotImplementedError('alias is not supported.')
758910
def open(self, path, mode='r', *args, **kwargs):
        """"""
        return open(os.path.join(os.path.dirname(self.path), path),
                    mode=mode, *args, **kwargs)
1164737
def load(cls, filepath):
        
        with open(filepath, "rb") as filehandler:
            classifier = pickle.load(filehandler)

        if not isinstance(classifier, Classifier):
            raise ValueError("Pickled object is not a Classifier")

        return classifier