sqlalchemy_imageattach.file
— File proxies¶The file-like types which wraps/proxies an other file objects.
sqlalchemy_imageattach.file.
FileProxy
(wrapped)¶The complete proxy for wrapped
file-like object.
Parameters: | wrapped (file , file-like object) – the file object to wrap |
---|
close
()¶Closes the file. It’s a context manager as well,
so prefer with
statement than direct call of
this:
with FileProxy(file_) as f:
print f.read()
read
(size=-1)¶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 |
readline
(size=None)¶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 |
Note
Unlike stdio
‘s fgets()
, the returned string
contains null characters ('\0'
) if they occurred in
the input.
readlines
(sizehint=None)¶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 ] |
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.
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.
Parameters: |
|
---|
tell
()¶Gets the file’s current position.
Returns: | the file’s current position |
---|---|
Return type: | numbers.Integral |