I tried a simple sample but i have an error with import xml.sax, the error is "no module name xml.sax" i think its because i need pyexpat from pyxml but i don´t find it on the web.
Is there another way to do this sample whitout the module xml.sax?
my sample code:
Code:
import appuifw
import e32
import urllib
import xml.sax
import xml.sax.handler
class DeviceStateHandler(xml.sax.handler.ContentHandler):
def __init__(self, device):
self.device = device
def startElement(self, name, attributes):
if name == "devicestate":
self.device = DeviceState(attributes["battery_level"],attributes["localtime"], attributes["connection_type"])
class DeviceState:
def __init__(self, battery_level, localtime, connection_type):
self.battery_level = battery_level
self.localtime = localtime
self.connection_type = connection_type
def getAttributes(self):
return u'Battery Level: ' + self.battery_level + u'\nLocalTime: ' + self.localtime + u'\nConnection Type: ' + self.connection_type
def quit():
appuifw.app.set_exit()
appuifw.app.exit_key_handler = quit
def print(text):
appuifw.note(text, 'info')
def stateDevice():
url = "http://127.0.0.1/rest/presence/devicestate"
content = urllib.urlopen(url).read()
handler = DeviceStateHandler()
xml.sax.parseString(content, handler)
print(handler.device.getAttributes())
appuifw.app.menu = [(u'State', stateDevice)]
appuifw.app.title = u'Sample REST Services'
app_lock = e32.Ao_lock()
app_lock.wait()
Thanks for help!!