Decodes bencoded data of a given file.

        Returns decoded structure(s).

        :param str filepath:
        :rtype: list
510631
def read_file(cls, filepath):
        
        with open(filepath, mode='rb') as f:
            contents = f.read()
        return cls.decode(contents)
473082
def read(path):
    
    # This function implementation was chosen to be compatible across Python 2/3.
    f = open(path, 'rb')
    # We avoid use of the with keyword for Python 2.4 support.
    try:
        b = f.read()
    finally:
        f.close()

    return b.decode(FILE_ENCODING)
9931
def decode_headers(header_list):
	'''
	
	'''

	decoded_headers = []
	for header in header_list:
		if cchardet:
			inferred = cchardet.detect(header)
			if inferred and inferred['confidence'] > 0.8:
				# print("Parsing headers!", header)
				decoded_headers.append(header.decode(inferred['encoding']))
			else:
				decoded_headers.append(header.decode('iso-8859-1'))
		else:    # pragma: no cover
			# All bytes are < 127 (e.g. ASCII)
			if all([char & 0x80 == 0 for char in header]):
				decoded_headers.append(header.decode("us-ascii"))
			elif isUTF8Strict(header):
				decoded_headers.append(header.decode("utf-8"))
			else:
				decoded_headers.append(header.decode('iso-8859-1'))

	return decoded_headers
843964
def decode(self, check_trailer=False): # pylint: disable=I0011,R0912
        
        try:
            kind = self.data[self.offset]
        except IndexError:
            raise BencodeError("Unexpected end of data at offset %d/%d" % (
                self.offset, len(self.data),
            ))

        if kind.isdigit():
            # String
            try:
                end = self.data.find(':', self.offset)
                length = int(self.data[self.offset:end], 10)
            except (ValueError, TypeError):
                raise BencodeError("Bad string length at offset %d (%r...)" % (
                    self.offset, self.data[self.offset:self.offset+32]
                ))

            self.offset = end+length+1
            obj = self.data[end+1:self.offset]

            if self.char_encoding:
                try:
                    obj = obj.decode(self.char_encoding)
                except (UnicodeError, AttributeError):
                    # deliver non-decodable string (byte arrays) as-is
                    pass
        elif kind == 'i':
            # Integer
            try:
                end = self.data.find('e', self.offset+1)
                obj = int(self.data[self.offset+1:end], 10)
            except (ValueError, TypeError):
                raise BencodeError("Bad integer at offset %d (%r...)" % (
                    self.offset, self.data[self.offset:self.offset+32]
                ))
            self.offset = end+1
        elif kind == 'l':
            # List
            self.offset += 1
            obj = []
            while self.data[self.offset:self.offset+1] != 'e':
                obj.append(self.decode())
            self.offset += 1
        elif kind == 'd':
            # Dict
            self.offset += 1
            obj = {}
            while self.data[self.offset:self.offset+1] != 'e':
                key = self.decode()
                obj[key] = self.decode()
            self.offset += 1
        else:
            raise BencodeError("Format error at offset %d (%r...)" % (
                self.offset, self.data[self.offset:self.offset+32]
            ))

        if check_trailer and self.offset != len(self.data):
            raise BencodeError("Trailing data at offset %d (%r...)" % (
                self.offset, self.data[self.offset:self.offset+32]
            ))

        return obj
443335
def from_file(filepath: str):
        
        trace = TrainingTrace()
        trace._trace = load_config(filepath)
        return trace
544274
def pre_process_data(filepath):
    
    positive_path = os.path.join(filepath, 'pos')
    negative_path = os.path.join(filepath, 'neg')

    pos_label = 1
    neg_label = 0

    dataset = []

    for filename in glob.glob(os.path.join(positive_path, '*.txt')):
        with open(filename, 'r') as f:
            dataset.append((pos_label, f.read()))

    for filename in glob.glob(os.path.join(negative_path, '*.txt')):
        with open(filename, 'r') as f:
            dataset.append((neg_label, f.read()))

    shuffle(dataset)

    return dataset
