Ejemplo n.º 1
0
def drain_pipe(stream: io.FileIO, buffer: typing.BinaryIO) -> Optional[int]:
    chunk = stream.readall()
    if chunk is not None:
        buffer.write(chunk)
        return len(chunk)
    else:
        return None
Ejemplo n.º 2
0
 def read_config(self):
     """Attempt to read config file and set config data.
     If no config file exists, return False. 
     """
     try:
         config_file = FileIO(self.container + REPO_FILE, "rb")
         file_data = json.loads(config_file.readall())
         self.data = file_data
         return True
     except FileNotFoundError:
         # No config file found: new repository
         return False
Ejemplo n.º 3
0
    def get_zipdata(self):
        cache_file_name = self.cache_filename
        stream = FileIO(cache_file_name, mode='w')
        zipfile = ZipFile(stream, 'w')
        self.write_zipfile(zipfile)
        zipfile.close()
        stream.close()

        stream = FileIO(cache_file_name, mode='r')
        zipdata = stream.readall()
        stream.close()
        remove(cache_file_name)
        return zipdata
Ejemplo n.º 4
0
class FileDataReader(AbstractDataReader):
    """ A reader that can read data from a file
    """

    def __init__(self, filename):
        """
        :param filename: The file to read
        :type filename: str
        :raise spinnman.exceptions.SpinnmanIOException: If the file\
                    cannot found or opened for reading
        """
        try:
            self._fileio = FileIO(filename, "r")
        except IOError as e:
            raise SpinnmanIOException(str(e))

    def read(self, n_bytes):
        """ See :py:meth:`spinnman.data.abstract_data_reader.AbstractDataReader.read`
        """
        return bytearray(self._fileio.read(n_bytes))

    def readinto(self, data):
        """ See :py:meth:`spinnman.data.abstract_data_reader.AbstractDataReader.readinto`
        """
        return self._fileio.readinto(data)

    def readall(self):
        """ See :py:meth:`spinnman.data.abstract_data_reader.AbstractDataReader.readall`
        """
        return self._fileio.readall()

    def close(self):
        """ Closes the file

        :return: Nothing is returned:
        :rtype: None
        :raise spinnman.exceptions.SpinnmanIOException: If the file\
                    cannot be closed
        """
        try:
            self._fileio.close()
        except IOError as e:
            raise SpinnmanIOException(str(e))
Ejemplo n.º 5
0
 def load_from_file(filename):
     f = FileIO(filename, 'rb')
     data = f.readall()
     return ByteArray(data)
Ejemplo n.º 6
0
"""

import sys
import io
from io import FileIO

inputFileName = sys.argv[1]
outputFileName = sys.argv[2]
nInLine = 10
if len(sys.argv) >= 4:
    nInLine = int(sys.argv[4])

inputStream = FileIO(inputFileName, 'r')
outputFile = open(outputFileName, 'w')

inputData = inputStream.readall()
inputStream.close()

outputStr = ''

n = 0
for x in inputData:
    outputStr += str(ord(x)).rjust(3) + ", "
    n += 1
    if n >= nInLine:
        outputStr += '\n'
        n = 0

outputFile.write(outputStr)
outputFile.close()
Ejemplo n.º 7
0
"""

import sys
import io
from io import FileIO

inputFileName = sys.argv[1]
outputFileName = sys.argv[2]
nInLine = 10
if len(sys.argv) >= 4:
    nInLine = int(sys.argv[4])

inputStream = FileIO(inputFileName, "r")
outputFile = open(outputFileName, "w")

inputData = inputStream.readall()
inputStream.close()

outputStr = ""

n = 0
for x in inputData:
    outputStr += str(ord(x)).rjust(3) + ", "
    n += 1
    if n >= nInLine:
        outputStr += "\n"
        n = 0

outputFile.write(outputStr)
outputFile.close()