Merge lp:~jameinel/maas/maasclient-multipart into lp:maas/trunk
| Status: | Merged |
|---|---|
| Approved by: | John A Meinel on 2012-10-05 |
| Approved revision: | 1168 |
| Merged at revision: | 1180 |
| Proposed branch: | lp:~jameinel/maas/maasclient-multipart |
| Merge into: | lp:maas/trunk |
| Diff against target: |
71 lines (+26/-8) 2 files modified
src/apiclient/multipart.py (+15/-8) src/apiclient/tests/test_multipart.py (+11/-0) |
| To merge this branch: | bzr merge lp:~jameinel/maas/maasclient-multipart |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Gavin Panella (community) | 2012-10-05 | Approve on 2012-10-05 | |
|
Review via email:
|
|||
Commit Message
Support MAASClient.
The multipart code already supported passing the same variable multiple times, but you can't expose that from a **kwargs style function.
Description of the Change
For the Tag updates, we need to pass a list to the API. It turns out that MAASClient didn't actually support it via the .get()/.post() methods.
The fix is pretty straightforward, and the tests assert that Django properly understands the results.
The other way to do this is to have the get/post methods themselves translate a "x=[list]" argument into a series of [(x, item1), (x, item2), (x, item3)...], which is already supported by the multipart code. But this made the most sense to me.
| John A Meinel (jameinel) wrote : | # |
| Jeroen T. Vermeulen (jtv) wrote : | # |
Checking for a list seems dangerously fragile: what of tuples, result sets, generators..? Is there no better way to distinguish this special case?
| John A Meinel (jameinel) wrote : | # |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 10/5/2012 12:25 PM, Jeroen T. Vermeulen wrote:
> Checking for a list seems dangerously fragile: what of tuples,
> result sets, generators..? Is there no better way to distinguish
> this special case?
>
Well, list is all I needed. :)
You can do:
try:
iter(foo)
except TypeError
but then you still need to check for string and unicode first, because
both of them are also iterable,and you don't want to send stuff one
character at a time.
isinstance(obj, (list, tuple, set, ...)) is also a possibility, though
I would probably stick with "if someone needs X, they can add support
for X".
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (Cygwin)
Comment: Using GnuPG with Mozilla - http://
iEYEARECAAYFAlB
jeUAoKwoHGu7sB5
=tS+u
-----END PGP SIGNATURE-----
| Gavin Panella (allenap) wrote : | # |
Remember your abc :)
from collections import Mapping
if isinstance(thing, Mapping):
# Treat it like a dict.
...
else:
# Assume it's an iterable of (name, value) tuples.
...
Also, maascli.
urllib.urlencode. It probably ought to move to apiclient.utils. Or the
standard library ;)
- 1168. By John A Meinel on 2012-10-05
-
Switch to make_payloads, since that is a bit cleaner about instance checks.


Note that this doesn't fix the 'MAASClient.get()' case. Where urlencode happily takes a list, str(lst) it, and then encodes the string formatted version.
But at least we can send a list easily via POST.