Tayra

Template. Script. Distribute

Decorator to template based on request’s useragent

Decorator to detect user-agent information in http request and remap the functional calls to one of the many decorated functions corresponding to the user-agent.

Module contents

tayra.decorators.useragent.useragent(agents=[], namespace=None, _ttlcontext={})[source]

Decorator to wrap different functions by same name into dictionary of callable, based on user agents. When a call is made to the function elsewhere in the template the actual call will be mapped to a callable, based on global variable request.

agents
List of agents (as strings) that should match the request enviroment, for the decorated function to be called. If this argument is not supplied then, the decorated function will be treated as default callable.
namespace
String to be used as namespace for storing { agent : callable, ... } dictionary. If namespace is not provided, then decorated function’s name will be used as namespace name

Table Of Contents

Related Topics

This Page