forked from Pylons/deform
/
interfaces.py
65 lines (52 loc) · 2.17 KB
/
interfaces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class FileUploadTempStore(object):
"""
The :class:`deform.FileUploadWidget` requires as its first
argument a ``tmpstore``. Such a tmpstore will implement this
interface: an object implementing the FileUploadTempStore
interface should implement the methods attached to this
description.
Effectively, this interface is a subset of the ``dict`` interface
plus an additional method named ``preview_url``. In fact, the
simplest possible implementation of this interface is:
.. code-block:: python
class MemoryTmpStore(dict):
def preview_url(self, name):
return None
However, the :class:`deform.FileUploadWidget` does not remove data
from the tempstore implementation it uses (it doesn't have enough
information to be able to do so), and it is job of the tempstore
implementation itself to expire items which haven't been accessed
in a while.
Therefore, the above ``MemoryTmpStore`` implementation is
generally unsuitable for production, as the data put into it is
not automatically evicted over time and file upload data provided
by untrusted users is usually unsuitable for storage in RAM. It's
more likely that an implementation in your application will center
around a sessioning library (such as Beaker) that does data
eviction and which stores file upload data in persistent storage.
"""
def __setitem__(self, name, value):
"""
Set a value.
"""
def __getitem__(self, name):
"""
Get a value.
"""
def get(self, name, default=None):
"""
Same as dict.get.
"""
def __contains__(self, name):
"""
This should return `True` if we have a value for the
name supplied, `False` otherwise.
"""
def preview_url(self, name):
"""
Return the preview URL for the item previously placed into the
tmpstore named ``name`` or ``None`` if there is no preview for
``name`` available (or if this tmpstore does not support
previewable items). This item should typically return a URL
to a thumbnail image.
"""