From 2e263fabbc273e2c5131fc1c8f246251db124811 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Mon, 17 Dec 2012 17:20:11 -0500 Subject: [PATCH] add timeout flag to post_xml (#96) --- pycsw/admin.py | 4 ++-- sbin/pycsw-admin.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pycsw/admin.py b/pycsw/admin.py index 1cbdf11cc..ceb94eb2e 100644 --- a/pycsw/admin.py +++ b/pycsw/admin.py @@ -411,14 +411,14 @@ def gen_opensearch_description(context, mdata, url, output_file): encoding='UTF-8', xml_declaration=1)) -def post_xml(url, xml): +def post_xml(url, xml, timeout=30): """Execute HTTP XML POST request and print response""" LOGGER.info('Executing HTTP POST request %s on server %s', xml, url) from owslib.util import http_post try: - return http_post(url, open(xml).read()) + return http_post(url=url, request=open(xml).read(), timeout=timeout) except Exception, err: raise RuntimeError(err) diff --git a/sbin/pycsw-admin.py b/sbin/pycsw-admin.py index 51a169f52..d185e40eb 100755 --- a/sbin/pycsw-admin.py +++ b/sbin/pycsw-admin.py @@ -79,6 +79,8 @@ def usage(): -s XML Schema + -t Timeout (in seconds) for HTTP requests (default is 30) + -u URL of CSW -x XML document @@ -144,13 +146,14 @@ def usage(): CSW_URL = None XML = None XSD = None +TIMEOUT = 30 if len(sys.argv) == 1: print usage() sys.exit(1) try: - OPTS, ARGS = getopt.getopt(sys.argv[1:], 'c:f:ho:p:ru:x:s:') + OPTS, ARGS = getopt.getopt(sys.argv[1:], 'c:f:ho:p:ru:x:s:t:') except getopt.GetoptError, err: print '\nERROR: %s' % err print usage() @@ -173,6 +176,8 @@ def usage(): XML = a if o == '-s': XSD = a + if o == '-t': + TIMEOUT = int(a) if o == '-h': # dump help and exit print usage() sys.exit(3) @@ -247,7 +252,7 @@ def usage(): elif COMMAND == 'gen_opensearch_description': admin.gen_opensearch_description(CONTEXT, METADATA, URL, OUTPUT_FILE) elif COMMAND == 'post_xml': - print admin.post_xml(CSW_URL, XML) + print admin.post_xml(CSW_URL, XML, TIMEOUT) elif COMMAND == 'get_sysprof': print admin.get_sysprof() elif COMMAND == 'validate_xml':