72 def get_data(host, query, idx, limit, debug):
73 """Contact DAS server and retrieve data for given DAS query"""
74 params = {
'input':query,
'idx':idx,
'limit':limit}
76 pat = re.compile(
'http[s]{0,1}://')
77 if not pat.match(host):
78 msg =
'Invalid hostname: %s' % host
81 headers = {
"Accept":
"application/json"}
82 encoded_data = urllib.urlencode(params, doseq=
True)
83 url +=
'?%s' % encoded_data
84 req = urllib2.Request(url=url, headers=headers)
86 hdlr = urllib2.HTTPHandler(debuglevel=1)
87 opener = urllib2.build_opener(hdlr)
89 opener = urllib2.build_opener()
90 fdesc = opener.open(req)
94 pat = re.compile(
r'^[a-z0-9]{32}')
95 if data
and isinstance(data, str)
and pat.match(data)
and len(data) == 32:
102 params.update({
'pid':data})
103 encoded_data = urllib.urlencode(params, doseq=
True)
104 url = host + path +
'?%s' % encoded_data
105 req = urllib2.Request(url=url, headers=headers)
107 fdesc = opener.open(req)
110 except urllib2.HTTPError
as err:
113 if data
and isinstance(data, str)
and pat.match(data)
and len(data) == 32: