sqlalchemy_imageattach.store
— Image storage backend interface¶This module declares a common interface for physically agnostic storage backends. Whatever a way to implement a storage, it needs only common operations of the interface. This consists of some basic operations like writing, reading, deletion, and finding urls.
Modules that implement the storage interface inside
sqlalchemy_imageattach.storages
package might help to implement
a new storage backend.
sqlalchemy_imageattach.store.
Store
¶The interface of image storage backends. Every image storage backend implementation has to implement this.
delete
(image)¶Delete the file of the given image
.
Parameters: | image (sqlalchemy_imageattach.entity.Image ) – the image to delete |
---|
delete_file
(object_type, object_id, width, height, mimetype)¶Deletes all reproducible files related to the image. It doesn’t raise any exception even if there’s no such file.
Parameters: |
|
---|
get_file
(object_type, object_id, width, height, mimetype)¶Gets the file-like object of the given criteria.
Parameters: |
|
---|---|
Returns: | the file of the image |
Return type: | file-like object, |
Raises: | exceptions.IOError – when such file doesn’t exist |
Note
This is an abstract method which has to be implemented (overridden) by subclasses.
It’s not for consumers but implementations, so consumers
should use open()
method instead of this.
get_url
(object_type, object_id, width, height, mimetype)¶Gets the file-like object of the given criteria.
Parameters: |
|
---|---|
Returns: | the url locating the image |
Return type: |
|
Note
This is an abstract method which has to be implemented (overridden) by subclasses.
It’s not for consumers but implementations, so consumers
should use locate()
method instead of this.
locate
(image)¶Gets the URL of the given image
.
Parameters: | image (sqlalchemy_imageattach.entity.Image ) – the image to get its url |
---|---|
Returns: | the url of the image |
Return type: | basestring |
open
(image, use_seek=False)¶Opens the file-like object of the given image
.
Returned file-like object guarantees:
collections.Iterable
protocolcollections.Iterator
protocolread()
methodreadline()
methodreadlines()
methodTo sum up: you definitely can read the file, in with
statement and for
loop.
Plus, if use_seek
option is True
:
For example, if you want to make a local copy of the image:
import shutil
with store.open(image) as src:
with open(filename, 'wb') as dst:
shutil.copyfileobj(src, dst)
Parameters: |
|
---|---|
Returns: | the file-like object of the image, which is a context
manager (plus, also seekable only if |
Return type: |
|
Raises: | exceptions.IOError – when such file doesn’t exist |
put_file
(file, object_type, object_id, width, height, mimetype, reproducible)¶Puts the file
of the image.
Parameters: |
|
---|
Note
This is an abstract method which has to be implemented (overridden) by subclasses.
It’s not for consumers but implementations, so consumers
should use store()
method instead of this.
store
(image, file)¶Stores the actual data file
of the given image
.
with open(imagefile, 'rb') as f:
store.store(image, f)
Parameters: |
|
---|