summaryrefslogtreecommitdiff
path: root/src/mailman/rest/docs/helpers.rst
diff options
context:
space:
mode:
authorBarry Warsaw2014-11-02 15:29:10 -0500
committerBarry Warsaw2014-11-02 15:29:10 -0500
commit9b19d1a9d77e71afc0783f22496bd623eda3024b (patch)
tree0f6942efb5f23ca54695769ee240119ad5a75ceb /src/mailman/rest/docs/helpers.rst
parentdfc451f81ccc8b0947fb3fa42e94c55026984cf8 (diff)
downloadmailman-9b19d1a9d77e71afc0783f22496bd623eda3024b.tar.gz
mailman-9b19d1a9d77e71afc0783f22496bd623eda3024b.tar.zst
mailman-9b19d1a9d77e71afc0783f22496bd623eda3024b.zip
Diffstat (limited to 'src/mailman/rest/docs/helpers.rst')
-rw-r--r--src/mailman/rest/docs/helpers.rst30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/mailman/rest/docs/helpers.rst b/src/mailman/rest/docs/helpers.rst
index 1a2a244ac..68dfda1be 100644
--- a/src/mailman/rest/docs/helpers.rst
+++ b/src/mailman/rest/docs/helpers.rst
@@ -73,7 +73,7 @@ converting their values.
>>> validator = Validator(one=int, two=unicode, three=bool)
>>> class FakeRequest:
- ... params = {}
+ ... params = None
>>> FakeRequest.params = dict(one='1', two='two', three='yes')
On valid input, the validator can be used as a ``**keyword`` argument.
@@ -157,12 +157,17 @@ such form data. Specifically, when a key shows up multiple times in the form
data, a list is given to the validator.
::
- # Of course we can't use a normal dictionary, but webob has a useful data
- # type we can use.
- >>> from webob.multidict import MultiDict
- >>> form_data = MultiDict(one='1', many='3')
- >>> form_data.add('many', '4')
- >>> form_data.add('many', '5')
+ # We can't use a normal dictionary because we'll have multiple keys, but
+ # the validator only wants to call .items() on the object.
+ >>> class MultiDict:
+ ... def __init__(self, *params): self.values = list(params)
+ ... def items(self): return iter(self.values)
+ >>> form_data = MultiDict(
+ ... ('one', '1'),
+ ... ('many', '3'),
+ ... ('many', '4'),
+ ... ('many', '5'),
+ ... )
This is a validation function that ensures the value is a list.
@@ -191,11 +196,12 @@ And a validator to pull it all together.
The list values are guaranteed to be in the same order they show up in the
form data.
- >>> from webob.multidict import MultiDict
- >>> form_data = MultiDict(one='1', many='3')
- >>> form_data.add('many', '5')
- >>> form_data.add('many', '4')
- >>> FakeRequest.params = form_data
+ >>> FakeRequest.params = MultiDict(
+ ... ('one', '1'),
+ ... ('many', '3'),
+ ... ('many', '5'),
+ ... ('many', '4'),
+ ... )
>>> values = validator(FakeRequest)
>>> print(values['one'])
1