示例#1
0
    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)))
示例#2
0
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)
示例#4
0
    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
示例#5
0
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
示例#6
0
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)
示例#7
0
	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
示例#8
0
 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
示例#9
0
 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
示例#10
0
	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
示例#11
0
 def __init__(self):
     SimpleClient.__init__(self, self.baseUrl)
示例#12
0
 def __init__(self):
     baseUrl = "http://localhost:8080/asn/service.do"
     SimpleClient.__init__(self, baseUrl)