Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Archived:How to access Symbian resources in WRT or Flash Lite, using PySymbian

From Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Article Metadata
Code ExampleArticle
Created: ivocalado (08 Sep 2009)
Last edited: hamishwillee (31 May 2013)
Featured Article
30 Aug



New programming languages for mobile application development, such Flash Lite and WRT, can't access device native resources such as GPS, Accelerometer, etc. This problem happens because they usually run in a sandbox. An approach that fixes this problem is the development of an access layer which must be between device and mobile application (Flash Lite or WRT). This access layer can be developed in any programming language that has native access to the device.

The figure below shows how this layer works.

Server Python layers.png


We propose the development of a mobile web server written in Python language which the main goal is to allow the retrieval of available native services in a Web Service REST-based approach. The web server was developed in an extensible manner that allows an easy addition of new services, decoupling the parameters handling of the service implementation. Due to that, it's possible to write a service with just the business logic itself.

Figure 2 depicts our architecture solution. There are three main entities associated with the architecture: client, HTTP server and the services.

  • Client: the application written in whatever technology, such as WRT or FlashLite, which requires internal resources. This application is completely independent from ServerPython, because this use only HTTP request to communicate with it.
  • HTTP Server: Manages all requests from Clients and invokes the right service.
  • Services: A set of services implemented by the developer. This is the hotspot of the ServerPython framework.


Figure 2. Architecture of the Mobile Web Server

Figure 3 shows the class diagram of the ServerPython. The Services class is the hotspot of the framework. The developer has to create methods and call the addCallBack method of the MyServer class added in the instance of Services.


Figure 3. Class diagram

The Source-Code

In this section, we present some of the main features of our solution.

The code below presents the HTTPServer class which handles the HTTP requests.

class HTTPServer:
def __init__(self, host, port):
"""This class is responsible for parsing the HTTP request and calling the correct method""" = host;
self.port = port;
def doGet(self, request, response):
"""This method is called when a GET request is sent to the web server. It MUST be overwritten in subclasses and it's called through template method design pattern"""
def doPost(self, request, response):
"""This method is called when a POST request is sent to the web server. It MUST be overwritten in subclasses and it's called through the template method design pattern"""
def __handlerAttributes(self, rawAttributes):
"""This method is called to handler the attributes of the HTTP request"""
for i in rawAttributes:
return map
def __handlerRequest(self, connection, rawRequest):
"""This method is called to handler the request. It splits the tokens, call the '__handlerAttributes' method and finaly call the correct request, i.e. GET or POST method"""
self._rawRequest = rawRequest
attributes = self.__handlerAttributes(tokenizedLine[1:])
tokenizedLine = requestLine.split()
request_object = attributes["requisition"]
if request_object.startswith('/'):
if len(objects)>1:
for i in objects:
iObject = i.split('=')
request = Request(self._rawRequest, attributes)
response = Response()
if attributes["request-method"]=='GET':
self.doGet(request, response)
elif attributes["request-method"]=='POST':
self.doPost(request, response)
rsp = response.getResponse()

class MyServer(HTTPServer):
"""This is a subclass of HTTPServer. The implementation of the GET HTTP method is provided. In our case, we call the correct service"""
def __init__(self,host, port):
HTTPServer.__init__(self, host, port)
def doGet(self, request, response):
"""Implementation of the GET method"""
response.println(str(self.callbacks[functionName](attributes))) # Call the service requested and return the result as a string

This is a service example. In this function we retrieve the position of device through GPS

def get_position(attributes): 
ret='latitude=' + str(pos['latitude']) + '&longitude=' + str(pos['longitude'])
return ret

This is a piece of code that shows how to start the server and to add a service.

server = MyServer('',5004)
server.addCallBack("get_position", get_position)

Step-by-step guide to install and use the ServerPython

  • Download and install spython.sis into your device.
  • Start the spython application.
  • Start the application which uses the intended resource (Flash Lite or WRT)

The developer can easily include new methods into the S60ServerPython, which requires minor knowledges about Python language. Below is described the required steps to make this task.

Implement a method 'method_x' in the Services class. It imposed just one restriction to the new method structure. The method MUST receive a map representing the passed parameters of the URL.

Execute the method 'server.addCallBack('url_to_x', method_x)', where server is an attribute of the type MyServer inside the Services class.


Here you can download the source code and the SIS file of the ServerPython. Note that if you want to use GPS, you have to install the SIS file. Click here to get the zip file with the source and SIS.

An example application in Flash Lite

As discussed previously, a client (Flash Lite) application has access to S60 internal resources through HTTP requests. In ActionScript 2.0 (which is used in Flash Lite 2.x and 3.x) a HTTP request can be executed using the LoadVars class. The basic use of this class is shown below:

var lv:LoadVars = new LoadVars();
lv.onLoad = function(success:Boolean){
//Actions when data is loaded.

The URL has to be changed to

if you want to get the GPS position from the device using the ServerPython.

A complete example on getting GPS position and showing a Google static map can be found here: example project. More details about this example code are available here: Archived:Accessing system resources with PySymbian on S60 3rd Edition devices.

Created by

  • Ivo Calado (ivocalado [at] embedded [dot] ufcg [dot] edu [dot] br)
  • Marcos Fábio Pereira (marcos [at] embedded [dot] ufcg [dot] edu [dot] br)
This page was last modified on 31 May 2013, at 01:03.
108 page views in the last 30 days.