parameters: (host, query, idx, limit, debug, threshold=300, ckey=None,
          cert=None, capath=None, qcache=0, das_headers=True)
return_statement: return jsondict
docstring: Contact DAS server and retrieve data for given DAS query
docstring_summary: Contact DAS server and retrieve data for given DAS query
docstring_tokens: Contact DAS server and retrieve data for given DAS query
function: def get_data(host, query, idx, limit, debug, threshold=300, ckey=None,
          cert=None, capath=None, qcache=0, das_headers=True):
      """Contact DAS server and retrieve data for given DAS query"""
      params  = {'input':query, 'idx':idx, 'limit':limit}
      if  qcache:
          params['qcache'] = qcache
      path    = '/das/cache'
      pat     = re.compile('http[s]{0,1}://')
      if  not pat.match(host):
          msg = 'Invalid hostname: %s' % host
          raise Exception(msg)
      url = host + path
      client = '%s (%s)' % (DAS_CLIENT, os.environ.get('USER', ''))
      headers = {"Accept": "application/json", "User-Agent": client}
      encoded_data = urllib.urlencode(params, doseq=True)
      url += '?%s' % encoded_data
      req  = urllib2.Request(url=url, headers=headers)
      if  ckey and cert:
          ckey = fullpath(ckey)
          cert = fullpath(cert)
          http_hdlr  = HTTPSClientAuthHandler(ckey, cert, capath, debug)
      elif cert and capath:
          cert = fullpath(cert)
          http_hdlr  = HTTPSClientAuthHandler(ckey, cert, capath, debug)
      else:
          http_hdlr  = urllib2.HTTPHandler(debuglevel=debug)
      proxy_handler  = urllib2.ProxyHandler({})
      cookie_jar     = cookielib.CookieJar()
      cookie_handler = urllib2.HTTPCookieProcessor(cookie_jar)
      try:
          opener = urllib2.build_opener(http_hdlr, proxy_handler, cookie_handler)
          fdesc = opener.open(req)
          data = fdesc.read()
          fdesc.close()
      except urllib2.HTTPError as error:
  	print(error.read())
  	sys.exit(1)
  
      pat = re.compile(r'^[a-z0-9]{32}')
      if  data and isinstance(data, str) and pat.match(data) and len(data) == 32:
          pid = data
      else:
          pid = None
      iwtime  = 2  # initial waiting time in seconds
      wtime   = 20 # final waiting time in seconds
      sleep   = iwtime
      time0   = time.time()
      while pid:
          params.update({'pid':data})
          encoded_data = urllib.urlencode(params, doseq=True)
          url  = host + path + '?%s' % encoded_data
          req  = urllib2.Request(url=url, headers=headers)
          try:
              fdesc = opener.open(req)
              data = fdesc.read()
              fdesc.close()
          except urllib2.HTTPError as err:
              return {"status":"fail", "reason":str(err)}
          if  data and isinstance(data, str) and pat.match(data) and len(data) == 32:
              pid = data
          else:
              pid = None
          time.sleep(sleep)
          if  sleep < wtime:
              sleep *= 2
          elif sleep == wtime:
              sleep = iwtime # start new cycle
          else:
              sleep = wtime
          if  (time.time()-time0) > threshold:
              reason = "client timeout after %s sec" % int(time.time()-time0)
              return {"status":"fail", "reason":reason}
      jsondict = json.loads(data)
      return jsondict
function_tokens: def get_data ( host , query , idx , limit , debug , threshold = 300 , ckey = None , cert = None , capath = None , qcache = 0 , das_headers = True ) : params = { 'input' : query , 'idx' : idx , 'limit' : limit } if qcache : params [ 'qcache' ] = qcache path = '/das/cache' pat = re . compile ( 'http[s]{0,1}://' ) if not pat . match ( host ) : msg = 'Invalid hostname: %s' % host raise Exception ( msg ) url = host + path client = '%s (%s)' % ( DAS_CLIENT , os . environ . get ( 'USER' , '' ) ) headers = { "Accept" : "application/json" , "User-Agent" : client } encoded_data = urllib . urlencode ( params , doseq = True ) url += '?%s' % encoded_data req = urllib2 . Request ( url = url , headers = headers ) if ckey and cert : ckey = fullpath ( ckey ) cert = fullpath ( cert ) http_hdlr = HTTPSClientAuthHandler ( ckey , cert , capath , debug ) elif cert and capath : cert = fullpath ( cert ) http_hdlr = HTTPSClientAuthHandler ( ckey , cert , capath , debug ) else : http_hdlr = urllib2 . HTTPHandler ( debuglevel = debug ) proxy_handler = urllib2 . ProxyHandler ( { } ) cookie_jar = cookielib . CookieJar ( ) cookie_handler = urllib2 . HTTPCookieProcessor ( cookie_jar ) try : opener = urllib2 . build_opener ( http_hdlr , proxy_handler , cookie_handler ) fdesc = opener . open ( req ) data = fdesc . read ( ) fdesc . close ( ) except urllib2 . HTTPError as error : print ( error . read ( ) ) sys . exit ( 1 ) pat = re . compile ( r'^[a-z0-9]{32}' ) if data and isinstance ( data , str ) and pat . match ( data ) and len ( data ) == 32 : pid = data else : pid = None iwtime = 2 # initial waiting time in seconds wtime = 20 # final waiting time in seconds sleep = iwtime time0 = time . time ( ) while pid : params . update ( { 'pid' : data } ) encoded_data = urllib . urlencode ( params , doseq = True ) url = host + path + '?%s' % encoded_data req = urllib2 . Request ( url = url , headers = headers ) try : fdesc = opener . open ( req ) data = fdesc . read ( ) fdesc . close ( ) except urllib2 . HTTPError as err : return { "status" : "fail" , "reason" : str ( err ) } if data and isinstance ( data , str ) and pat . match ( data ) and len ( data ) == 32 : pid = data else : pid = None time . sleep ( sleep ) if sleep < wtime : sleep *= 2 elif sleep == wtime : sleep = iwtime # start new cycle else : sleep = wtime if ( time . time ( ) - time0 ) > threshold : reason = "client timeout after %s sec" % int ( time . time ( ) - time0 ) return { "status" : "fail" , "reason" : reason } jsondict = json . loads ( data ) return jsondict