From bf1204e9c920588adf649033d5db02bb7d75d640 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 20 Jul 2009 23:13:59 -0400 Subject: Our first writable REST API! You can now create new domains through the webserver. Fix the https/http urls. Add the adapter for HTTPCharsets so POSTs work properly. Nice little cargo cult from lazr.restful. --- src/mailman/tests/test_documentation.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/mailman/tests/test_documentation.py') diff --git a/src/mailman/tests/test_documentation.py b/src/mailman/tests/test_documentation.py index 0409e737c..81762c5cc 100644 --- a/src/mailman/tests/test_documentation.py +++ b/src/mailman/tests/test_documentation.py @@ -37,6 +37,7 @@ import doctest import unittest from email import message_from_string +from urllib import urlencode from urllib2 import urlopen import mailman @@ -109,16 +110,28 @@ def dump_msgdata(msgdata, *additional_skips): print '{0:{2}}: {1}'.format(key, msgdata[key], longest) -def dump_json(url): +def dump_json(url, data=None): """Print the JSON dictionary read from a URL. :param url: The url to open, read, and print. :type url: string + :param data: Data to use to POST to a URL. + :type data: dict """ - fp = urlopen(url) + if data is None: + fp = urlopen(url) + else: + fp = urlopen(url, urlencode(data)) # fp does not support the context manager protocol. try: - data = json.load(fp) + raw_data = fp.read() + if len(raw_data) == 0: + print 'URL:', fp.geturl() + info = fp.info() + for header in sorted(info): + print '{0}: {1}'.format(header, info[header]) + return + data = json.loads(raw_data) finally: fp.close() for key in sorted(data): -- cgit v1.2.3-70-g09d2