WSGI app mapping requesting User Agent to arbitrary value through user de fined module. Utilizes Wurfl to deliver requesting device info.
Python
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ua_mapper
AUTHORS.rst
CHANGELOG.rst
LICENSE
MANIFEST.in
README.rst
setup.py

README.rst

User Agent Mapper

WSGI handler for mapping a request's user agent to an appropriate template level.

Overview

This project contains a WSGI handler that maps the HTTP request's user agent to an appropriate template level. The handler simply returns the template level.

The mapping uses the WURFL API and XML file to look up the device capabilities associated with the user agent. Mappings are cached using memcached.

Requirements

  1. pywurfl
  2. python-memcached

Usage

To use the user agent mapper, subclass UAMapper and override its map function. An instance of this subclass will then serve as the WSGI handler.

ua_mapper.wsgi

The basic WSGI handler.

ua_mapper.wsgi.UAMapper

The WSGI handler base class that performs user agent mapping. It uses wurfl to map a user agent to a specific device.

map(self, device)

This method must be overridden to perform a custom mapping. The base method simply returns 'medium' or 'high' depending on the resolution of the device.

ua_mapper.updatewurfl

A utility script that downloads the latest WURFL XML file, parses the XML and outputs wurfl. wurfl contains the mapping of user agents to devices. This script requires the wurfl2python module.