Read data from the specified file.
    :param filename_or_file_object: filename of the file or an opened :class:`file` buffer to that file
    :type filename_or_file_object: basestring|file
    :return:
436535
def from_file(filename_or_file_object):
    
    if isinstance(filename_or_file_object, basestring):
        file_ = open(filename_or_file_object, 'r')
        we_opened = True
    else:
        we_opened = False
        file_ = filename_or_file_object

    try:
        data = load(file_.read())
    finally:
        if we_opened:
            file_.close()

    return data
769205
def _read_name_file(self, filename):
        
        file_path = os.path.join(self._DATA_DIR, filename)
        with open(file_path) as f:
            names = json.load(f)

        return names
579350
def _readfile(cls, filename):
        
        f = codecs.open(filename, encoding='utf-8')
        filedata = f.read()
        f.close()
        tokenz = LM.tokenize(filedata, mode='c')
        #print tokenz
        return tokenz
1070947
def read_file_or_stdin(filename = nil)
      filename.nil? ? !STDIN.tty? && STDIN.read : File.read(filename)
    end
836654
def scan_file(self, this_file, this_filename):
        
        params = {
            'api_key': self.api_key,
            'filename': this_filename
        }
        try:
            files = {'file': (this_file.name, open(this_file.name, 'rb'), 'application/octet-stream')}
        except TypeError as e:
            return dict(error=e.message)

        try:
            response = requests.post(self.base + 'file/upload', files=files, data=params)
        except requests.RequestException as e:
            return dict(error=e.message)

        return _return_response_and_status_code(response)
501661
def _read_file(self, file):  # type: (str) -> Optional[str]
        
        if not self.setup_file_name:
            return None
        source = None
        if os.path.isfile(file):
            with self.file_opener.open_this(file, "r") as setup_py:
                source = setup_py.read()
        return source
1217498
def parse_file(self, filename):
        

        with open(filename, "rb", _BUFFERING) as stream:
            self.parse(stream.read())
989671
def read_file(filename, content_type = nil)
      data = File.binread(filename)

      if detect = mime_type_charset_detecter(content_type)
        detect.call(data).encode(Encoding::UTF_8, universal_newline: true)
      else
        data
      end
    end
1131448
def read_file_to_buffer(filename):
    
    f = open(filename, "r")
    buf = BytesIO(f.read())
    f.close()
    return buf
1019693
def write(self, file_or_filename):
        
        if isinstance(file_or_filename, basestring):
            file = None
            try:
                file = open(file_or_filename, "wb")
            except Exception, detail:
                logger.error("Error opening %s." % detail)
            finally:
                if file is not None:
                    self._write_data(file)
                    file.close()
        else:
            file = file_or_filename
            self._write_data(file)

        return file
247123
def open_image(fname_or_instance: Union[str, IO[bytes]]):
    
    if isinstance(fname_or_instance, Image.Image):
        return fname_or_instance

    return Image.open(fname_or_instance)
988775
def _parse_file(self, file_obj):
        
        byte_data = file_obj.read(self.size)
        self._parse_byte_data(byte_data)
969836
def read(self, file_or_filename):
        
        t0 = time.time()
        self.init()
        if isinstance(file_or_filename, basestring):
            fname = os.path.basename(file_or_filename)
            logger.info("Loading PSS/E Raw file [%s]." % fname)

            file = None
            try:
                file = open(file_or_filename, "rb")
            except:
                logger.error("Error opening %s." % fname)
                return None
            finally:
                if file is not None:
                    case = self._parse_file(file)
                    file.close()
        else:
            file = file_or_filename
            case = self._parse_file(file)

        logger.info("PSS/E Raw file parsed in %.2fs." % (time.time() - t0))

        return case
529977
public static Object readObject(String fileName, boolean isInternalFile) throws DISIException {
        Object result;
        try {
            InputStream fos = null;

            if (isInternalFile == true) {
                fos = Thread.currentThread().getContextClassLoader().getResource(fileName).openStream();
            } else {
                fos = new FileInputStream(fileName);
            }

            BufferedInputStream bis = new BufferedInputStream(fos);
            ObjectInputStream oos = new ObjectInputStream(bis);
            try {
                result = oos.readObject();
            } catch (IOException e) {
                final String errMessage = e.getClass().getSimpleName() + ": " + e.getMessage();
                log.error(errMessage, e);
                throw new DISIException(errMessage, e);
            } catch (ClassNotFoundException e) {
                final String errMessage = e.getClass().getSimpleName() + ": " + e.getMessage();
                log.error(errMessage, e);
                throw new DISIException(errMessage, e);
            }
            oos.close();
            bis.close();
            fos.close();
        } catch (IOException e) {
            final String errMessage = e.getClass().getSimpleName() + ": " + e.getMessage();
            log.error(errMessage, e);
            throw new DISIException(errMessage, e);
        }
        return result;
    }
956520
def _read_from_file(self):
        
        # test if we can read the given file
        if not gf.file_can_be_read(self.file_path):
            self.log_exc(u"File '%s' cannot be read" % (self.file_path), None, True, OSError)

        if self.file_format not in TextFileFormat.ALLOWED_VALUES:
            self.log_exc(u"Text file format '%s' is not supported." % (self.file_format), None, True, ValueError)

        # read the contents of the file
        self.log([u"Reading contents of file '%s'", self.file_path])
        with io.open(self.file_path, "r", encoding="utf-8") as text_file:
            lines = text_file.readlines()

        # clear text fragments
        self.clear()

        # parse the contents
        map_read_function = {
            TextFileFormat.MPLAIN: self._read_mplain,
            TextFileFormat.MUNPARSED: self._read_munparsed,
            TextFileFormat.PARSED: self._read_parsed,
            TextFileFormat.PLAIN: self._read_plain,
            TextFileFormat.SUBTITLES: self._read_subtitles,
            TextFileFormat.UNPARSED: self._read_unparsed
        }
        map_read_function[self.file_format](lines)

        # log the number of fragments
        self.log([u"Parsed %d fragments", len(self.fragments)])
365305
def read_file(self):
        
        file_obj = open(self.file, 'r')
        content = file_obj.read()
        file_obj.close()
        if content:
            content = json.loads(content)
            return content
        else:
            return {}
1138165
def parse_file(file_or_path, encoding='utf-8', validate=False):
    
    try:
        is_string = isinstance(file_or_path, basestring)
    except NameError:
        is_string = isinstance(file_or_path, str)
    if is_string:
        with codecs.open(file_or_path, 'r', encoding) as file_:
            result = pattern.parseFile(file_)[0]
    else:
        result = pattern.parseFile(file_or_path)[0]
    if validate:
        result.validate()
    return result