ape.parts.storage.socketstorage.SocketStorage

class ape.parts.storage.socketstorage.SocketStorage(file_object)

A class to store data to a file

SocketStorage constructor

Param:
  • file_object: opened file-like socket-based object
__init__(file_object)

SocketStorage constructor

Param:
  • file_object: opened file-like socket-based object

Methods

__init__(file_object) SocketStorage constructor
close() Closes self.file if it exists, sets self.closed to True
log_error(error[, message]) Logs the error in bold red
open(name) Opens a file for writing
read() reads all the output and returns as a single string
readline() Calls a single read-line returns ‘timed out’ if socket.timeout
write(text) write text to a file
writeline(text) Adds newline to end of text and writes it to the file
writelines(texts) write lines to a file (does not add newline character to end of lines)

Attributes

file
return:opened file-like object
logger
return:A logging object.
close()

Closes self.file if it exists, sets self.closed to True

log_error(error, message='')

Logs the error in bold red

Param:
  • error: error type (prefix in red and bold)
  • message: descriptive message (red but not bold)
open(name)

Opens a file for writing

Param:
  • name: a basename (no path) for the file
Returns:

copy of self with file as open file and closed set to False

read()

reads all the output and returns as a single string

Raise:ApeError if socket times-out
readline()

Calls a single read-line returns ‘timed out’ if socket.timeout

readlines()

reads all the output and returns a list of lines

Raise:ApeError if the socket times out
write(text)

write text to a file

Param:
  • text: text to write to the file
Raise:

ApeError on socket.error

writeline(text)

Adds newline to end of text and writes it to the file

writelines(texts)

write lines to a file (does not add newline character to end of lines)

Param:
  • texts: iterable collection of strings to write to the file
Raise:

ApeError on socket.error (socket closed)

file
Returns:opened file-like object
logger
Returns:A logging object.

Navigation