summaryrefslogtreecommitdiff
path: root/src/mailman/model/requests.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-08-17 22:27:32 -0400
committerBarry Warsaw2012-08-17 22:27:32 -0400
commit82d2ef15e3810abf984dc70c800dac3ebca02f03 (patch)
tree72d5de1d008184cd2291a62804fc0ff8af25e190 /src/mailman/model/requests.py
parent247609a779b8194c90fa8f65cb0503923b835458 (diff)
downloadmailman-82d2ef15e3810abf984dc70c800dac3ebca02f03.tar.gz
mailman-82d2ef15e3810abf984dc70c800dac3ebca02f03.tar.zst
mailman-82d2ef15e3810abf984dc70c800dac3ebca02f03.zip
Diffstat (limited to 'src/mailman/model/requests.py')
-rw-r--r--src/mailman/model/requests.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/mailman/model/requests.py b/src/mailman/model/requests.py
index a92332e4a..5eb940233 100644
--- a/src/mailman/model/requests.py
+++ b/src/mailman/model/requests.py
@@ -24,6 +24,7 @@ __all__ = [
]
+from cPickle import dumps, loads
from datetime import timedelta
from storm.locals import AutoReload, Int, RawStr, Reference, Unicode
from zope.component import getUtility
@@ -39,7 +40,19 @@ from mailman.interfaces.requests import IListRequests, RequestType
@implementer(IPendable)
class DataPendable(dict):
- pass
+ def update(self, mapping):
+ # Keys and values must be strings (unicodes, but bytes values are
+ # accepted for now). Any other types for keys are a programming
+ # error. If we find a non-Unicode value, pickle it and encode it in
+ # such a way that it will be properly reconstituted when unpended.
+ clean_mapping = {}
+ for key, value in mapping.items():
+ assert isinstance(key, basestring)
+ if not isinstance(value, unicode):
+ key = '_pck_' + key
+ value = dumps(value).decode('raw-unicode-escape')
+ clean_mapping[key] = value
+ super(DataPendable, self).update(clean_mapping)
@@ -82,10 +95,6 @@ class ListRequests:
if data is None:
data_hash = None
else:
- # We're abusing the pending database as a way of storing arbitrary
- # key/value pairs, where both are strings. This isn't ideal but
- # it lets us get auxiliary data almost for free. We may need to
- # lock this down more later.
pendable = DataPendable()
pendable.update(data)
token = getUtility(IPendings).add(pendable, timedelta(days=5000))
@@ -106,7 +115,12 @@ class ListRequests:
pendable = getUtility(IPendings).confirm(
result.data_hash, expunge=False)
data = dict()
- data.update(pendable)
+ # Unpickle any non-Unicode values.
+ for key, value in pendable.items():
+ if key.startswith('_pck_'):
+ data[key[5:]] = loads(value.encode('raw-unicode-escape'))
+ else:
+ data[key] = value
return result.key, data
@dbconnection