Skip to main content

HTTP User-Agent parser for Pyramid

Project description

Project Info

Provides an HTTP User-Agent parser and classifier for the Pyramid web framework.

Setup

Once pyramid_useragent is installed, you typically use the config.include mechanism to include it into your Pyramid project’s configuration. In your Pyramid project’s __init__.py:

config = Configurator(.....)
config.include('pyramid_useragent')

Alternately, instead of using the Configurator’s include method, you can activate Pyramid by changing your application’s .ini file, use the following line:

pyramid.includes = pyramid_useragent

Usage

def demo(request):

    client = request.user_agent_classified

    if client.is_mobile or client.is_tablet:
        return "Download our mobile app!"

    if client.is_bot:
        return "Are you human? I'am human."

    ua = request.user_agent_parsed

    if ua.maincomponent.name == 'Links':
        return "Did you REALLY use Links?"

    if 'AdobeAIR' in ua.components:
        if ua.components['AdobeAIR'].version == '3.9.0.1210':
            return "Much unsecure, so flaws"

    if ua.maincomponent.name == "Mozilla":
        return "This is supposed to describe your platform: %s" % (
            '; '.join(ua.maincomponent.comments))

    return [c.name for c in ua.components.values()]

Tests

pip install -e .[testing]
nosetests

Documentation

pip install -e .[docs]
cd docs
make html

Changes

0.3

  • Add a User-Agent classifier using the user-agents project

0.2

  • Continuous testing

  • Documentation

0.1

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyramid_useragent-0.3.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distribution

pyramid_useragent-0.3-py27-none-any.whl (16.0 kB view hashes)

Uploaded Python 2.7

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page