Skip to main content

FileProxyMixin

A mixin class used to forward file methods to an underlying file object. The internal file object has to be called "file"::

class FileProxy(FileProxyMixin):
def __init__(self, file):
self.file = file

Attributes

AttributeTypeDescription
encodingstringThe character encoding used to decode the underlying file's content.
filenointegerThe integer file descriptor used by the underlying file object to request I/O operations from the operating system.
flushcallableThe method used to flush the write buffers of the underlying file object.
isattybooleanA boolean indicating whether the underlying file object is connected to a terminal device.
newlinesstring or tupleA string, tuple of strings, or None indicating the newline conventions encountered in the underlying file.
readcallableThe method used to read a specified number of bytes or characters from the underlying file.
readintocallableThe method used to read bytes from the underlying file into a pre-allocated, writable bytes-like object.
readlinecallableThe method used to read a single line from the underlying file.
readlinescallableThe method used to read all remaining lines from the underlying file and return them as a list.
seekcallableThe method used to change the stream position within the underlying file.
tellcallableThe method used to return the current stream position of the underlying file.
truncatecallableThe method used to resize the underlying file to a specified number of bytes.
writecallableThe method used to write a string or bytes to the underlying file.
writelinescallableThe method used to write a list of lines to the underlying file.
closedbooleanA boolean indicating whether the underlying file object has been closed or is unavailable.

Methods


closed()

@classmethod
def closed() - > boolean

Checks whether the underlying file object is closed or if the file reference is null.

Returns

TypeDescription
booleanTrue if the file is closed or missing, False otherwise

readable()

@classmethod
def readable() - > boolean

Determines if the underlying file supports reading operations.

Returns

TypeDescription
booleanTrue if the file can be read from, False if it is closed or lacks read support

writable()

@classmethod
def writable() - > boolean

Determines if the underlying file supports writing operations by checking the file's native method or its mode string.

Returns

TypeDescription
booleanTrue if the file is open and supports writing, False otherwise

seekable()

@classmethod
def seekable() - > boolean

Determines if the underlying file supports random access via seek operations.

Returns

TypeDescription
booleanTrue if the file is open and supports seeking, False otherwise