148284
def read_file(self, filepath=None, filename=None):
        
        name = filename if filename else self.filename
        path = filepath if filepath else self.filepath
        name = self._ends_with(name, ".json")
        path = self._ends_with(path, os.path.sep)

        try:
            return self._read_json(path, name)
        except EnvironmentError as error:
            self.logger.error("Error while opening or reading the file: {}".format(error))
            raise
        except ValueError as error:
            self.logger.error("File contents cannot be decoded to JSON: {}".format(error))
            raise
767213
def fs_encode(path):
    

    path = _get_path(path)
    if path is None:
        raise TypeError("expected a valid path to encode")
    if isinstance(path, six.text_type):
        if six.PY2:
            return b"".join(
                (
                    _byte(ord(c) - 0xDC00)
                    if 0xDC00 <= ord(c) <= 0xDCFF
                    else c.encode(_fs_encoding, _fs_encode_errors)
                )
                for c in path
            )
        return path.encode(_fs_encoding, _fs_encode_errors)
    return path
1314130
def load_file_to_base64_str(f_path):
    
    path = abs_path(f_path)
    with io.open(path, 'rb') as f:
        f_bytes = f.read()
        base64_str = base64.b64encode(f_bytes).decode("utf-8")
        return base64_str
964228
def decode(self, data):
        
        return Zchunk(lib.zarmour_decode(self._as_parameter_, data), True)
1169315
def readlines(self, filepath):
        """"""
        target = self._read_check(filepath)

        if os.path.isfile(target):
            with open(target) as f:
                lines = f.readlines()

            #If we got this file via SSH, delete it from the temp folder
            if self.is_ssh(filepath):
                os.remove(target)
        else:
            lines = []

        return lines
1092776
def _read(filepath_or_buffer: FilePathOrBuffer, kwds):
    """"""
    encoding = kwds.get('encoding', None)
    if encoding is not None:
        encoding = re.sub('_', '-', encoding).lower()
        kwds['encoding'] = encoding

    compression = kwds.get('compression', 'infer')
    compression = _infer_compression(filepath_or_buffer, compression)

    # TODO: get_filepath_or_buffer could return
    # Union[FilePathOrBuffer, s3fs.S3File, gcsfs.GCSFile]
    # though mypy handling of conditional imports is difficult.
    # See https://github.com/python/mypy/issues/1297
    fp_or_buf, _, compression, should_close = get_filepath_or_buffer(
        filepath_or_buffer, encoding, compression)
    kwds['compression'] = compression

    if kwds.get('date_parser', None) is not None:
        if isinstance(kwds['parse_dates'], bool):
            kwds['parse_dates'] = True

    # Extract some of the arguments (pass chunksize on).
    iterator = kwds.get('iterator', False)
    chunksize = _validate_integer('chunksize', kwds.get('chunksize', None), 1)
    nrows = kwds.get('nrows', None)

    # Check for duplicates in names.
    _validate_names(kwds.get("names", None))

    # Create the parser.
    parser = TextFileReader(fp_or_buf, **kwds)

    if chunksize or iterator:
        return parser

    try:
        data = parser.read(nrows)
    finally:
        parser.close()

    if should_close:
        try:
            fp_or_buf.close()
        except ValueError:
            pass

    return data
794004
def recognize_file(self, file_path):
        
        file_path = _convert_to_charp(file_path)
        ptr = self._recognize_file_func(self.alpr_pointer, file_path)
        json_data = ctypes.cast(ptr, ctypes.c_char_p).value
        json_data = _convert_from_charp(json_data)
        response_obj = json.loads(json_data)
        self._free_json_mem_func(ctypes.c_void_p(ptr))
        return response_obj
544466
def read_file(cls, path):
        
        with open(path, encoding="utf-8") as file:
            file_contents = file.read()
            return cls.read(file_contents)
475143
public static byte[] readFileToBytes( String filePath ) throws IOException {
        Path path = Paths.get(filePath);
        byte[] bytes = Files.readAllBytes(path);
        return bytes;
    }
871803
def str_from_file(path):
    
    with open(path) as f:
        s = f.read().strip()
    return s
1237092
def decode_path(file_path):
    """"""
    if file_path is None:
        return
    if isinstance(file_path, six.binary_type):
        file_path = file_path.decode(sys.getfilesystemencoding())
    return file_path