def __init__(self, params, baseUrl=None): baseUrl = baseUrl or self.default_baseUrl # print 'EcoServiceClient' # print ' - baseUrl: %s' % baseUrl SimpleClient.__init__(self, baseUrl) resp_json = self.getResponseJson(params) # print '\n resp KEYS' # for key in resp_json: # print '-', key # for key2 in resp_json[key]: # print ' -', key2 if resp_json.has_key('error'): raise Exception, resp_json['error'] if resp_json['data'].has_key('error'): raise Exception, 'DATA error: %s' % resp_json['data']['error'] if not params.has_key('data_type'): params['data_type'] = 'data' if params['data_type'] == 'data': self.data = resp_json['payload']['data'] self.relation = resp_json['payload']['relation'] elif params['data_type'] == 'all': self.data = resp_json['data']['payload']['data'] self.relation = resp_json['data']['payload']['relation'] self.vocab = resp_json['vocab']['payload'] self.roster = resp_json['roster']['payload'] if self.verbose: for attr in ['data', 'relation', 'vocab', 'roster']: print ' - %s: %d' % (attr, len(getattr(self, attr)))
def get_modules(url): client = SimpleClient (url) html = client.getData() m = h2Tag_pat.findall(html) modules = [] if 0 and m: print 'm is TRUE' print ' there are %d in m' % len(m) print 'the first element is a %s' % type (m[0]) if not m: return [] for s in m: m2 = attr_pat.match (s) if not m2: # print 'could not find name attribute in "%s"' % s continue m3 = a_pat.match(s) if not m3: # print 'could not match on a tag' continue modules.append(m3.group(1)) return modules
def getResponse(baseUrl, params, responseDoc_class=ResponseDoc): client = SimpleClient(baseUrl) xml = client.getData(params=params) lines = xml.split('\n') if lines[0].find('<?xml') > -1: lines = lines[1:] xml = '\n'.join(lines).strip() return responseDoc_class(xml)
def __init__(self): self.data = {} client = SimpleClient(self.baseUrl) client.verbose = 0 rec = client.getResponseDoc() for element in rec.selectNodes(rec.dom, 'asnJurisdictions:Jurisdiction'): j = Jurisdiction(element) self[j.organizationJurisdiction] = j
def getResponseDoc(params): postData = {} client = SimpleClient(baseUrl) # data = client.getData(params=params) # print data responseDoc = client.getResponseDoc(params) #here of course we could validate return responseDoc
def timedRequest (params, opts=None): clicks = time.time() client = SimpleClient(baseUrl) resp = client.getData(params, opts) print '%d bytes transfered' % len(resp) print 'responseCode: ', client.responseCode if len(resp) > 300: print resp[:300] + ' ....' else: print resp print 'time elapsed: %f seconds' % (time.time() - clicks)
def verify (self): valid = False try: client = SimpleClient(self.url) client.getData() responseCode = client.responseCode # print 'responseCode: ', client.responseCode if responseCode == 200: valid = True except Exception, msg: # print msg pass # valid remains False
def __init__(self, params): self.data = {} client = SimpleClient(self.baseUrl) client.verbose = 0 rec = client.getResponseDoc(params=params) # print rec docNodes = rec.selectNodes(rec.dom, 'asnDocuments:Document') # print "%d docs found" % len(docNodes) for element in docNodes: doc = Document(element) # if not doc.asnPurl: # # raise KeyError, "asnPurl not found \n%s" % element.toxml() # print "asnPurl not found" # continue self[doc.asnUri] = doc
def getResponseDoc(self, params=None, opts=None): XmlRecord.xpath_delimiter = '/' doc = SimpleClient.getResponseDoc(self, params, opts) error = doc.selectSingleNode(doc.dom, "HandleResolutionService/error") if error: raise HRSError, '%s: %s' % (error.getAttribute('code'), XmlUtils.getText(error)) return doc
def getResponseDoc (self, params=None, opts=None): doc = SimpleClient.getResponseDoc(self, params, opts) error = doc.selectSingleNode(doc.dom,'DDSRepositoryUpdateService:error') if error: raise SimpleClientError, 'ERROR %s' % XmlUtils.getText(error) # print ' - updated %s' % params['id'] # id = doc.getTextAtPath('DDSRepositoryUpdateService:PutRecord:recordInfo:recordId') # print ' - updated', id return doc
def __init__(self): SimpleClient.__init__(self, self.baseUrl)
def __init__(self): baseUrl = "http://localhost:8080/asn/service.do" SimpleClient.__init__(self, baseUrl)