Fork me on GitHub

sqlalchemy_imageattach.file — File proxies

The file-like types which wraps/proxies an other file objects.

class sqlalchemy_imageattach.file.FileProxy(wrapped)

The complete proxy for wrapped file-like object.

Parameters:wrapped (file, file-like object) – the file object to wrap

Closes the file. It’s a context manager as well, so prefer with statement than direct call of this:

with FileProxy(file_) as f:

Implementation of Iterator protocol.


Reads at the most size bytes from the file. It maybe less if the read hits EOF before obtaining size bytes.

Parameters:size – bytes to read. if it is negative or omitted, read all data until EOF is reached. default is -1
Returns:read bytes. an empty string when EOF is encountered immediately
Return type:str

Reads an entire line from the file. A trailing newline character is kept in the string (but maybe absent when a file ends with an incomplete line).

Parameters:size (numbers.Integral) – if it’s present and non-negative, it is maximum byte count (including trailing newline) and an incomplete line maybe returned
Returns:read bytes
Return type:str


Unlike stdio‘s fgets(), the returned string contains null characters ('\0') if they occurred in the input.


Reads until EOF using readline().

Parameters:sizehint (numbers.Integral) – if it’s present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (or more to accommodate a final whole line)
Returns:a list containing the lines read
Return type:List[bytes]

The same to iter(file). Use that.

Deprecated since version long: time ago

Use iter() instead.

class sqlalchemy_imageattach.file.ReusableFileProxy(wrapped)

It memorizes the current position (tell()) when the context enters and then rewinds (seek()) back to the memorized initial_offset when the context exits.

class sqlalchemy_imageattach.file.SeekableFileProxy(wrapped)

The almost same to FileProxy except it has seek() and tell() methods in addition.

seek(offset, whence=0)

Sets the file’s current position.

  • offset (numbers.Integral) – the offset to set
  • whence – see the docs of default is os.SEEK_SET

Gets the file’s current position.

Returns:the file’s current position
Return type:numbers.Integral