def parse(self, data, macaddress): doc = simplexmlapi.loads(data) try: result = doc.latitude._, doc.longitude._ except: result = doc.error._ return macaddress, result
def restRequest(url,values,type=None,jXML=False,jXMLIter=None,jXMLNon=None,path=None,port=443,**kwargs): """ REST request handler. URL - (GET) Entire URL (POST) Base URL, example: http://www.google.com Values - Query or form varialbes Type - Either GET or POST Path - (POST Only) Folder and file, example: /webservice/test.html """ encodedValues = urllib.urlencode(values) if type == None: req = urllib2.Request(url,encodedValues) data = urllib2.urlopen(req).read() if jXML == False: return simplexmlapi.loads(data) if jXML == True and isinstance(jXMLIter, list): if isinstance(jXMLNon, list): jin = jinwrightXML(data,iter_tags=jXMLIter,non_tags=jXMLNon) return jin.all() else: jin = jinwrightXML(data,iter_tags=jXMLIter) return jin.iterableTags() else: if path != None: headers = {} if hasattr(kwargs, 'headers'): headers = kwargs['headers'] conn = httplib.HTTPConnection(url) conn.request(type, path, encodedValues, headers) response = conn.getresponse() data = response.read() conn.close() return data else: raise RestExcept("Path not defined.")
def post_multipart(self, host, selector, fields, files, start, end, length): """ Post fields and files to an http host as multipart/form-data. fields is a sequence of (name, value) elements for regular form fields. files is a sequence of (name, filename, value) elements for data to be uploaded as files Return the server response. """ content_type, body = self.encode_multipart_formdata(fields, files, start, end, length) h = httplib.HTTPConnection(host) headers = { 'Content-Length': str(len(body)), 'User-Agent': 'Nirvanix Python SDK', 'Content-Type': content_type } h.request('POST', selector, body, headers) res = h.getresponse() if debug: print "Err Code: " + str(res.status) print "Err Msg: " + str(res.reason) return simplexmlapi.loads(res.read())
def load_xml(self,content): nd = simplexmlapi.loads(content) return nd