Filepath Or Buffer

class dataprofiler.data_readers.filepath_or_buffer.FileOrBufferHandler(filepath_or_buffer, open_method='r', encoding=None, seek_offset=None, seek_whence=0)

Bases: object

FileOrBufferHandler class to read a filepath or buffer in and always return a readable buffer

Context manager class used for inputing a file or buffer and returning a structure that is always a buffer.

Parameters
  • filepath_or_buffer (Union[str, StringIO, BytesIO]) – path to the file being loaded or buffer

  • open_method (string) – value describes the mode the file is opened in

  • seek_offset (int) – offset from start of the stream

Returns

TextIOBase or BufferedIOBase class/subclass

class dataprofiler.data_readers.filepath_or_buffer.DetachingTextIOWrapper(buffer, encoding=None, errors=None, newline=None, line_buffering=False, write_through=False)

Bases: _io.TextIOWrapper

DetachingTextIOWrapper class is used to detach buffer to avoid buffer closing before it’s returned

close()

Flush and close the IO object.

This method has no effect if the file is already closed.

buffer
closed
detach()

Separate the underlying buffer from the TextIOBase and return it.

After the underlying buffer has been detached, the TextIO is in an unusable state.

encoding
errors
fileno()

Returns underlying file descriptor if one exists.

OSError is raised if the IO object does not use a file descriptor.

flush()

Flush write buffers, if applicable.

This is not implemented for read-only and non-blocking streams.

isatty()

Return whether this is an ‘interactive’ stream.

Return False if it can’t be determined.

line_buffering
name
newlines
read(size=- 1, /)

Read at most n characters from stream.

Read from underlying buffer until we have n characters or we hit EOF. If n is negative or omitted, read until EOF.

readable()

Return whether object was opened for reading.

If False, read() will raise OSError.

readline(size=- 1, /)

Read until newline or EOF.

Returns an empty string if EOF is hit immediately.

readlines(hint=- 1, /)

Return a list of lines from the stream.

hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.

reconfigure(*, encoding=None, errors=None, newline=None, line_buffering=None, write_through=None)

Reconfigure the text stream with new parameters.

This also does an implicit stream flush.

seek(cookie, whence=0, /)

Change stream position.

Change the stream position to the given byte offset. The offset is interpreted relative to the position indicated by whence. Values for whence are:

  • 0 – start of stream (the default); offset should be zero or positive

  • 1 – current stream position; offset may be negative

  • 2 – end of stream; offset is usually negative

Return the new absolute position.

seekable()

Return whether object supports random access.

If False, seek(), tell() and truncate() will raise OSError. This method may need to do a test seek().

tell()

Return current stream position.

truncate(pos=None, /)

Truncate file to size bytes.

File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.

writable()

Return whether object was opened for writing.

If False, write() will raise OSError.

write(text, /)

Write string to stream. Returns the number of characters written (which is always equal to the length of the string).

write_through
writelines(lines, /)

Write a list of lines to stream.

Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.